| 161 | } |
| 162 | |
| 163 | void MessagesSearch::searchReceived( |
| 164 | const TLMessages &result, |
| 165 | mtpRequestId requestId, |
| 166 | const QString &nextToken) { |
| 167 | if (requestId != _requestId) { |
| 168 | return; |
| 169 | } |
| 170 | auto &owner = _history->owner(); |
| 171 | auto found = result.match([&](const MTPDmessages_messages &data) { |
| 172 | if (_requestId != 0) { |
| 173 | // Don't apply cached data! |
| 174 | owner.processUsers(data.vusers()); |
| 175 | owner.processChats(data.vchats()); |
| 176 | _history->peer->processTopics(data.vtopics()); |
| 177 | } |
| 178 | auto items = HistoryItemsFromTL(&owner, data.vmessages().v); |
| 179 | const auto total = int(data.vmessages().v.size()); |
| 180 | return FoundMessages{ total, std::move(items), nextToken }; |
| 181 | }, [&](const MTPDmessages_messagesSlice &data) { |
| 182 | if (_requestId != 0) { |
| 183 | // Don't apply cached data! |
| 184 | owner.processUsers(data.vusers()); |
| 185 | owner.processChats(data.vchats()); |
| 186 | _history->peer->processTopics(data.vtopics()); |
| 187 | } |
| 188 | auto items = HistoryItemsFromTL(&owner, data.vmessages().v); |
| 189 | // data.vnext_rate() is used only in global search. |
| 190 | const auto total = int(data.vcount().v); |
| 191 | return FoundMessages{ total, std::move(items), nextToken }; |
| 192 | }, [&](const MTPDmessages_channelMessages &data) { |
| 193 | if (_requestId != 0) { |
| 194 | // Don't apply cached data! |
| 195 | owner.processUsers(data.vusers()); |
| 196 | owner.processChats(data.vchats()); |
| 197 | if (const auto channel = _history->peer->asChannel()) { |
| 198 | channel->ptsReceived(data.vpts().v); |
| 199 | } else { |
| 200 | LOG(("API Error: " |
| 201 | "received messages.channelMessages when no channel " |
| 202 | "was passed!")); |
| 203 | } |
| 204 | _history->peer->processTopics(data.vtopics()); |
| 205 | } |
| 206 | auto items = HistoryItemsFromTL(&owner, data.vmessages().v); |
| 207 | const auto total = int(data.vcount().v); |
| 208 | return FoundMessages{ total, std::move(items), nextToken }; |
| 209 | }, [](const MTPDmessages_messagesNotModified &data) { |
| 210 | return FoundMessages{}; |
| 211 | }); |
| 212 | if (!_offsetId) { |
| 213 | _cacheOfStartByToken.emplace(nextToken, result); |
| 214 | } |
| 215 | _requestId = 0; |
| 216 | _offsetId = found.messages.empty() |
| 217 | ? MsgId() |
| 218 | : found.messages.back().msg; |
| 219 | _messagesFounds.fire(std::move(found)); |
| 220 | } |
nothing calls this directly
no test coverage detected