| 403 | } |
| 404 | |
| 405 | rpl::producer<SparseIdsSlice> SearchController::simpleIdsSlice( |
| 406 | PeerId peerId, |
| 407 | MsgId topicRootId, |
| 408 | PeerId monoforumPeerId, |
| 409 | MsgId aroundId, |
| 410 | const Query &query, |
| 411 | int limitBefore, |
| 412 | int limitAfter) { |
| 413 | Expects(peerId != 0); |
| 414 | Expects(IsServerMsgId(aroundId) || (aroundId == 0)); |
| 415 | Expects((aroundId != 0) |
| 416 | || (limitBefore == 0 && limitAfter == 0)); |
| 417 | Expects((query.peerId == peerId |
| 418 | && query.topicRootId == topicRootId |
| 419 | && query.monoforumPeerId == monoforumPeerId) |
| 420 | || (query.migratedPeerId == peerId |
| 421 | && MsgId(0) == topicRootId |
| 422 | && PeerId(0) == monoforumPeerId)); |
| 423 | |
| 424 | auto it = _cache.find(query); |
| 425 | if (it == _cache.end()) { |
| 426 | return [=](auto) { return rpl::lifetime(); }; |
| 427 | } |
| 428 | |
| 429 | auto listData = (peerId == query.peerId) |
| 430 | ? &it->second->peerData |
| 431 | : &*it->second->migratedData; |
| 432 | return [=](auto consumer) { |
| 433 | auto lifetime = rpl::lifetime(); |
| 434 | auto builder = lifetime.make_state<SparseIdsSliceBuilder>( |
| 435 | aroundId, |
| 436 | limitBefore, |
| 437 | limitAfter); |
| 438 | builder->insufficientAround( |
| 439 | ) | rpl::on_next([=]( |
| 440 | const SparseIdsSliceBuilder::AroundData &data) { |
| 441 | requestMore(data, query, listData); |
| 442 | }, lifetime); |
| 443 | |
| 444 | auto pushNextSnapshot = [=] { |
| 445 | consumer.put_next(builder->snapshot()); |
| 446 | }; |
| 447 | |
| 448 | listData->list.sliceUpdated( |
| 449 | ) | rpl::filter([=](const SliceUpdate &update) { |
| 450 | return builder->applyUpdate(update); |
| 451 | }) | rpl::on_next(pushNextSnapshot, lifetime); |
| 452 | |
| 453 | _session->data().itemRemoved( |
| 454 | ) | rpl::filter([=](not_null<const HistoryItem*> item) { |
| 455 | return (item->history()->peer->id == peerId) |
| 456 | && (!topicRootId || item->topicRootId() == topicRootId) |
| 457 | && (!monoforumPeerId |
| 458 | || item->sublistPeerId() == monoforumPeerId); |
| 459 | }) | rpl::filter([=](not_null<const HistoryItem*> item) { |
| 460 | return builder->removeOne(item->id); |
| 461 | }) | rpl::on_next(pushNextSnapshot, lifetime); |
| 462 |
nothing calls this directly
no test coverage detected