| 526 | } |
| 527 | |
| 528 | void RepliesList::loadAround(MsgId id) { |
| 529 | Expects(!_creating); |
| 530 | |
| 531 | if (_loadingAround && *_loadingAround == id) { |
| 532 | return; |
| 533 | } |
| 534 | histories().cancelRequest(base::take(_beforeId)); |
| 535 | histories().cancelRequest(base::take(_afterId)); |
| 536 | |
| 537 | const auto send = [=](Fn<void()> finish) { |
| 538 | return _history->session().api().request(MTPmessages_GetReplies( |
| 539 | _history->peer->input(), |
| 540 | MTP_int(_rootId), |
| 541 | MTP_int(id), // offset_id |
| 542 | MTP_int(0), // offset_date |
| 543 | MTP_int(id ? (-kMessagesPerPage / 2) : 0), // add_offset |
| 544 | MTP_int(kMessagesPerPage), // limit |
| 545 | MTP_int(0), // max_id |
| 546 | MTP_int(0), // min_id |
| 547 | MTP_long(0) // hash |
| 548 | )).done([=](const MTPmessages_Messages &result) { |
| 549 | _beforeId = 0; |
| 550 | _loadingAround = std::nullopt; |
| 551 | finish(); |
| 552 | |
| 553 | if (!id) { |
| 554 | _skippedAfter = 0; |
| 555 | } else { |
| 556 | _skippedAfter = std::nullopt; |
| 557 | } |
| 558 | _skippedBefore = std::nullopt; |
| 559 | _list.clear(); |
| 560 | if (processMessagesIsEmpty(result)) { |
| 561 | _fullCount = _skippedBefore = _skippedAfter = 0; |
| 562 | } else if (id) { |
| 563 | Assert(!_list.empty()); |
| 564 | if (_list.front() <= id) { |
| 565 | _skippedAfter = 0; |
| 566 | } else if (_list.back() >= id) { |
| 567 | _skippedBefore = 0; |
| 568 | } |
| 569 | } |
| 570 | checkReadTillEnd(); |
| 571 | }).fail([=] { |
| 572 | _beforeId = 0; |
| 573 | _loadingAround = std::nullopt; |
| 574 | finish(); |
| 575 | }).send(); |
| 576 | }; |
| 577 | _loadingAround = id; |
| 578 | _beforeId = histories().sendRequest( |
| 579 | _history, |
| 580 | Histories::RequestType::History, |
| 581 | send); |
| 582 | } |
| 583 | |
| 584 | void RepliesList::loadBefore() { |
| 585 | Expects(!_list.empty()); |
nothing calls this directly
no test coverage detected