| 1142 | } |
| 1143 | |
| 1144 | void SavedSublist::loadAround(MsgId id) { |
| 1145 | if (_loadingAround && *_loadingAround == id) { |
| 1146 | _loadingAroundRetry = id; |
| 1147 | return; |
| 1148 | } |
| 1149 | _loadingAroundRetry = std::nullopt; |
| 1150 | histories().cancelRequest(base::take(_beforeId)); |
| 1151 | histories().cancelRequest(base::take(_afterId)); |
| 1152 | |
| 1153 | const auto send = [=](Fn<void()> finish) { |
| 1154 | using Flag = MTPmessages_GetSavedHistory::Flag; |
| 1155 | const auto parentChat = _parent->parentChat(); |
| 1156 | return session().api().request(MTPmessages_GetSavedHistory( |
| 1157 | MTP_flags(parentChat ? Flag::f_parent_peer : Flag(0)), |
| 1158 | parentChat ? parentChat->input() : MTPInputPeer(), |
| 1159 | sublistPeer()->input(), |
| 1160 | MTP_int(id), // offset_id |
| 1161 | MTP_int(0), // offset_date |
| 1162 | MTP_int(id ? (-kMessagesPerPage / 2) : 0), // add_offset |
| 1163 | MTP_int(kMessagesPerPage), // limit |
| 1164 | MTP_int(0), // max_id |
| 1165 | MTP_int(0), // min_id |
| 1166 | MTP_long(0)) // hash |
| 1167 | ).done([=](const MTPmessages_Messages &result) { |
| 1168 | _beforeId = 0; |
| 1169 | _loadingAround = std::nullopt; |
| 1170 | finish(); |
| 1171 | |
| 1172 | if (!id) { |
| 1173 | _skippedAfter = 0; |
| 1174 | } else { |
| 1175 | _skippedAfter = std::nullopt; |
| 1176 | } |
| 1177 | _skippedBefore = std::nullopt; |
| 1178 | _list.clear(); |
| 1179 | if (processMessagesIsEmpty(result)) { |
| 1180 | _fullCount = _skippedBefore = _skippedAfter = 0; |
| 1181 | if (!_parent->parentChat() |
| 1182 | && !_chatListMessage.value_or(nullptr)) { |
| 1183 | if (isPinnedDialog(FilterId())) { |
| 1184 | _restorePinnedWhenNonEmpty = true; |
| 1185 | owner().setChatPinned(this, FilterId(), false); |
| 1186 | } |
| 1187 | setLastServerMessage(nullptr); |
| 1188 | updateChatListExistence(); |
| 1189 | } |
| 1190 | } else if (id) { |
| 1191 | Assert(!_list.empty()); |
| 1192 | if (_list.front() <= id) { |
| 1193 | _skippedAfter = 0; |
| 1194 | } else if (_list.back() >= id) { |
| 1195 | _skippedBefore = 0; |
| 1196 | } |
| 1197 | } else if (!_parent->parentChat() |
| 1198 | && !_chatListMessage.value_or(nullptr)) { |
| 1199 | Assert(!_list.empty()); |
| 1200 | applyMaybeLast(owner().message( |
| 1201 | owningHistory()->peer, |
nothing calls this directly
no test coverage detected