From 7727cd734ede368feadc61278f5e29a0a940ace3 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 16 May 2022 09:21:40 +0300 Subject: [PATCH] Slightly simplified processing of received full peer info. --- Telegram/SourceFiles/apiwrap.cpp | 42 ++++++++++---------------------- Telegram/SourceFiles/apiwrap.h | 8 +++--- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 7761b3acfd..65e7e3d96d 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -998,46 +998,41 @@ void ApiWrap::requestFullPeer(not_null peer) { } return request(MTPusers_GetFullUser( user->inputUser - )).done([=](const MTPusers_UserFull &result, mtpRequestId requestId) { + )).done([=](const MTPusers_UserFull &result) { result.match([&](const MTPDusers_userFull &data) { _session->data().processUsers(data.vusers()); _session->data().processChats(data.vchats()); }); - gotUserFull(user, result, requestId); + gotUserFull(user, result); }).fail(failHandler).send(); } else if (const auto chat = peer->asChat()) { return request(MTPmessages_GetFullChat( chat->inputChat - )).done([=]( - const MTPmessages_ChatFull &result, - mtpRequestId requestId) { - gotChatFull(peer, result, requestId); + )).done([=](const MTPmessages_ChatFull &result) { + gotChatFull(peer, result); }).fail(failHandler).send(); } else if (const auto channel = peer->asChannel()) { return request(MTPchannels_GetFullChannel( channel->inputChannel - )).done([=]( - const MTPmessages_ChatFull &result, - mtpRequestId requestId) { - gotChatFull(peer, result, requestId); + )).done([=](const MTPmessages_ChatFull &result) { + gotChatFull(peer, result); migrateDone(channel, channel); }).fail(failHandler).send(); } Unexpected("Peer type in requestFullPeer."); }(); - _fullPeerRequests.insert(peer, requestId); + _fullPeerRequests.emplace(peer, requestId); } void ApiWrap::processFullPeer( not_null peer, const MTPmessages_ChatFull &result) { - gotChatFull(peer, result, mtpRequestId(0)); + gotChatFull(peer, result); } void ApiWrap::gotChatFull( not_null peer, - const MTPmessages_ChatFull &result, - mtpRequestId req) { + const MTPmessages_ChatFull &result) { const auto &d = result.c_messages_chatFull(); _session->data().applyMaximumChatVersions(d.vchats()); @@ -1060,12 +1055,7 @@ void ApiWrap::gotChatFull( } }); - if (req) { - const auto i = _fullPeerRequests.find(peer); - if (i != _fullPeerRequests.cend() && i.value() == req) { - _fullPeerRequests.erase(i); - } - } + _fullPeerRequests.remove(peer); _session->changes().peerUpdated( peer, Data::PeerUpdate::Flag::FullInfo); @@ -1073,8 +1063,7 @@ void ApiWrap::gotChatFull( void ApiWrap::gotUserFull( not_null user, - const MTPusers_UserFull &result, - mtpRequestId req) { + const MTPusers_UserFull &result) { result.match([&](const MTPDusers_userFull &data) { data.vfull_user().match([&](const MTPDuserFull &fields) { if (user == _session->user() && !_session->validateSelf(fields.vid().v)) { @@ -1087,12 +1076,7 @@ void ApiWrap::gotUserFull( Data::ApplyUserUpdate(user, fields); }); }); - if (req) { - const auto i = _fullPeerRequests.find(user); - if (i != _fullPeerRequests.cend() && i.value() == req) { - _fullPeerRequests.erase(i); - } - } + _fullPeerRequests.remove(user); _session->changes().peerUpdated( user, Data::PeerUpdate::Flag::FullInfo); @@ -1133,7 +1117,7 @@ void ApiWrap::requestPeer(not_null peer) { } Unexpected("Peer type in requestPeer."); }(); - _peerRequests.insert(peer, requestId); + _peerRequests.emplace(peer, requestId); } void ApiWrap::requestPeerSettings(not_null peer) { diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index fdbff5d263..ab234b19c0 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -420,12 +420,10 @@ private: void gotChatFull( not_null peer, - const MTPmessages_ChatFull &result, - mtpRequestId req); + const MTPmessages_ChatFull &result); void gotUserFull( not_null user, - const MTPusers_UserFull &result, - mtpRequestId req); + const MTPusers_UserFull &result); void resolveWebPages(); void gotWebPages( ChannelData *channel, @@ -522,7 +520,7 @@ private: MessageDataRequests> _channelMessageDataRequests; SingleQueuedInvokation _messageDataResolveDelayed; - using PeerRequests = QMap; + using PeerRequests = base::flat_map; PeerRequests _fullPeerRequests; PeerRequests _peerRequests; base::flat_set> _requestedPeerSettings;