MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / searchReceived

Method searchReceived

Telegram/SourceFiles/api/api_messages_search.cpp:163–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163void 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}

Callers

nothing calls this directly

Calls 12

HistoryItemsFromTLFunction · 0.85
processUsersMethod · 0.80
processChatsMethod · 0.80
processTopicsMethod · 0.80
asChannelMethod · 0.80
ptsReceivedMethod · 0.80
emplaceMethod · 0.80
MsgIdClass · 0.50
ownerMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
fireMethod · 0.45

Tested by

no test coverage detected