From 4111da1dd0926d657e5205744111b2c6fec7b61c Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 18 Jan 2019 16:27:37 +0400 Subject: [PATCH] Move some calls from App namespace. --- Telegram/SourceFiles/apiwrap.cpp | 149 ++--- Telegram/SourceFiles/app.cpp | 65 +- Telegram/SourceFiles/app.h | 18 - Telegram/SourceFiles/auth_session.cpp | 2 +- .../SourceFiles/boxes/add_contact_box.cpp | 20 +- Telegram/SourceFiles/boxes/background_box.cpp | 4 +- .../SourceFiles/boxes/change_phone_box.cpp | 6 +- Telegram/SourceFiles/boxes/confirm_box.cpp | 2 +- Telegram/SourceFiles/boxes/peer_list_box.cpp | 5 +- .../boxes/peer_list_controllers.cpp | 12 +- .../boxes/peers/add_participants_box.cpp | 9 +- Telegram/SourceFiles/boxes/share_box.cpp | 27 +- .../SourceFiles/boxes/sticker_set_box.cpp | 8 +- Telegram/SourceFiles/boxes/username_box.cpp | 3 +- .../calls/calls_box_controller.cpp | 8 +- Telegram/SourceFiles/calls/calls_call.cpp | 8 +- Telegram/SourceFiles/calls/calls_instance.cpp | 3 +- .../chat_helpers/gifs_list_widget.cpp | 13 +- .../SourceFiles/chat_helpers/stickers.cpp | 21 +- .../chat_helpers/stickers_list_widget.cpp | 2 +- .../SourceFiles/core/click_handler_types.cpp | 6 +- .../SourceFiles/core/local_url_handlers.cpp | 3 +- .../SourceFiles/data/data_channel_admins.cpp | 3 +- Telegram/SourceFiles/data/data_drafts.cpp | 5 +- Telegram/SourceFiles/data/data_feed.cpp | 6 +- .../SourceFiles/data/data_media_types.cpp | 5 +- Telegram/SourceFiles/data/data_peer.cpp | 2 +- .../data/data_search_controller.cpp | 18 +- Telegram/SourceFiles/data/data_session.cpp | 60 +- Telegram/SourceFiles/data/data_session.h | 75 ++- .../SourceFiles/data/data_shared_media.cpp | 4 +- Telegram/SourceFiles/data/data_user.h | 2 +- .../SourceFiles/data/data_user_photos.cpp | 3 +- Telegram/SourceFiles/data/data_web_page.cpp | 14 +- .../dialogs/dialogs_indexed_list.cpp | 4 +- .../dialogs/dialogs_inner_widget.cpp | 40 +- .../SourceFiles/dialogs/dialogs_widget.cpp | 32 +- Telegram/SourceFiles/facades.cpp | 4 +- .../admin_log/history_admin_log_inner.cpp | 22 +- .../admin_log/history_admin_log_item.cpp | 6 +- .../admin_log/history_admin_log_section.cpp | 3 +- Telegram/SourceFiles/history/history.cpp | 53 +- Telegram/SourceFiles/history/history_item.cpp | 2 +- .../history/history_item_components.cpp | 3 +- .../SourceFiles/history/history_message.cpp | 20 +- .../SourceFiles/history/history_service.cpp | 8 +- .../SourceFiles/history/history_widget.cpp | 28 +- .../history/media/history_media_contact.cpp | 4 +- .../info_common_groups_inner_widget.cpp | 11 +- .../info_common_groups_widget.cpp | 4 +- .../feed/info_feed_channels_controllers.cpp | 10 +- .../SourceFiles/info/info_content_widget.cpp | 4 +- Telegram/SourceFiles/info/info_controller.cpp | 11 +- Telegram/SourceFiles/info/info_controller.h | 4 +- Telegram/SourceFiles/info/info_memento.cpp | 4 +- .../SourceFiles/info/info_wrap_widget.cpp | 2 +- .../inline_bots/inline_bot_result.cpp | 4 +- .../inline_bots/inline_results_widget.cpp | 3 +- Telegram/SourceFiles/mainwidget.cpp | 602 +++++++++--------- Telegram/SourceFiles/mainwidget.h | 3 + Telegram/SourceFiles/mediaview.cpp | 6 +- .../passport/passport_form_controller.cpp | 4 +- .../SourceFiles/settings/settings_main.cpp | 4 +- .../settings/settings_privacy_controllers.cpp | 10 +- Telegram/SourceFiles/storage/file_upload.cpp | 32 +- .../SourceFiles/storage/serialize_common.cpp | 5 +- .../SourceFiles/storage/storage_user_photos.h | 2 +- .../SourceFiles/support/support_helper.cpp | 3 +- Telegram/SourceFiles/ui/text/text_entity.cpp | 3 +- Telegram/SourceFiles/window/main_window.cpp | 2 +- .../window/notifications_manager.cpp | 4 +- .../SourceFiles/window/window_controller.cpp | 152 +++-- .../SourceFiles/window/window_controller.h | 15 +- .../SourceFiles/window/window_peer_menu.cpp | 24 +- 74 files changed, 896 insertions(+), 852 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 0a650cc97..907b59aa3 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -266,12 +266,12 @@ void ApiWrap::proxyPromotionDone(const MTPhelp_ProxyData &proxy) { proxy.match([&](const MTPDhelp_proxyDataEmpty &data) { _session->data().setProxyPromoted(nullptr); }, [&](const MTPDhelp_proxyDataPromo &data) { - App::feedChats(data.vchats); - App::feedUsers(data.vusers); + _session->data().processChats(data.vchats); + _session->data().processUsers(data.vusers); const auto peerId = peerFromMTP(data.vpeer); const auto peer = _session->data().peer(peerId); _session->data().setProxyPromoted(peer); - if (const auto history = App::historyLoaded(peer)) { + if (const auto history = _session->data().historyLoaded(peer)) { requestDialogEntry(history); } }); @@ -378,7 +378,7 @@ void ApiWrap::importChatInvite(const QString &hash) { }, [](auto&&) { return PeerId(0); }); - if (const auto peer = App::peerLoaded(peerId)) { + if (const auto peer = _session->data().peerLoaded(peerId)) { App::wnd()->controller()->showPeerHistory( peer, Window::SectionShow::Way::Forward); @@ -563,8 +563,8 @@ void ApiWrap::resolveMessageDatas() { void ApiWrap::gotMessageDatas(ChannelData *channel, const MTPmessages_Messages &msgs, mtpRequestId requestId) { auto handleResult = [&](auto &&result) { - App::feedUsers(result.vusers); - App::feedChats(result.vchats); + _session->data().processUsers(result.vusers); + _session->data().processChats(result.vchats); App::feedMsgs(result.vmessages, NewMessageExisting); }; switch (msgs.type()) { @@ -624,7 +624,7 @@ void ApiWrap::requestContacts() { } Assert(result.type() == mtpc_contacts_contacts); const auto &d = result.c_contacts_contacts(); - App::feedUsers(d.vusers); + _session->data().processUsers(d.vusers); for (const auto &contact : d.vcontacts.v) { if (contact.type() != mtpc_contact) continue; @@ -763,15 +763,15 @@ void ApiWrap::applyPeerDialogs(const MTPmessages_PeerDialogs &dialogs) { Expects(dialogs.type() == mtpc_messages_peerDialogs); const auto &data = dialogs.c_messages_peerDialogs(); - App::feedUsers(data.vusers); - App::feedChats(data.vchats); + _session->data().processUsers(data.vusers); + _session->data().processChats(data.vchats); App::feedMsgs(data.vmessages, NewMessageLast); for (const auto &dialog : data.vdialogs.v) { switch (dialog.type()) { case mtpc_dialog: { const auto &fields = dialog.c_dialog(); if (const auto peerId = peerFromMTP(fields.vpeer)) { - App::history(peerId)->applyDialog(fields); + _session->data().history(peerId)->applyDialog(fields); } } break; @@ -798,15 +798,15 @@ void ApiWrap::applyFeedDialogs( dialogs.match([&](const MTPDmessages_dialogsNotModified &) { Unexpected("Type in ApiWrap::applyFeedDialogs."); }, [&](const auto &data) { - App::feedUsers(data.vusers); - App::feedChats(data.vchats); + _session->data().processUsers(data.vusers); + _session->data().processChats(data.vchats); App::feedMsgs(data.vmessages.v, NewMessageLast); channels.reserve(data.vdialogs.v.size()); for (const auto &dialog : data.vdialogs.v) { dialog.match([&](const MTPDdialog &data) { if (const auto peerId = peerFromMTP(data.vpeer)) { if (peerIsChannel(peerId)) { - const auto history = App::history(peerId); + const auto history = _session->data().history(peerId); history->applyDialog(dialog.c_dialog()); channels.emplace_back(history->peer->asChannel()); } else { @@ -886,7 +886,8 @@ void ApiWrap::requestWallPaper( _wallPaperRequestId = 0; _wallPaperSlug = QString(); result.match([&](const MTPDwallPaper &data) { - const auto document = _session->data().document(data.vdocument); + const auto document = _session->data().processDocument( + data.vdocument); if (document->checkWallPaperProperties()) { if (const auto done = base::take(_wallPaperDone)) { done({ @@ -972,8 +973,8 @@ void ApiWrap::gotChatFull( const auto &d = result.c_messages_chatFull(); _session->data().applyMaximumChatVersions(d.vchats); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + _session->data().processUsers(d.vusers); + _session->data().processChats(d.vchats); using UpdateFlag = Notify::PeerUpdate::Flag; if (const auto chat = peer->asChat()) { @@ -987,7 +988,7 @@ void ApiWrap::gotChatFull( if (f.has_bot_info()) { for (const auto &item : f.vbot_info.v) { item.match([&](const MTPDbotInfo &data) { - if (const auto bot = App::userLoaded(data.vuser_id.v)) { + if (const auto bot = _session->data().userLoaded(data.vuser_id.v)) { bot->setBotInfo(item); fullPeerUpdated().notify(bot); } @@ -1029,7 +1030,7 @@ void ApiWrap::gotChatFull( if (f.has_migrated_from_chat_id()) { channel->addFlags(MTPDchannel::Flag::f_megagroup); const auto chat = channel->owner().chat( - peerFromChat(f.vmigrated_from_chat_id)); + f.vmigrated_from_chat_id.v); Data::ApplyMigration(chat, channel); } for (const auto &item : f.vbot_info.v) { @@ -1047,7 +1048,7 @@ void ApiWrap::gotChatFull( channel->setRestrictedCount(f.has_banned_count() ? f.vbanned_count.v : 0); channel->setKickedCount(f.has_kicked_count() ? f.vkicked_count.v : 0); channel->setInviteLink((f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString()); - if (const auto history = App::historyLoaded(channel->id)) { + if (const auto history = _session->data().historyLoaded(channel)) { history->clearUpTill(f.vavailable_min_id.v); history->applyDialogFields( f.vunread_count.v, @@ -1108,9 +1109,9 @@ void ApiWrap::gotUserFull( }); return; } - App::feedUsers(MTP_vector(1, d.vuser)); + _session->data().processUser(d.vuser); if (d.has_profile_photo()) { - _session->data().photo(d.vprofile_photo); + _session->data().processPhoto(d.vprofile_photo); } App::feedUserLink(MTP_int(peerToUser(user->id)), d.vlink.c_contacts_link().vmy_link, d.vlink.c_contacts_link().vforeign_link); if (App::main()) { @@ -1158,14 +1159,14 @@ void ApiWrap::requestPeer(not_null peer) { return data.vchats; }); _session->data().applyMaximumChatVersions(chats); - App::feedChats(chats); + _session->data().processChats(chats); }; if (const auto user = peer->asUser()) { return request(MTPusers_GetUsers( MTP_vector(1, user->inputUser) )).done([=](const MTPVector &result) { _peerRequests.remove(user); - App::feedUsers(result); + _session->data().processUsers(result); }).fail(failHandler).send(); } else if (const auto chat = peer->asChat()) { return request(MTPmessages_GetChats( @@ -1352,7 +1353,7 @@ void ApiWrap::requestPeers(const QList &peers) { } } const auto handleChats = [=](const MTPmessages_Chats &result) { - App::feedChats(result.match([](const auto &data) { + _session->data().processChats(result.match([](const auto &data) { return data.vchats; })); }; @@ -1370,7 +1371,7 @@ void ApiWrap::requestPeers(const QList &peers) { request(MTPusers_GetUsers( MTP_vector(users) )).done([=](const MTPVector &result) { - App::feedUsers(result); + _session->data().processUsers(result); }).send(); } } @@ -1452,7 +1453,7 @@ void ApiWrap::requestAdmins(not_null channel) { )).done([this, channel](const MTPchannels_ChannelParticipants &result) { _adminsRequests.remove(channel); result.match([&](const MTPDchannels_channelParticipants &data) { - App::feedUsers(data.vusers); + _session->data().processUsers(data.vusers); applyAdminsList( channel, data.vcount.v, @@ -1498,7 +1499,7 @@ void ApiWrap::applyLastParticipantsList( continue; } - auto user = App::user(userId); + auto user = _session->data().user(userId); if (p.type() == mtpc_channelParticipantCreator) { channel->mgInfo->creator = user; if (!channel->mgInfo->admins.empty() @@ -1550,7 +1551,7 @@ void ApiWrap::applyBotsList( not_null channel, int availableCount, const QVector &list) { - const auto history = App::historyLoaded(channel->id); + const auto history = _session->data().historyLoaded(channel); channel->mgInfo->bots.clear(); channel->mgInfo->botStatus = -1; @@ -1565,7 +1566,7 @@ void ApiWrap::applyBotsList( continue; } - auto user = App::user(userId); + auto user = _session->data().user(userId); if (user->botInfo) { channel->mgInfo->bots.insert(user); botStatus = 2;// (botStatus > 0/* || !i.key()->botInfo->readsAllHistory*/) ? 2 : 1; @@ -1629,7 +1630,7 @@ void ApiWrap::requestSelfParticipant(not_null channel) { const auto finalize = [=](UserId inviter, TimeId inviteDate) { channel->inviter = inviter; channel->inviteDate = inviteDate; - if (const auto history = App::historyLoaded(channel)) { + if (const auto history = _session->data().historyLoaded(channel)) { if (history->lastMessageKnown()) { history->checkJoinedMessage(true); history->owner().sendHistoryChangeNotifications(); @@ -1645,7 +1646,7 @@ void ApiWrap::requestSelfParticipant(not_null channel) { )).done([=](const MTPchannels_ChannelParticipant &result) { _selfParticipantRequests.erase(channel); result.match([&](const MTPDchannels_channelParticipant &data) { - App::feedUsers(data.vusers); + _session->data().processUsers(data.vusers); const auto &participant = data.vparticipant; participant.match([&](const MTPDchannelParticipantSelf &data) { @@ -1778,7 +1779,7 @@ void ApiWrap::saveDefaultRestrictions( void ApiWrap::deleteAllFromUser( not_null channel, not_null from) { - const auto history = App::historyLoaded(channel->id); + const auto history = _session->data().historyLoaded(channel); const auto ids = history ? history->collectMessagesFromUserToDelete(from) : QVector(); @@ -1804,7 +1805,7 @@ void ApiWrap::deleteAllFromUserSend( const auto offset = applyAffectedHistory(channel, result); if (offset > 0) { deleteAllFromUserSend(channel, from); - } else if (const auto history = App::historyLoaded(channel)) { + } else if (const auto history = _session->data().historyLoaded(channel)) { history->requestChatListMessage(); } }).send(); @@ -2196,7 +2197,7 @@ void ApiWrap::savePrivacy(const MTPInputPrivacyKey &key, QVectordata().processUsers(rules.vusers); _privacySaveRequests.remove(keyTypeId); handlePrivacyChange(keyTypeId, rules.vrules); }).fail([=](const RPCError &error) { @@ -2306,7 +2307,7 @@ void ApiWrap::updatePrivacyLastSeens(const QVector &rules) { for_const (auto &item, result.v) { Assert(item.type() == mtpc_contactStatus); auto &data = item.c_contactStatus(); - if (auto user = App::userLoaded(data.vuser_id.v)) { + if (auto user = _session->data().userLoaded(data.vuser_id.v)) { auto oldOnlineTill = user->onlineTill; auto newOnlineTill = OnlineTillFromStatus(data.vstatus, oldOnlineTill); if (oldOnlineTill != newOnlineTill) { @@ -2338,7 +2339,7 @@ int ApiWrap::OnlineTillFromStatus( void ApiWrap::clearHistory(not_null peer) { auto deleteTillId = MsgId(0); - if (const auto history = App::historyLoaded(peer->id)) { + if (const auto history = _session->data().historyLoaded(peer)) { if (const auto last = history->lastMessage()) { deleteTillId = last->id; } @@ -2704,8 +2705,8 @@ void ApiWrap::channelRangeDifferenceDone( case mtpc_updates_channelDifferenceTooLong: { const auto &d = result.c_updates_channelDifferenceTooLong(); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + _session->data().processUsers(d.vusers); + _session->data().processChats(d.vchats); nextRequestPts = d.vpts.v; isFinal = d.is_final(); @@ -2829,7 +2830,7 @@ void ApiWrap::refreshFileReference( fail(); } }, [&](Data::FileOriginUserPhoto data) { - if (const auto user = App::user(data.userId)) { + if (const auto user = _session->data().user(data.userId)) { request(MTPphotos_GetUserPhotos( user->inputUser, MTP_int(-1), @@ -2839,7 +2840,7 @@ void ApiWrap::refreshFileReference( fail(); } }, [&](Data::FileOriginPeerPhoto data) { - if (const auto peer = App::peer(data.peerId)) { + if (const auto peer = _session->data().peer(data.peerId)) { if (const auto user = peer->asUser()) { request(MTPusers_GetUsers( MTP_vector(1, user->inputUser))); @@ -2895,15 +2896,15 @@ void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &msgs switch (msgs.type()) { case mtpc_messages_messages: { auto &d = msgs.c_messages_messages(); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + _session->data().processUsers(d.vusers); + _session->data().processChats(d.vchats); v = &d.vmessages.v; } break; case mtpc_messages_messagesSlice: { auto &d = msgs.c_messages_messagesSlice(); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + _session->data().processUsers(d.vusers); + _session->data().processChats(d.vchats); v = &d.vmessages.v; } break; @@ -2914,8 +2915,8 @@ void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &msgs } else { LOG(("API Error: received messages.channelMessages when no channel was passed! (ApiWrap::gotWebPages)")); } - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + _session->data().processUsers(d.vusers); + _session->data().processChats(d.vchats); v = &d.vmessages.v; } break; @@ -3023,7 +3024,8 @@ std::vector> *ApiWrap::stickersByEmoji( entry.list.clear(); entry.list.reserve(data.vstickers.v.size()); for (const auto &sticker : data.vstickers.v) { - const auto document = _session->data().document(sticker); + const auto document = _session->data().processDocument( + sticker); if (document->sticker()) { entry.list.push_back(document); } @@ -3311,7 +3313,7 @@ void ApiWrap::parseChannelParticipants( const QVector &list)> callbackList, Fn callbackNotModified) { result.match([&](const MTPDchannels_channelParticipants &data) { - App::feedUsers(data.vusers); + _session->data().processUsers(data.vusers); if (channel->mgInfo) { refreshChannelAdmins(channel, data.vparticipants.v); } @@ -3557,14 +3559,13 @@ void ApiWrap::requestMessageAfterDate( MTP_int(minId), MTP_int(historyHash) )).done([ - peer, - offsetDate, + =, callback = std::forward(callback) ](const MTPmessages_Messages &result) { - auto getMessagesList = [&result, peer]() -> const QVector* { - auto handleMessages = [](auto &messages) { - App::feedUsers(messages.vusers); - App::feedChats(messages.vchats); + auto getMessagesList = [&]() -> const QVector* { + auto handleMessages = [&](auto &messages) { + _session->data().processUsers(messages.vusers); + _session->data().processChats(messages.vchats); return &messages.vmessages.v; }; switch (result.type()) { @@ -3660,8 +3661,8 @@ void ApiWrap::requestMessageAfterDate( // const auto &data = result.c_messages_feedMessages(); // const auto &messages = data.vmessages.v; // const auto type = NewMessageExisting; - // App::feedUsers(data.vusers); - // App::feedChats(data.vchats); + // _session->data().processUsers(data.vusers); + // _session->data().processChats(data.vchats); // for (const auto &msg : messages) { // if (const auto item = _session->data().addNewMessage(msg, type)) { // if (item->date() >= offsetDate || true) { @@ -3863,14 +3864,14 @@ void ApiWrap::userPhotosDone( switch (result.type()) { case mtpc_photos_photos: { auto &d = result.c_photos_photos(); - App::feedUsers(d.vusers); + _session->data().processUsers(d.vusers); fullCount = d.vphotos.v.size(); return &d.vphotos.v; } break; case mtpc_photos_photosSlice: { auto &d = result.c_photos_photosSlice(); - App::feedUsers(d.vusers); + _session->data().processUsers(d.vusers); fullCount = d.vcount.v; return &d.vphotos.v; } break; @@ -3881,7 +3882,7 @@ void ApiWrap::userPhotosDone( auto photoIds = std::vector(); photoIds.reserve(photos.size()); for (auto &photo : photos) { - if (auto photoData = _session->data().photo(photo)) { + if (auto photoData = _session->data().processPhoto(photo)) { photoIds.push_back(photoData->id); } } @@ -3943,14 +3944,14 @@ void ApiWrap::userPhotosDone( // const auto feed = _session->data().feed(feedId); // auto channels = std::vector>(); // for (const auto &channelId : list.vchannels.v) { -// channels.push_back(App::channel(channelId.v)); +// channels.push_back(_session->data().channel(channelId.v)); // } // feed->setChannels(std::move(channels)); // } // } // -// App::feedUsers(data.vusers); -// App::feedChats(data.vchats); +// _session->data().processUsers(data.vusers); +// _session->data().processChats(data.vchats); // // if (data.has_newly_joined_feed()) { // _session->data().setDefaultFeedId( @@ -4085,8 +4086,8 @@ void ApiWrap::userPhotosDone( // const auto tooSmallPosition = [&](const auto &position) { // return (slice == SliceType::After) && !(messageId < position); // }; -// App::feedUsers(data.vusers); -// App::feedChats(data.vchats); +// _session->data().processUsers(data.vusers); +// _session->data().processChats(data.vchats); // if (!messages.empty()) { // ids.reserve(messages.size()); // for (const auto &msg : messages) { @@ -4662,7 +4663,7 @@ void ApiWrap::sendBotStart(not_null bot, PeerData *chat) { auto &info = bot->botInfo; auto &token = chat ? info->startGroupToken : info->startToken; if (token.isEmpty()) { - auto message = ApiWrap::MessageToSend(App::history(bot)); + auto message = ApiWrap::MessageToSend(_session->data().history(bot)); message.textWithTags = { qsl("/start"), TextWithTags::Tags() }; sendMessage(std::move(message)); return; @@ -5135,18 +5136,18 @@ void ApiWrap::photoUploadReady( file )).done([=](const MTPphotos_Photo &result) { result.match([&](const MTPDphotos_photo &data) { - _session->data().photo(data.vphoto); - App::feedUsers(data.vusers); + _session->data().processPhoto(data.vphoto); + _session->data().processUsers(data.vusers); }); }).send(); } else if (const auto chat = peer->asChat()) { - const auto history = App::history(chat); + const auto history = _session->data().history(chat); history->sendRequestId = request(MTPmessages_EditChatPhoto( chat->inputChat, MTP_inputChatUploadedPhoto(file) )).done(applier).afterRequest(history->sendRequestId).send(); } else if (const auto channel = peer->asChannel()) { - const auto history = App::history(channel); + const auto history = _session->data().history(channel); history->sendRequestId = request(MTPchannels_EditPhoto( channel->inputChannel, MTP_inputChatUploadedPhoto(file) @@ -5298,7 +5299,7 @@ void ApiWrap::saveSelfBio(const QString &text, FnMut done) { )).done([=](const MTPUser &result) { _saveBioRequestId = 0; - App::feedUsers(MTP_vector(1, result)); + _session->data().processUsers(MTP_vector(1, result)); _session->user()->setAbout(_saveBioText); if (_saveBioDone) { _saveBioDone(); @@ -5317,7 +5318,7 @@ void ApiWrap::reloadPrivacy(Privacy::Key key) { )).done([=](const MTPaccount_PrivacyRules &result) { _privacyRequestIds.erase(key); result.match([&](const MTPDaccount_privacyRules &data) { - App::feedUsers(data.vusers); + _session->data().processUsers(data.vusers); pushPrivacy(key, data.vrules.v); }); }).fail([=](const RPCError &error) { @@ -5351,7 +5352,7 @@ auto ApiWrap::parsePrivacy(const QVector &rules) const auto &users = data.vusers.v; always.reserve(always.size() + users.size()); for (const auto userId : users) { - const auto user = App::user(UserId(userId.v)); + const auto user = _session->data().user(UserId(userId.v)); if (!base::contains(never, user) && !base::contains(always, user)) { always.push_back(user); @@ -5365,7 +5366,7 @@ auto ApiWrap::parsePrivacy(const QVector &rules) const auto &users = data.vusers.v; never.reserve(never.size() + users.size()); for (const auto userId : users) { - const auto user = App::user(UserId(userId.v)); + const auto user = _session->data().user(UserId(userId.v)); if (!base::contains(always, user) && !base::contains(never, user)) { never.push_back(user); @@ -5589,7 +5590,7 @@ void ApiWrap::readServerHistoryForce(not_null history) { if (!channel->amIn()) { return; // no read request for channels that I didn't join } else if (const auto migrateFrom = channel->migrateFrom()) { - if (const auto migrated = App::historyLoaded(migrateFrom)) { + if (const auto migrated = _session->data().historyLoaded(migrateFrom)) { readServerHistory(migrated); } } diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 53623537c..b862dd4b0 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -130,22 +130,6 @@ namespace App { return nullptr; } - UserData *feedUser(const MTPUser &user) { - return Auth().data().user(user); - } - - UserData *feedUsers(const MTPVector &users) { - return Auth().data().processUsers(users); - } - - PeerData *feedChat(const MTPChat &chat) { - return Auth().data().chat(chat); - } - - PeerData *feedChats(const MTPVector &chats) { - return Auth().data().processChats(chats); - } - bool checkEntitiesAndViewsUpdate(const MTPDmessage &m) { auto peerId = peerFromMTP(m.vto_id); if (m.has_from_id() && peerId == Auth().userPeerId()) { @@ -337,13 +321,13 @@ namespace App { } void feedInboxRead(const PeerId &peer, MsgId upTo) { - if (const auto history = App::historyLoaded(peer)) { + if (const auto history = Auth().data().historyLoaded(peer)) { history->inboxRead(upTo); } } void feedOutboxRead(const PeerId &peer, MsgId upTo, TimeId when) { - if (auto history = App::historyLoaded(peer)) { + if (auto history = Auth().data().historyLoaded(peer)) { history->outboxRead(upTo); if (const auto user = history->peer->asUser()) { user->madeAction(when); @@ -371,7 +355,7 @@ namespace App { if (!data) return; const auto affectedHistory = (channelId != NoChannel) - ? App::history(peerFromChannel(channelId)).get() + ? Auth().data().history(peerFromChannel(channelId)).get() : nullptr; auto historiesToCheck = base::flat_set>(); @@ -393,7 +377,7 @@ namespace App { } void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink) { - if (const auto user = userLoaded(userId.v)) { + if (const auto user = Auth().data().userLoaded(userId.v)) { const auto wasShowPhone = (user->contactStatus() == UserData::ContactStatus::CanAdd); switch (myLink.type()) { case mtpc_contactLinkContact: @@ -431,51 +415,10 @@ namespace App { } } - not_null peer(PeerId id) { - return Auth().data().peer(id); - } - not_null user(UserId id) { - return Auth().data().user(id); - } - not_null chat(ChatId id) { - return Auth().data().chat(id); - } - not_null channel(ChannelId id) { - return Auth().data().channel(id); - } - PeerData *peerLoaded(PeerId id) { - return Auth().data().peerLoaded(id); - } - UserData *userLoaded(UserId id) { - return Auth().data().userLoaded(id); - } - ChatData *chatLoaded(ChatId id) { - return Auth().data().chatLoaded(id); - } - ChannelData *channelLoaded(ChannelId id) { - return Auth().data().channelLoaded(id); - } - QString peerName(const PeerData *peer, bool forDialogs) { return peer ? ((forDialogs && peer->isUser() && !peer->asUser()->nameOrPhone.isEmpty()) ? peer->asUser()->nameOrPhone : peer->name) : lang(lng_deleted); } - not_null history(PeerId peer) { - return Auth().data().history(peer); - } - - History *historyLoaded(PeerId peer) { - return Auth().data().historyLoaded(peer); - } - - not_null history(not_null peer) { - return history(peer->id); - } - - History *historyLoaded(const PeerData *peer) { - return peer ? historyLoaded(peer->id) : nullptr; - } - HistoryItem *histItemById(ChannelId channelId, MsgId itemId) { if (!itemId) return nullptr; diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index 7d5f74277..943b4c139 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -65,11 +65,6 @@ namespace App { QString formatPhone(QString phone); - UserData *feedUser(const MTPUser &user); - UserData *feedUsers(const MTPVector &users); // returns last user - PeerData *feedChat(const MTPChat &chat); - PeerData *feedChats(const MTPVector &chats); // returns last chat - bool checkEntitiesAndViewsUpdate(const MTPDmessage &m); // returns true if item found and it is not detached void updateEditedMessage(const MTPMessage &m); void addSavedGif(DocumentData *doc); @@ -83,22 +78,9 @@ namespace App { ImagePtr image(const MTPPhotoSize &size); - [[nodiscard]] not_null peer(PeerId id); - [[nodiscard]] not_null user(UserId userId); - [[nodiscard]] not_null chat(ChatId chatId); - [[nodiscard]] not_null channel(ChannelId channelId); - [[nodiscard]] PeerData *peerLoaded(PeerId id); - [[nodiscard]] UserData *userLoaded(UserId userId); - [[nodiscard]] ChatData *chatLoaded(ChatId chatId); - [[nodiscard]] ChannelData *channelLoaded(ChannelId channelId); - [[nodiscard]] QString peerName(const PeerData *peer, bool forDialogs = false); - [[nodiscard]] not_null history(PeerId peer); - [[nodiscard]] History *historyLoaded(PeerId peer); [[nodiscard]] HistoryItem *histItemById(ChannelId channelId, MsgId itemId); - [[nodiscard]] not_null history(not_null peer); - [[nodiscard]] History *historyLoaded(const PeerData *peer); [[nodiscard]] HistoryItem *histItemById( const ChannelData *channel, MsgId itemId); diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index 10a87f4a9..8a05d1908 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -386,7 +386,7 @@ AuthSession::AuthSession(const MTPUser &user) , _storage(std::make_unique()) , _notifications(std::make_unique(this)) , _data(std::make_unique(this)) -, _user(_data->user(user)) +, _user(_data->processUser(user)) , _changelogs(Core::Changelogs::Create(this)) , _supportHelper(Support::Helper::Create(this)) { _saveDataTimer.setCallback([=] { diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 1acc10f90..c16e6a0c6 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_user.h" +#include "data/data_session.h" #include "mainwidget.h" #include "mainwindow.h" #include "apiwrap.h" @@ -321,8 +322,9 @@ bool AddContactBox::onSaveUserFail(const RPCError &error) { if (MTP::isDefaultHandledError(error)) return false; _addRequest = 0; - QString err(error.type()); - QString firstName = _first->getLastText().trimmed(), lastName = _last->getLastText().trimmed(); + const auto &err = error.type(); + const auto firstName = _first->getLastText().trimmed(); + const auto lastName = _last->getLastText().trimmed(); if (err == "CHAT_TITLE_NOT_MODIFIED") { _user->setName(firstName, lastName, _user->nameOrPhone, _user->username); closeBox(); @@ -340,14 +342,14 @@ void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) { if (!isBoxShown() || !App::main()) return; const auto &d = res.c_contacts_importedContacts(); - App::feedUsers(d.vusers); + Auth().data().processUsers(d.vusers); const auto &v = d.vimported.v; const auto user = [&]() -> UserData* { if (!v.isEmpty()) { auto &c = v.front().c_importedContact(); if (c.vclient_id.v == _contactId) { - return App::userLoaded(c.vuser_id.v); + return Auth().data().userLoaded(c.vuser_id.v); } } return nullptr; @@ -368,7 +370,7 @@ void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) { void AddContactBox::onSaveUserDone(const MTPcontacts_ImportedContacts &res) { auto &d = res.c_contacts_importedContacts(); - App::feedUsers(d.vusers); + Auth().data().processUsers(d.vusers); closeBox(); } @@ -535,7 +537,7 @@ void GroupInfoBox::createGroup( : std::nullopt; } | [](auto chats) { - return App::chat(chats->front().c_chat().vid.v); + return Auth().data().chat(chats->front().c_chat().vid.v); } | [&](not_null chat) { if (!image.isNull()) { @@ -643,7 +645,7 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio : std::nullopt; } | [](auto chats) { - return App::channel(chats->front().c_channel().vid.v); + return Auth().data().channel(chats->front().c_channel().vid.v); } | [&](not_null channel) { auto image = _photo->takeResultImage(); @@ -1153,7 +1155,7 @@ void EditNameBox::save() { } void EditNameBox::saveSelfDone(const MTPUser &user) { - App::feedUsers(MTP_vector(1, user)); + _user->owner().processUsers(MTP_vector(1, user)); closeBox(); } @@ -1194,7 +1196,7 @@ RevokePublicLinkBox::Inner::Inner(QWidget *parent, Fn revokeCallback) : return data.vchats.v; }); for (const auto &chat : chats) { - if (const auto peer = App::feedChat(chat)) { + if (const auto peer = Auth().data().processChat(chat)) { if (!peer->isChannel() || peer->userName().isEmpty()) { continue; } diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index b9b2ed23f..49545f090 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -290,12 +290,12 @@ BackgroundPreviewBox::BackgroundPreviewBox( const Data::WallPaper &paper) : _text1(GenerateTextItem( this, - App::history(App::user(ServiceUserId)), + Auth().data().history(peerFromUser(ServiceUserId)), lang(lng_background_text1), false)) , _text2(GenerateTextItem( this, - App::history(App::user(ServiceUserId)), + Auth().data().history(peerFromUser(ServiceUserId)), lang(lng_background_text2), true)) , _paper(paper) diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index c9ad47155..02c318333 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -8,13 +8,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/change_phone_box.h" #include "lang/lang_keys.h" -#include "styles/style_boxes.h" #include "ui/widgets/labels.h" #include "ui/widgets/input_fields.h" #include "ui/wrap/fade_wrap.h" #include "boxes/confirm_phone_box.h" #include "ui/toast/toast.h" #include "boxes/confirm_box.h" +#include "auth_session.h" +#include "data/data_session.h" +#include "styles/style_boxes.h" namespace { @@ -260,7 +262,7 @@ void ChangePhoneBox::EnterCode::submit() { MTP_string(_hash), MTP_string(code) ), rpcDone([weak = make_weak(this)](const MTPUser &result) { - App::feedUser(result); + Auth().data().processUser(result); if (weak) { Ui::hideLayer(); } diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index e32fd51f4..27be54380 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -689,7 +689,7 @@ std::vector> ConfirmInviteBox::GetParticipants( auto result = std::vector>(); result.reserve(v.size()); for (const auto &participant : v) { - if (const auto user = App::feedUser(participant)) { + if (const auto user = Auth().data().processUser(participant)) { result.push_back(user); } } diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 64d4934e8..413ff4e8d 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/file_download.h" #include "data/data_peer_values.h" #include "data/data_chat.h" +#include "data/data_session.h" #include "window/themes/window_theme.h" auto PaintUserpicCallback( @@ -64,7 +65,7 @@ void PeerListBox::createMultiSelect() { _select->entity()->setSubmittedCallback([this](Qt::KeyboardModifiers) { content()->submitted(); }); _select->entity()->setQueryChangedCallback([this](const QString &query) { searchQueryChanged(query); }); _select->entity()->setItemRemovedCallback([this](uint64 itemId) { - if (auto peer = App::peerLoaded(itemId)) { + if (auto peer = Auth().data().peerLoaded(itemId)) { if (auto row = peerListFindRow(peer->id)) { content()->changeCheckState(row, false, PeerListRow::SetStyle::Animated); update(); @@ -327,7 +328,7 @@ auto PeerListBox::peerListCollectSelectedRows() if (!items.empty()) { result.reserve(items.size()); for (const auto itemId : items) { - result.push_back(App::peer(itemId)); + result.push_back(Auth().data().peer(itemId)); } } return result; diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index fe9b31747..4e02c875b 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -26,7 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { void ShareBotGame(not_null bot, not_null chat) { - const auto history = App::historyLoaded(chat); + const auto history = chat->owner().historyLoaded(chat); const auto randomId = rand_value(); const auto requestId = MTP::send( MTPmessages_SendMedia( @@ -182,8 +182,8 @@ void PeerListGlobalSearchController::searchDone( auto &contacts = result.c_contacts_found(); auto query = _query; if (requestId) { - App::feedUsers(contacts.vusers); - App::feedChats(contacts.vchats); + Auth().data().processUsers(contacts.vusers); + Auth().data().processChats(contacts.vchats); auto it = _queries.find(requestId); if (it != _queries.cend()) { query = it->second; @@ -193,7 +193,7 @@ void PeerListGlobalSearchController::searchDone( } const auto feedList = [&](const MTPVector &list) { for (const auto &mtpPeer : list.v) { - if (const auto peer = App::peerLoaded(peerFromMTP(mtpPeer))) { + if (const auto peer = Auth().data().peerLoaded(peerFromMTP(mtpPeer))) { delegate()->peerListSearchAddRow(peer); } } @@ -255,7 +255,7 @@ void ChatsListBoxController::rebuildRows() { }; auto added = 0; if (respectSavedMessagesChat()) { - if (appendRow(App::history(Auth().user()))) { + if (appendRow(Auth().data().history(Auth().user()))) { ++added; } } @@ -292,7 +292,7 @@ QString ChatsListBoxController::emptyBoxText() const { } std::unique_ptr ChatsListBoxController::createSearchRow(not_null peer) { - return createRow(App::history(peer)); + return createRow(peer->owner().history(peer)); } bool ChatsListBoxController::appendRow(not_null history) { diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index a8a5c715b..2883bd832 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_user.h" +#include "data/data_session.h" #include "history/history.h" #include "dialogs/dialogs_indexed_list.h" #include "auth_session.h" @@ -435,7 +436,7 @@ bool AddSpecialBoxController::checkInfoLoaded( Expects(result.type() == mtpc_channels_channelParticipant); const auto &participant = result.c_channels_channelParticipant(); - App::feedUsers(participant.vusers); + channel->owner().processUsers(participant.vusers); _additional.applyParticipant(participant.vparticipant); callback(); }).fail([=](const RPCError &error) { @@ -964,8 +965,8 @@ void AddSpecialBoxSearchController::searchGlobalDone( auto &found = result.c_contacts_found(); auto query = _query; if (requestId) { - App::feedUsers(found.vusers); - App::feedChats(found.vchats); + _peer->owner().processUsers(found.vusers); + _peer->owner().processChats(found.vchats); auto it = _globalQueries.find(requestId); if (it != _globalQueries.cend()) { query = it->second; @@ -977,7 +978,7 @@ void AddSpecialBoxSearchController::searchGlobalDone( const auto feedList = [&](const MTPVector &list) { for (const auto &mtpPeer : list.v) { const auto peerId = peerFromMTP(mtpPeer); - if (const auto peer = App::peerLoaded(peerId)) { + if (const auto peer = _peer->owner().peerLoaded(peerId)) { if (const auto user = peer->asUser()) { _additional->checkForLoaded(user); delegate()->peerListSearchAddRow(user); diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 9bedd7e31..af1665af3 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/emoji_suggestions_widget.h" #include "data/data_channel.h" #include "data/data_user.h" +#include "data/data_session.h" #include "auth_session.h" #include "messenger.h" #include "styles/style_boxes.h" @@ -220,7 +221,7 @@ void ShareBox::prepare() { applyFilterUpdate(query); }); _select->setItemRemovedCallback([=](uint64 itemId) { - if (const auto peer = App::peerLoaded(itemId)) { + if (const auto peer = Auth().data().peerLoaded(itemId)) { _inner->peerUnselected(peer); selectedChanged(); update(); @@ -334,8 +335,8 @@ void ShareBox::peopleReceived( switch (result.type()) { case mtpc_contacts_found: { auto &found = result.c_contacts_found(); - App::feedUsers(found.vusers); - App::feedChats(found.vchats); + Auth().data().processUsers(found.vusers); + Auth().data().processChats(found.vchats); _inner->peopleReceived( query, found.vmy_results.v, @@ -491,7 +492,7 @@ ShareBox::Inner::Inner( const auto dialogs = App::main()->dialogsList(); const auto self = Auth().user(); if (_filterCallback(self)) { - _chatsIndexed->addToEnd(App::history(self)); + _chatsIndexed->addToEnd(self->owner().history(self)); } for (const auto row : dialogs->all()) { if (const auto history = row->history()) { @@ -880,7 +881,7 @@ void ShareBox::Inner::changeCheckState(Chat *chat) { if (!chat) return; if (!_filter.isEmpty()) { - const auto history = App::history(chat->peer); + const auto history = chat->peer->owner().history(chat->peer); auto row = _chatsIndexed->getRow(history); if (!row) { const auto rowsByLetter = _chatsIndexed->addToEnd(history); @@ -1017,8 +1018,8 @@ void ShareBox::Inner::peopleReceived( d_byUsernameFiltered.reserve(already + my.size() + people.size()); const auto feedList = [&](const QVector &list) { for (const auto &data : list) { - if (const auto peer = App::peerLoaded(peerFromMTP(data))) { - const auto history = App::historyLoaded(peer); + if (const auto peer = Auth().data().peerLoaded(peerFromMTP(data))) { + const auto history = Auth().data().historyLoaded(peer); if (!_filterCallback(peer)) { continue; } else if (history && _chatsIndexed->getRow(history)) { @@ -1066,7 +1067,9 @@ QVector ShareBox::Inner::selected() const { QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId) { auto shareHashData = QByteArray(0x10, Qt::Uninitialized); auto shareHashDataInts = reinterpret_cast(shareHashData.data()); - auto channel = fullId.channel ? App::channelLoaded(fullId.channel) : static_cast(nullptr); + auto channel = fullId.channel + ? Auth().data().channelLoaded(fullId.channel) + : static_cast(nullptr); auto channelAccessHash = channel ? channel->access : 0ULL; auto channelAccessHashInts = reinterpret_cast(&channelAccessHash); shareHashDataInts[0] = Auth().userId(); @@ -1169,7 +1172,9 @@ void ShareGameScoreByHash(const QString &hash) { }); }; - auto channel = channelId ? App::channelLoaded(channelId) : nullptr; + const auto channel = channelId + ? Auth().data().channelLoaded(channelId) + : nullptr; if (channel || !channelId) { resolveMessageAndShareScore(channel); } else { @@ -1177,9 +1182,9 @@ void ShareGameScoreByHash(const QString &hash) { auto requestChannel = MTPchannels_GetChannels(requestChannelIds); MTP::send(requestChannel, rpcDone([=](const MTPmessages_Chats &result) { result.match([](const auto &data) { - App::feedChats(data.vchats); + Auth().data().processChats(data.vchats); }); - if (const auto channel = App::channelLoaded(channelId)) { + if (const auto channel = Auth().data().channelLoaded(channelId)) { resolveMessageAndShareScore(channel); } })); diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index f9716bad6..b86a039e2 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -201,11 +201,11 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) { auto &v = d.vdocuments.v; _pack.reserve(v.size()); _packOvers.reserve(v.size()); - for (int i = 0, l = v.size(); i < l; ++i) { - auto doc = Auth().data().document(v.at(i)); - if (!doc->sticker()) continue; + for (const auto &item : v) { + const auto document = Auth().data().processDocument(item); + if (!document->sticker()) continue; - _pack.push_back(doc); + _pack.push_back(document); _packOvers.push_back(Animation()); } auto &packs = d.vpacks.v; diff --git a/Telegram/SourceFiles/boxes/username_box.cpp b/Telegram/SourceFiles/boxes/username_box.cpp index def070a56..b82333482 100644 --- a/Telegram/SourceFiles/boxes/username_box.cpp +++ b/Telegram/SourceFiles/boxes/username_box.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/toast/toast.h" #include "messenger.h" #include "auth_session.h" +#include "data/data_session.h" #include "data/data_user.h" #include "styles/style_boxes.h" @@ -170,7 +171,7 @@ void UsernameBox::linkClick() { } void UsernameBox::onUpdateDone(const MTPUser &user) { - App::feedUsers(MTP_vector(1, user)); + Auth().data().processUser(user); closeBox(); } diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index 079d68b0e..4712651dc 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -255,9 +255,9 @@ void BoxController::loadMoreRows() { )).done([this](const MTPmessages_Messages &result) { _loadRequestId = 0; - auto handleResult = [this](auto &data) { - App::feedUsers(data.vusers); - App::feedChats(data.vchats); + auto handleResult = [&](auto &data) { + Auth().data().processUsers(data.vusers); + Auth().data().processChats(data.vchats); receivedCalls(data.vmessages.v); }; @@ -305,7 +305,7 @@ void BoxController::receivedCalls(const QVector &result) { for (const auto &message : result) { auto msgId = IdFromMessage(message); auto peerId = PeerFromMessage(message); - if (auto peer = App::peerLoaded(peerId)) { + if (auto peer = Auth().data().peerLoaded(peerId)) { auto item = Auth().data().addNewMessage(message, NewMessageExisting); insertRow(item, InsertWay::Append); } else { diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 2be4c5bbd..968c885f2 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/media_audio_track.h" #include "calls/calls_panel.h" #include "data/data_user.h" +#include "data/data_session.h" #ifdef slots #undef slots @@ -201,7 +202,7 @@ void Call::startOutgoing() { setState(State::Waiting); auto &call = result.c_phone_phoneCall(); - App::feedUsers(call.vusers); + Auth().data().processUsers(call.vusers); if (call.vphone_call.type() != mtpc_phoneCallWaiting) { LOG(("Call Error: Expected phoneCallWaiting in response to phone.requestCall()")); finish(FinishType::Failed); @@ -273,7 +274,7 @@ void Call::actuallyAnswer() { )).done([this](const MTPphone_PhoneCall &result) { Expects(result.type() == mtpc_phone_phoneCall); auto &call = result.c_phone_phoneCall(); - App::feedUsers(call.vusers); + Auth().data().processUsers(call.vusers); if (call.vphone_call.type() != mtpc_phoneCallWaiting) { LOG(("Call Error: Expected phoneCallWaiting in response to phone.acceptCall()")); finish(FinishType::Failed); @@ -487,8 +488,9 @@ void Call::confirmAcceptedCall(const MTPDphoneCallAccepted &call) { MTP_int(tgvoip::VoIPController::GetConnectionMaxLayer())) )).done([this](const MTPphone_PhoneCall &result) { Expects(result.type() == mtpc_phone_phoneCall); + auto &call = result.c_phone_phoneCall(); - App::feedUsers(call.vusers); + Auth().data().processUsers(call.vusers); if (call.vphone_call.type() != mtpc_phoneCall) { LOG(("Call Error: Expected phoneCall in response to phone.confirmCall()")); finish(FinishType::Failed); diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index 1b5fed1de..8e022d67a 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "calls/calls_call.h" #include "calls/calls_panel.h" #include "data/data_user.h" +#include "data/data_session.h" #include "media/media_audio_track.h" #include "platform/platform_specific.h" #include "mainwidget.h" @@ -222,7 +223,7 @@ bool Instance::isQuitPrevent() { void Instance::handleCallUpdate(const MTPPhoneCall &call) { if (call.type() == mtpc_phoneCallRequested) { auto &phoneCall = call.c_phoneCallRequested(); - auto user = App::userLoaded(phoneCall.vadmin_id.v); + auto user = Auth().data().userLoaded(phoneCall.vadmin_id.v); if (!user) { LOG(("API Error: User not loaded for phoneCallRequested.")); } else if (user->isSelf()) { diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 4cc593a56..64ae3e35b 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -223,7 +223,7 @@ void GifsListWidget::inlineResultsDone(const MTPmessages_BotResults &result) { auto adding = (it != _inlineCache.cend()); if (result.type() == mtpc_messages_botResults) { auto &d = result.c_messages_botResults(); - App::feedUsers(d.vusers); + Auth().data().processUsers(d.vusers); auto &v = d.vresults.v; auto queryId = d.vquery_id.v; @@ -842,12 +842,15 @@ void GifsListWidget::searchForGifs(const QString &query) { if (!_searchBot && !_searchBotRequestId) { auto username = str_const_toString(kSearchBotUsername); - _searchBotRequestId = request(MTPcontacts_ResolveUsername(MTP_string(username))).done([this](const MTPcontacts_ResolvedPeer &result) { + _searchBotRequestId = request(MTPcontacts_ResolveUsername( + MTP_string(username) + )).done([=](const MTPcontacts_ResolvedPeer &result) { Expects(result.type() == mtpc_contacts_resolvedPeer); + auto &data = result.c_contacts_resolvedPeer(); - App::feedUsers(data.vusers); - App::feedChats(data.vchats); - if (auto peer = App::peerLoaded(peerFromMTP(data.vpeer))) { + Auth().data().processUsers(data.vusers); + Auth().data().processChats(data.vchats); + if (auto peer = Auth().data().peerLoaded(peerFromMTP(data.vpeer))) { if (auto user = peer->asUser()) { _searchBot = user; } diff --git a/Telegram/SourceFiles/chat_helpers/stickers.cpp b/Telegram/SourceFiles/chat_helpers/stickers.cpp index 1909033ea..71584fb0f 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers.cpp @@ -480,9 +480,9 @@ void SpecialSetReceived( auto custom = sets.find(CustomSetId); auto pack = Pack(); pack.reserve(items.size()); - for_const (auto &mtpDocument, items) { + for (const auto &item : items) { ++dateIndex; - auto document = Auth().data().document(mtpDocument); + const auto document = Auth().data().processDocument(item); if (!document->sticker()) { continue; } @@ -662,10 +662,11 @@ void GifsReceived(const QVector &items, int32 hash) { saved.clear(); saved.reserve(items.size()); - for_const (auto &gif, items) { - auto document = Auth().data().document(gif); + for (const auto &item : items) { + const auto document = Auth().data().processDocument(item); if (!document->isGifv()) { - LOG(("API Error: bad document returned in HistoryWidget::savedGifsGot!")); + LOG(("API Error: " + "bad document returned in HistoryWidget::savedGifsGot!")); continue; } @@ -917,13 +918,13 @@ Set *FeedSetFull(const MTPmessages_StickerSet &data) { auto pack = Pack(); pack.reserve(d_docs.size()); - for (auto i = 0, l = d_docs.size(); i != l; ++i) { - auto doc = Auth().data().document(d_docs.at(i)); - if (!doc->sticker()) continue; + for (const auto &item : d_docs) { + const auto document = Auth().data().processDocument(item); + if (!document->sticker()) continue; - pack.push_back(doc); + pack.push_back(document); if (custom != sets.cend()) { - auto index = custom->stickers.indexOf(doc); + const auto index = custom->stickers.indexOf(document); if (index >= 0) { custom->stickers.removeAt(index); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 661d17ca3..8afcca20c 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -1092,7 +1092,7 @@ void StickersListWidget::searchResultsDone( setData = &d.vset.c_stickerSet(); } for (const auto &cover : d.vcovers.v) { - const auto document = Auth().data().document(cover); + const auto document = Auth().data().processDocument(cover); if (document->sticker()) { covers.push_back(document); } diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index edb8e2322..847b37f78 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "messenger.h" #include "mainwidget.h" +#include "auth_session.h" #include "application.h" #include "platform/platform_specific.h" #include "history/view/history_view_element.h" @@ -21,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/tooltip.h" #include "core/file_utilities.h" #include "data/data_user.h" +#include "data/data_session.h" namespace { @@ -247,7 +249,7 @@ TextWithEntities MentionClickHandler::getExpandedLinkTextWithEntities(ExpandLink void MentionNameClickHandler::onClick(ClickContext context) const { const auto button = context.button; if (button == Qt::LeftButton || button == Qt::MiddleButton) { - if (auto user = App::userLoaded(_userId)) { + if (auto user = Auth().data().userLoaded(_userId)) { Ui::showPeerProfile(user); } } @@ -259,7 +261,7 @@ TextWithEntities MentionNameClickHandler::getExpandedLinkTextWithEntities(Expand } QString MentionNameClickHandler::tooltip() const { - if (auto user = App::userLoaded(_userId)) { + if (auto user = Auth().data().userLoaded(_userId)) { auto name = App::peerName(user); if (name != _text) { return name; diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 8d76edbc0..7916f05ea 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/sticker_set_box.h" #include "passport/passport_form_controller.h" #include "window/window_controller.h" +#include "data/data_session.h" #include "mainwindow.h" #include "mainwidget.h" #include "messenger.h" @@ -43,7 +44,7 @@ bool JoinGroupByHash(const Match &match, const QVariant &context) { Auth().api().importChatInvite(hash); })); }, [=](const MTPDchatInviteAlready &data) { - if (const auto chat = App::feedChat(data.vchat)) { + if (const auto chat = Auth().data().processChat(data.vchat)) { App::wnd()->controller()->showPeerHistory( chat, Window::SectionShow::Way::Forward); diff --git a/Telegram/SourceFiles/data/data_channel_admins.cpp b/Telegram/SourceFiles/data/data_channel_admins.cpp index 9583871c6..811db7911 100644 --- a/Telegram/SourceFiles/data/data_channel_admins.cpp +++ b/Telegram/SourceFiles/data/data_channel_admins.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "data/data_channel.h" +#include "data/data_session.h" namespace Data { @@ -29,7 +30,7 @@ void ChannelAdminChanges::feed(UserId userId, bool isAdmin) { ChannelAdminChanges::~ChannelAdminChanges() { if (!_changes.empty()) { - if (auto history = App::historyLoaded(_channel)) { + if (const auto history = _channel->owner().historyLoaded(_channel)) { history->applyGroupAdminChanges(_changes); } } diff --git a/Telegram/SourceFiles/data/data_drafts.cpp b/Telegram/SourceFiles/data/data_drafts.cpp index e07742063..99bdf5a0d 100644 --- a/Telegram/SourceFiles/data/data_drafts.cpp +++ b/Telegram/SourceFiles/data/data_drafts.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/message_field.h" #include "history/history.h" #include "history/history_widget.h" +#include "data/data_session.h" #include "mainwidget.h" #include "storage/localstorage.h" #include "support/support_helper.h" @@ -45,7 +46,7 @@ Draft::Draft( } void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) { - const auto history = App::history(peerId); + const auto history = Auth().data().history(peerId); const auto textWithTags = TextWithTags { qs(draft.vmessage), ConvertEntitiesToTextTags( @@ -79,7 +80,7 @@ void applyPeerCloudDraft(PeerId peerId, const MTPDdraftMessage &draft) { } void clearPeerCloudDraft(PeerId peerId, TimeId date) { - const auto history = App::history(peerId); + const auto history = Auth().data().history(peerId); if (history->skipCloudDraft(QString(), MsgId(0), date)) { return; } diff --git a/Telegram/SourceFiles/data/data_feed.cpp b/Telegram/SourceFiles/data/data_feed.cpp index 70336eeeb..a7995d7fa 100644 --- a/Telegram/SourceFiles/data/data_feed.cpp +++ b/Telegram/SourceFiles/data/data_feed.cpp @@ -78,7 +78,7 @@ void Feed::indexNameParts() { } void Feed::registerOne(not_null channel) { - const auto history = App::history(channel); + const auto history = owner().history(channel); if (!base::contains(_channels, history)) { const auto invisible = (_channels.size() < 2); _channels.push_back(history); @@ -120,7 +120,7 @@ void Feed::registerOne(not_null channel) { } void Feed::unregisterOne(not_null channel) { - const auto history = App::history(channel); + const auto history = owner().history(channel); const auto i = ranges::remove(_channels, history); if (i != end(_channels)) { const auto visible = (_channels.size() > 1); @@ -339,7 +339,7 @@ bool Feed::unreadCountKnown() const { // #feed //void Feed::applyDialog(const MTPDdialogFeed &data) { // const auto addChannel = [&](ChannelId channelId) { -// if (const auto channel = App::channelLoaded(channelId)) { +// if (const auto channel = owner().channelLoaded(channelId)) { // channel->setFeed(this); // } // }; diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index ce165aa99..e53c5b304 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -338,7 +338,8 @@ bool MediaPhoto::updateInlineResultMedia(const MTPMessageMedia &media) { } auto &data = media.c_messageMediaPhoto(); if (data.has_photo() && !data.has_ttl_seconds()) { - const auto photo = parent()->history()->owner().photo(data.vphoto); + const auto photo = parent()->history()->owner().processPhoto( + data.vphoto); if (photo == _photo) { return true; } else { @@ -684,7 +685,7 @@ bool MediaFile::updateInlineResultMedia(const MTPMessageMedia &media) { } auto &data = media.c_messageMediaDocument(); if (data.has_document() && !data.has_ttl_seconds()) { - const auto document = parent()->history()->owner().document( + const auto document = parent()->history()->owner().processDocument( data.vdocument); if (document == _document) { return false; diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index e65e1e034..329e948e1 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -179,7 +179,7 @@ void PeerData::setUserpic( void PeerData::setUserpicPhoto(const MTPPhoto &data) { const auto photoId = data.match([&](const MTPDphoto &data) { - const auto photo = owner().photo(data); + const auto photo = owner().processPhoto(data); photo->peer = this; return photo->id; }, [](const MTPDphotoEmpty &data) { diff --git a/Telegram/SourceFiles/data/data_search_controller.cpp b/Telegram/SourceFiles/data/data_search_controller.cpp index 49aef7798..198e739d0 100644 --- a/Telegram/SourceFiles/data/data_search_controller.cpp +++ b/Telegram/SourceFiles/data/data_search_controller.cpp @@ -107,16 +107,16 @@ SearchResult ParseSearchResult( switch (data.type()) { case mtpc_messages_messages: { auto &d = data.c_messages_messages(); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + peer->owner().processUsers(d.vusers); + peer->owner().processChats(d.vchats); result.fullCount = d.vmessages.v.size(); return &d.vmessages.v; } break; case mtpc_messages_messagesSlice: { auto &d = data.c_messages_messagesSlice(); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + peer->owner().processUsers(d.vusers); + peer->owner().processChats(d.vchats); result.fullCount = d.vcount.v; return &d.vmessages.v; } break; @@ -129,8 +129,8 @@ SearchResult ParseSearchResult( LOG(("API Error: received messages.channelMessages when " "no channel was passed! (ParseSearchResult)")); } - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + peer->owner().processUsers(d.vusers); + peer->owner().processChats(d.vchats); result.fullCount = d.vcount.v; return &d.vmessages.v; } break; @@ -151,7 +151,7 @@ SearchResult ParseSearchResult( auto addType = NewMessageExisting; result.messageIds.reserve(messages->size()); for (const auto &message : *messages) { - if (auto item = Auth().data().addNewMessage(message, addType)) { + if (auto item = peer->owner().addNewMessage(message, addType)) { auto itemId = item->id; if ((type == Storage::SharedMediaType::kCount) || item->sharedMediaTypes().test(type)) { @@ -178,9 +178,9 @@ SearchResult ParseSearchResult( } SearchController::CacheEntry::CacheEntry(const Query &query) -: peerData(App::peer(query.peerId)) +: peerData(Auth().data().peer(query.peerId)) , migratedData(query.migratedPeerId - ? base::make_optional(Data(App::peer(query.migratedPeerId))) + ? base::make_optional(Data(Auth().data().peer(query.migratedPeerId))) : std::nullopt) { } diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 95fc1c15e..112e5188a 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -233,7 +233,7 @@ ChannelData *Session::channelLoaded(ChannelId id) const { return nullptr; } -not_null Session::user(const MTPUser &data) { +not_null Session::processUser(const MTPUser &data) { const auto result = user(data.match([](const auto &data) { return data.vid.v; })); @@ -409,7 +409,7 @@ not_null Session::user(const MTPUser &data) { return result; } -not_null Session::chat(const MTPChat &data) { +not_null Session::processChat(const MTPChat &data) { const auto result = data.match([&](const MTPDchat &data) { return peer(peerFromChat(data.vid.v)); }, [&](const MTPDchatForbidden &data) { @@ -621,7 +621,7 @@ not_null Session::chat(const MTPChat &data) { UserData *Session::processUsers(const MTPVector &data) { auto result = (UserData*)nullptr; for (const auto &user : data.v) { - result = this->user(user); + result = processUser(user); } return result; } @@ -629,7 +629,7 @@ UserData *Session::processUsers(const MTPVector &data) { PeerData *Session::processChats(const MTPVector &data) { auto result = (PeerData*)nullptr; for (const auto &chat : data.v) { - result = this->chat(chat); + result = processChat(chat); } return result; } @@ -1614,10 +1614,10 @@ not_null Session::photo(PhotoId id) { return i->second.get(); } -not_null Session::photo(const MTPPhoto &data) { +not_null Session::processPhoto(const MTPPhoto &data) { switch (data.type()) { case mtpc_photo: - return photo(data.c_photo()); + return processPhoto(data.c_photo()); case mtpc_photoEmpty: return photo(data.c_photoEmpty().vid.v); @@ -1625,13 +1625,13 @@ not_null Session::photo(const MTPPhoto &data) { Unexpected("Type in Session::photo()."); } -not_null Session::photo(const MTPDphoto &data) { +not_null Session::processPhoto(const MTPDphoto &data) { const auto result = photo(data.vid.v); photoApplyFields(result, data); return result; } -not_null Session::photo( +not_null Session::processPhoto( const MTPPhoto &data, const PreparedPhotoThumbs &thumbs) { auto thumb = (const QImage*)nullptr; @@ -1846,10 +1846,10 @@ not_null Session::document(DocumentId id) { return i->second.get(); } -not_null Session::document(const MTPDocument &data) { +not_null Session::processDocument(const MTPDocument &data) { switch (data.type()) { case mtpc_document: - return document(data.c_document()); + return processDocument(data.c_document()); case mtpc_documentEmpty: return document(data.c_documentEmpty().vid.v); @@ -1857,13 +1857,13 @@ not_null Session::document(const MTPDocument &data) { Unexpected("Type in Session::document()."); } -not_null Session::document(const MTPDdocument &data) { +not_null Session::processDocument(const MTPDdocument &data) { const auto result = document(data.vid.v); documentApplyFields(result, data); return result; } -not_null Session::document( +not_null Session::processDocument( const MTPdocument &data, QImage &&thumb) { switch (data.type()) { @@ -2077,10 +2077,10 @@ not_null Session::webpage(WebPageId id) { return i->second.get(); } -not_null Session::webpage(const MTPWebPage &data) { +not_null Session::processWebpage(const MTPWebPage &data) { switch (data.type()) { case mtpc_webPage: - return webpage(data.c_webPage()); + return processWebpage(data.c_webPage()); case mtpc_webPageEmpty: { const auto result = webpage(data.c_webPageEmpty().vid.v); if (result->pendingTill > 0) { @@ -2089,7 +2089,7 @@ not_null Session::webpage(const MTPWebPage &data) { return result; } break; case mtpc_webPagePending: - return webpage(data.c_webPagePending()); + return processWebpage(data.c_webPagePending()); case mtpc_webPageNotModified: LOG(("API Error: " "webPageNotModified is unexpected in Session::webpage().")); @@ -2098,13 +2098,13 @@ not_null Session::webpage(const MTPWebPage &data) { Unexpected("Type in Session::webpage()."); } -not_null Session::webpage(const MTPDwebPage &data) { +not_null Session::processWebpage(const MTPDwebPage &data) { const auto result = webpage(data.vid.v); webpageApplyFields(result, data); return result; } -not_null Session::webpage(const MTPDwebPagePending &data) { +not_null Session::processWebpage(const MTPDwebPagePending &data) { constexpr auto kDefaultPendingTimeout = 60; const auto result = webpage(data.vid.v); webpageApplyFields( @@ -2203,8 +2203,10 @@ void Session::webpageApplyFields( siteName, data.has_title() ? qs(data.vtitle) : QString(), description, - data.has_photo() ? photo(data.vphoto).get() : nullptr, - data.has_document() ? document(data.vdocument).get() : nullptr, + data.has_photo() ? processPhoto(data.vphoto).get() : nullptr, + (data.has_document() + ? processDocument(data.vdocument).get() + : nullptr), WebPageCollage(data), data.has_duration() ? data.vduration.v : 0, data.has_author() ? qs(data.vauthor) : QString(), @@ -2255,7 +2257,7 @@ not_null Session::game(GameId id) { return i->second.get(); } -not_null Session::game(const MTPDgame &data) { +not_null Session::processGame(const MTPDgame &data) { const auto result = game(data.vid.v); gameApplyFields(result, data); return result; @@ -2316,8 +2318,10 @@ void Session::gameApplyFields( qs(data.vshort_name), qs(data.vtitle), qs(data.vdescription), - photo(data.vphoto), - data.has_document() ? document(data.vdocument).get() : nullptr); + processPhoto(data.vphoto), + (data.has_document() + ? processDocument(data.vdocument).get() + : nullptr)); } void Session::gameApplyFields( @@ -2348,7 +2352,7 @@ not_null Session::poll(PollId id) { return i->second.get(); } -not_null Session::poll(const MTPPoll &data) { +not_null Session::processPoll(const MTPPoll &data) { return data.match([&](const MTPDpoll &data) { const auto id = data.vid.v; const auto result = poll(id); @@ -2360,8 +2364,8 @@ not_null Session::poll(const MTPPoll &data) { }); } -not_null Session::poll(const MTPDmessageMediaPoll &data) { - const auto result = poll(data.vpoll); +not_null Session::processPoll(const MTPDmessageMediaPoll &data) { + const auto result = processPoll(data.vpoll); const auto changed = result->applyResults(data.vresults); if (changed) { notifyPollUpdateDelayed(result); @@ -2375,7 +2379,7 @@ void Session::applyUpdate(const MTPDupdateMessagePoll &update) { return (i == end(_polls)) ? nullptr : update.has_poll() - ? poll(update.vpoll).get() + ? processPoll(update.vpoll).get() : i->second.get(); }(); if (updated && updated->applyResults(update.vresults)) { @@ -2949,7 +2953,7 @@ void Session::serviceNotification( const MTPMessageMedia &media) { const auto date = unixtime(); if (!userLoaded(ServiceUserId)) { - user(MTP_user( + processUser(MTP_user( MTP_flags( MTPDuser::Flag::f_first_name | MTPDuser::Flag::f_phone @@ -3098,7 +3102,7 @@ void Session::setWallpapers(const QVector &data, int32 hash) { } for (const auto &paper : data) { paper.match([&](const MTPDwallPaper &paper) { - const auto document = this->document(paper.vdocument); + const auto document = processDocument(paper.vdocument); if (document->checkWallPaperProperties()) { _wallpapers.push_back({ paper.vid.v, diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 7a4e5bd21..5063e6ae4 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -84,17 +84,25 @@ public: Storage::Cache::Database &cache(); [[nodiscard]] not_null peer(PeerId id); + [[nodiscard]] not_null peer(UserId id) = delete; [[nodiscard]] not_null user(UserId id); [[nodiscard]] not_null chat(ChatId id); [[nodiscard]] not_null channel(ChannelId id); + [[nodiscard]] not_null user(PeerId id) = delete; + [[nodiscard]] not_null chat(PeerId id) = delete; + [[nodiscard]] not_null channel(PeerId id) = delete; [[nodiscard]] PeerData *peerLoaded(PeerId id) const; + [[nodiscard]] PeerData *peerLoaded(UserId id) const = delete; [[nodiscard]] UserData *userLoaded(UserId id) const; [[nodiscard]] ChatData *chatLoaded(ChatId id) const; [[nodiscard]] ChannelData *channelLoaded(ChannelId id) const; + [[nodiscard]] UserData *userLoaded(PeerId id) const = delete; + [[nodiscard]] ChatData *chatLoaded(PeerId id) const = delete; + [[nodiscard]] ChannelData *channelLoaded(PeerId id) const = delete; - not_null user(const MTPUser &data); - not_null chat(const MTPChat &data); + not_null processUser(const MTPUser &data); + not_null processChat(const MTPChat &data); // Returns last user, if there were any. UserData *processUsers(const MTPVector &data); @@ -107,10 +115,12 @@ public: void enumerateChannels(Fn)> action) const; [[nodiscard]] PeerData *peerByUsername(const QString &username) const; - not_null history(PeerId peerId); - History *historyLoaded(PeerId peerId) const; - not_null history(not_null peer); - History *historyLoaded(const PeerData *peer); + [[nodiscard]] not_null history(PeerId peerId); + [[nodiscard]] History *historyLoaded(PeerId peerId) const; + [[nodiscard]] not_null history(UserId userId) = delete; + [[nodiscard]] History *historyLoaded(UserId userId) const = delete; + [[nodiscard]] not_null history(not_null peer); + [[nodiscard]] History *historyLoaded(const PeerData *peer); void registerSendAction( not_null history, @@ -307,8 +317,6 @@ public: -> rpl::producer; void updateSendActionAnimation(SendActionAnimationUpdate &&update); - void updateSendActionAnimation(); - int unreadBadge() const; bool unreadBadgeMuted() const; int unreadBadgeIgnoreOne(History *history) const; @@ -323,13 +331,13 @@ public: void selfDestructIn(not_null item, TimeMs delay); - not_null photo(PhotoId id); - not_null photo(const MTPPhoto &data); - not_null photo(const MTPDphoto &data); - not_null photo( + [[nodiscard]] not_null photo(PhotoId id); + not_null processPhoto(const MTPPhoto &data); + not_null processPhoto(const MTPDphoto &data); + not_null processPhoto( const MTPPhoto &data, const PreparedPhotoThumbs &thumbs); - not_null photo( + [[nodiscard]] not_null photo( PhotoId id, const uint64 &access, const QByteArray &fileReference, @@ -340,18 +348,18 @@ public: void photoConvert( not_null original, const MTPPhoto &data); - PhotoData *photoFromWeb( + [[nodiscard]] PhotoData *photoFromWeb( const MTPWebDocument &data, ImagePtr thumb = ImagePtr(), bool willBecomeNormal = false); - not_null document(DocumentId id); - not_null document(const MTPDocument &data); - not_null document(const MTPDdocument &data); - not_null document( + [[nodiscard]] not_null document(DocumentId id); + not_null processDocument(const MTPDocument &data); + not_null processDocument(const MTPDdocument &data); + not_null processDocument( const MTPdocument &data, QImage &&thumb); - not_null document( + [[nodiscard]] not_null document( DocumentId id, const uint64 &access, const QByteArray &fileReference, @@ -365,19 +373,19 @@ public: void documentConvert( not_null original, const MTPDocument &data); - DocumentData *documentFromWeb( + [[nodiscard]] DocumentData *documentFromWeb( const MTPWebDocument &data, ImagePtr thumb); - not_null webpage(WebPageId id); - not_null webpage(const MTPWebPage &data); - not_null webpage(const MTPDwebPage &data); - not_null webpage(const MTPDwebPagePending &data); - not_null webpage( + [[nodiscard]] not_null webpage(WebPageId id); + not_null processWebpage(const MTPWebPage &data); + not_null processWebpage(const MTPDwebPage &data); + not_null processWebpage(const MTPDwebPagePending &data); + [[nodiscard]] not_null webpage( WebPageId id, const QString &siteName, const TextWithEntities &content); - not_null webpage( + [[nodiscard]] not_null webpage( WebPageId id, WebPageType type, const QString &url, @@ -392,9 +400,9 @@ public: const QString &author, TimeId pendingTill); - not_null game(GameId id); - not_null game(const MTPDgame &data); - not_null game( + [[nodiscard]] not_null game(GameId id); + not_null processGame(const MTPDgame &data); + [[nodiscard]] not_null game( GameId id, const uint64 &accessHash, const QString &shortName, @@ -406,11 +414,12 @@ public: not_null original, const MTPGame &data); - not_null poll(PollId id); - not_null poll(const MTPPoll &data); - not_null poll(const MTPDmessageMediaPoll &data); + [[nodiscard]] not_null poll(PollId id); + not_null processPoll(const MTPPoll &data); + not_null processPoll(const MTPDmessageMediaPoll &data); - not_null location(const LocationCoords &coords); + [[nodiscard]] not_null location( + const LocationCoords &coords); void registerPhotoItem( not_null photo, diff --git a/Telegram/SourceFiles/data/data_shared_media.cpp b/Telegram/SourceFiles/data/data_shared_media.cpp index cf1749f1e..743827816 100644 --- a/Telegram/SourceFiles/data/data_shared_media.cpp +++ b/Telegram/SourceFiles/data/data_shared_media.cpp @@ -76,7 +76,7 @@ rpl::producer SharedMediaViewer( limitBefore, limitAfter); auto requestMediaAround = [ - peer = App::peer(key.peerId), + peer = Auth().data().peer(key.peerId), type = key.type ](const SparseIdsSliceBuilder::AroundData &data) { Auth().api().requestSharedMedia( @@ -313,7 +313,7 @@ void SharedMediaWithLastSlice::reverse() { std::optional SharedMediaWithLastSlice::LastPeerPhotoId( PeerId peerId) { - if (auto peer = App::peerLoaded(peerId)) { + if (const auto peer = Auth().data().peerLoaded(peerId)) { return peer->userpicPhotoUnknown() ? std::nullopt : base::make_optional(peer->userpicPhotoId()); diff --git a/Telegram/SourceFiles/data/data_user.h b/Telegram/SourceFiles/data/data_user.h index 3bcef79cd..a3ce0713b 100644 --- a/Telegram/SourceFiles/data/data_user.h +++ b/Telegram/SourceFiles/data/data_user.h @@ -144,7 +144,7 @@ public: return canShareThisContact() && !isContact(); } - // In feedUsers() we check only that. + // In Data::Session::processUsers() we check only that. // When actually trying to share contact we perform // a full check by canShareThisContact() call. bool canShareThisContactFast() const { diff --git a/Telegram/SourceFiles/data/data_user_photos.cpp b/Telegram/SourceFiles/data/data_user_photos.cpp index d9c0ee1c7..7715f358e 100644 --- a/Telegram/SourceFiles/data/data_user_photos.cpp +++ b/Telegram/SourceFiles/data/data_user_photos.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "auth_session.h" #include "apiwrap.h" +#include "data/data_session.h" #include "storage/storage_facade.h" #include "storage/storage_user_photos.h" @@ -207,7 +208,7 @@ rpl::producer UserPhotosViewer( consumer.put_next(builder->snapshot()); } }; - auto requestPhotosAround = [user = App::user(key.userId)]( + auto requestPhotosAround = [user = Auth().data().user(key.userId)]( PhotoId photoId) { Auth().api().requestUserPhotos(user, photoId); }; diff --git a/Telegram/SourceFiles/data/data_web_page.cpp b/Telegram/SourceFiles/data/data_web_page.cpp index fcbe56215..16fa33770 100644 --- a/Telegram/SourceFiles/data/data_web_page.cpp +++ b/Telegram/SourceFiles/data/data_web_page.cpp @@ -53,10 +53,10 @@ WebPageCollage ExtractCollage( auto &storage = Auth().data(); for (const auto &photo : photos) { - storage.photo(photo); + storage.processPhoto(photo); } for (const auto &document : documents) { - storage.document(document); + storage.processDocument(document); } auto result = WebPageCollage(); result.items.reserve(count); @@ -89,12 +89,12 @@ WebPageCollage ExtractCollage(const MTPDwebPage &data) { if (!data.has_cached_page()) { return {}; } - const auto parseMedia = [&] { + const auto processMedia = [&] { if (data.has_photo()) { - Auth().data().photo(data.vphoto); + Auth().data().processPhoto(data.vphoto); } if (data.has_document()) { - Auth().data().document(data.vdocument); + Auth().data().processDocument(data.vdocument); } }; return data.vcached_page.match([&](const auto &page) { @@ -108,13 +108,13 @@ WebPageCollage ExtractCollage(const MTPDwebPage &data) { case mtpc_pageBlockAudio: return WebPageCollage(); case mtpc_pageBlockSlideshow: - parseMedia(); + processMedia(); return ExtractCollage( block.c_pageBlockSlideshow().vitems.v, page.vphotos.v, page.vdocuments.v); case mtpc_pageBlockCollage: - parseMedia(); + processMedia(); return ExtractCollage( block.c_pageBlockCollage().vitems.v, page.vphotos.v, diff --git a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp index 616d9a534..8a68400c8 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_indexed_list.cpp @@ -95,7 +95,7 @@ void IndexedList::peerNameChanged( const base::flat_set &oldLetters) { Expects(_sortMode != SortMode::Date); - if (const auto history = App::historyLoaded(peer)) { + if (const auto history = peer->owner().historyLoaded(peer)) { if (_sortMode == SortMode::Name) { adjustByName(history, oldLetters); } else { @@ -110,7 +110,7 @@ void IndexedList::peerNameChanged( const base::flat_set &oldLetters) { Expects(_sortMode == SortMode::Date); - if (const auto history = App::historyLoaded(peer)) { + if (const auto history = peer->owner().historyLoaded(peer)) { adjustNames(list, history, oldLetters); } } diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 7fcd01ec8..f5f067dc8 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -1410,7 +1410,7 @@ void DialogsInner::updateDialogRow( if (IsServerMsgId(-row.fullId.msg)) { if (const auto peer = row.key.peer()) { if (const auto from = peer->migrateFrom()) { - if (const auto migrated = App::historyLoaded(from)) { + if (const auto migrated = from->owner().historyLoaded(from)) { row = Dialogs::RowDescriptor( migrated, FullMsgId(0, -row.fullId.msg)); @@ -1871,7 +1871,7 @@ void DialogsInner::applyDialog(const MTPDdialog &dialog) { return; } - const auto history = App::history(peerId); + const auto history = Auth().data().history(peerId); history->applyDialog(dialog); if (!history->useProxyPromotion() && !history->isPinnedDialog()) { @@ -1882,7 +1882,7 @@ void DialogsInner::applyDialog(const MTPDdialog &dialog) { } _contactsNoDialogs->del(history); if (const auto from = history->peer->migrateFrom()) { - if (const auto historyFrom = App::historyLoaded(from)) { + if (const auto historyFrom = from->owner().historyLoaded(from)) { removeDialog(historyFrom); } } else if (const auto to = history->peer->migrateTo()) { @@ -1912,7 +1912,7 @@ void DialogsInner::addSavedPeersAfter(const QDateTime &date) { const auto lastPeer = saved.last(); saved.remove(lastDate, lastPeer); - const auto history = App::history(lastPeer); + const auto history = Auth().data().history(lastPeer); history->setChatListTimeId(ServerTimeFromParsed(lastDate)); _contactsNoDialogs->del(history); } @@ -1953,7 +1953,7 @@ bool DialogsInner::searchReceived( auto msgId = IdFromMessage(message); auto peerId = PeerFromMessage(message); auto lastDate = DateFromMessage(message); - if (const auto peer = App::peerLoaded(peerId)) { + if (const auto peer = Auth().data().peerLoaded(peerId)) { if (lastDate) { const auto item = Auth().data().addNewMessage( message, @@ -2025,14 +2025,14 @@ void DialogsInner::peerSearchReceived( _peerSearchResults.clear(); _peerSearchResults.reserve(result.size()); for (const auto &mtpPeer : my) { - if (const auto peer = App::peerLoaded(peerFromMTP(mtpPeer))) { + if (const auto peer = Auth().data().peerLoaded(peerFromMTP(mtpPeer))) { if (alreadyAdded(peer)) { continue; } const auto prev = nullptr, next = nullptr; const auto position = 0; auto row = std::make_unique( - App::history(peer), + peer->owner().history(peer), prev, next, position); @@ -2047,8 +2047,8 @@ void DialogsInner::peerSearchReceived( } } for (const auto &mtpPeer : result) { - if (const auto peer = App::peerLoaded(peerFromMTP(mtpPeer))) { - if (const auto history = App::historyLoaded(peer)) { + if (const auto peer = Auth().data().peerLoaded(peerFromMTP(mtpPeer))) { + if (const auto history = peer->owner().historyLoaded(peer)) { if (history->inChatList(Dialogs::Mode::All)) { continue; // skip existing chats } @@ -2071,13 +2071,13 @@ void DialogsInner::userIsContactUpdated(not_null user) { return; } if (user->contactStatus() == UserData::ContactStatus::Contact) { - const auto history = App::history(user->id); + const auto history = user->owner().history(user->id); _contacts->addByName(history); if (!shownDialogs()->getRow(history) && !_dialogs->contains(history)) { _contactsNoDialogs->addByName(history); } - } else if (const auto history = App::historyLoaded(user)) { + } else if (const auto history = user->owner().historyLoaded(user)) { if (_selected && _selected->history() == history) { _selected = nullptr; } @@ -2196,9 +2196,9 @@ void DialogsInner::searchInChat(Dialogs::Key key, UserData *from) { _searchInMigrated = nullptr; if (const auto peer = key.peer()) { if (const auto migrateTo = peer->migrateTo()) { - return searchInChat(App::history(migrateTo), from); + return searchInChat(peer->owner().history(migrateTo), from); } else if (const auto migrateFrom = peer->migrateFrom()) { - _searchInMigrated = App::history(migrateFrom); + _searchInMigrated = peer->owner().history(migrateFrom); } } _searchInChat = key; @@ -2544,7 +2544,7 @@ DialogsInner::ChosenRow DialogsInner::computeChosenRow() const { }; } else if (base::in_range(_peerSearchSelected, 0, _peerSearchResults.size())) { return { - App::history(_peerSearchResults[_peerSearchSelected]->peer), + Auth().data().history(_peerSearchResults[_peerSearchSelected]->peer), Data::UnreadMessagePosition }; } else if (base::in_range(_searchedSelected, 0, _searchResults.size())) { @@ -2666,7 +2666,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryBefore( FullMsgId(NoChannel, ShowAtUnreadMsgId)); } return Dialogs::RowDescriptor( - App::history(_peerSearchResults.back()->peer), + Auth().data().history(_peerSearchResults.back()->peer), FullMsgId(NoChannel, ShowAtUnreadMsgId)); } } @@ -2683,7 +2683,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryBefore( for (auto b = _peerSearchResults.cbegin(), i = b + 1, e = _peerSearchResults.cend(); i != e; ++i) { if ((*i)->peer == whichHistory->peer) { return Dialogs::RowDescriptor( - App::history((*(i - 1))->peer), + Auth().data().history((*(i - 1))->peer), FullMsgId(NoChannel, ShowAtUnreadMsgId)); } } @@ -2739,7 +2739,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryAfter( ++i; if (i != e) { return Dialogs::RowDescriptor( - App::history((*i)->peer), + Auth().data().history((*i)->peer), FullMsgId(NoChannel, ShowAtUnreadMsgId)); } else if (!_searchResults.empty()) { return Dialogs::RowDescriptor( @@ -2758,7 +2758,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryAfter( FullMsgId(NoChannel, ShowAtUnreadMsgId)); } else if (!_peerSearchResults.empty()) { return Dialogs::RowDescriptor( - App::history(_peerSearchResults.front()->peer), + Auth().data().history(_peerSearchResults.front()->peer), FullMsgId(NoChannel, ShowAtUnreadMsgId)); } else if (!_searchResults.empty()) { return Dialogs::RowDescriptor( @@ -2786,7 +2786,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryFirst() const { FullMsgId(NoChannel, ShowAtUnreadMsgId)); } else if (!_peerSearchResults.empty()) { return Dialogs::RowDescriptor( - App::history(_peerSearchResults.front()->peer), + Auth().data().history(_peerSearchResults.front()->peer), FullMsgId(NoChannel, ShowAtUnreadMsgId)); } else if (!_searchResults.empty()) { return Dialogs::RowDescriptor( @@ -2811,7 +2811,7 @@ Dialogs::RowDescriptor DialogsInner::chatListEntryLast() const { _searchResults.back()->item()->fullId()); } else if (!_peerSearchResults.empty()) { return Dialogs::RowDescriptor( - App::history(_peerSearchResults.back()->peer), + Auth().data().history(_peerSearchResults.back()->peer), FullMsgId(NoChannel, ShowAtUnreadMsgId)); } else if (!_filterResults.empty()) { return Dialogs::RowDescriptor( diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index a5a8a52d7..99a5cb3eb 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -310,7 +310,7 @@ void DialogsWidget::createDialog(Dialogs::Key key) { _inner->createDialog(key); const auto history = key.history(); if (creating && history && history->peer->migrateFrom()) { - if (const auto migrated = App::historyLoaded( + if (const auto migrated = history->owner().historyLoaded( history->peer->migrateFrom())) { if (migrated->inChatList(Dialogs::Mode::All)) { _inner->removeDialog(migrated); @@ -445,8 +445,8 @@ void DialogsWidget::dialogsReceived( const auto [dialogsList, messagesList] = [&] { const auto process = [&](const auto &data) { - App::feedUsers(data.vusers); - App::feedChats(data.vchats); + Auth().data().processUsers(data.vusers); + Auth().data().processChats(data.vchats); return std::make_tuple(&data.vdialogs.v, &data.vmessages.v); }; switch (dialogs.type()) { @@ -514,7 +514,7 @@ void DialogsWidget::updateDialogsOffset( if (lastDate) { _dialogsOffsetDate = lastDate; _dialogsOffsetId = lastMsgId; - _dialogsOffsetPeer = App::peer(lastPeer); + _dialogsOffsetPeer = Auth().data().peer(lastPeer); } else { _dialogsFull = true; } @@ -564,8 +564,8 @@ void DialogsWidget::pinnedDialogsReceived( if (_pinnedDialogsRequestId != requestId) return; auto &data = result.c_messages_peerDialogs(); - App::feedUsers(data.vusers); - App::feedChats(data.vchats); + Auth().data().processUsers(data.vusers); + Auth().data().processChats(data.vchats); Auth().data().applyPinnedDialogs(data.vdialogs.v); applyReceivedDialogs(data.vdialogs.v, data.vmessages.v); @@ -932,8 +932,8 @@ void DialogsWidget::searchReceived( auto &d = result.c_messages_messages(); if (_searchRequest != 0) { // Don't apply cached data! - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + Auth().data().processUsers(d.vusers); + Auth().data().processChats(d.vchats); } auto &msgs = d.vmessages.v; if (!_inner->searchReceived(msgs, type, msgs.size())) { @@ -949,8 +949,8 @@ void DialogsWidget::searchReceived( auto &d = result.c_messages_messagesSlice(); if (_searchRequest != 0) { // Don't apply cached data! - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + Auth().data().processUsers(d.vusers); + Auth().data().processChats(d.vchats); } auto &msgs = d.vmessages.v; if (!_inner->searchReceived(msgs, type, d.vcount.v)) { @@ -979,8 +979,8 @@ void DialogsWidget::searchReceived( } if (_searchRequest != 0) { // Don't apply cached data! - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + Auth().data().processUsers(d.vusers); + Auth().data().processChats(d.vchats); } auto &msgs = d.vmessages.v; if (!_inner->searchReceived(msgs, type, d.vcount.v)) { @@ -1026,8 +1026,8 @@ void DialogsWidget::peerSearchReceived( switch (result.type()) { case mtpc_contacts_found: { auto &d = result.c_contacts_found(); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + Auth().data().processUsers(d.vusers); + Auth().data().processChats(d.vchats); _inner->peerSearchReceived(q, d.vmy_results.v, d.vresults.v); } break; } @@ -1186,9 +1186,9 @@ void DialogsWidget::setSearchInChat(Dialogs::Key chat, UserData *from) { _searchInMigrated = nullptr; if (const auto peer = chat.peer()) { if (const auto migrateTo = peer->migrateTo()) { - return setSearchInChat(App::history(migrateTo), from); + return setSearchInChat(peer->owner().history(migrateTo), from); } else if (const auto migrateFrom = peer->migrateFrom()) { - _searchInMigrated = App::history(migrateFrom); + _searchInMigrated = peer->owner().history(migrateFrom); } } const auto searchInPeerUpdated = (_searchInChat != chat); diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 39b27bcf3..b37afec81 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -160,7 +160,7 @@ void searchByHashtag(const QString &tag, PeerData *inPeer) { m->searchMessages( tag + ' ', (inPeer - ? App::history(inPeer).get() + ? inPeer->owner().history(inPeer).get() : Dialogs::Key())); } } @@ -799,7 +799,7 @@ DefineRefVar(Global, base::Variable, WorkMode); DefineRefVar(Global, base::Observable, UnreadCounterUpdate); DefineRefVar(Global, base::Observable, PeerChooseCancel); - + DefineVar(Global, QString, CallOutputDeviceID); DefineVar(Global, QString, CallInputDeviceID); DefineVar(Global, int, CallOutputVolume); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 0cdc13e81..92c97990e 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -216,7 +216,7 @@ InnerWidget::InnerWidget( : RpWidget(parent) , _controller(controller) , _channel(channel) -, _history(App::history(channel)) +, _history(channel->owner().history(channel)) , _scrollDateCheck([this] { scrollDateCheck(); }) , _emptyText( st::historyAdminLogEmptyWidth @@ -405,7 +405,7 @@ void InnerWidget::requestAdmins() { return std::make_pair(userId, canEdit); }) | ranges::view::transform([&](auto &&pair) { return std::make_pair( - App::userLoaded(pair.first), + Auth().data().userLoaded(pair.first), pair.second); }) | ranges::view::filter([&](auto &&pair) { return (pair.first != nullptr); @@ -588,13 +588,23 @@ void InnerWidget::preloadMore(Direction direction) { auto maxId = (direction == Direction::Up) ? _minId : 0; auto minId = (direction == Direction::Up) ? 0 : _maxId; auto perPage = _items.empty() ? kEventsFirstPage : kEventsPerPage; - requestId = request(MTPchannels_GetAdminLog(MTP_flags(flags), _channel->inputChannel, MTP_string(_searchQuery), filter, MTP_vector(admins), MTP_long(maxId), MTP_long(minId), MTP_int(perPage))).done([this, &requestId, &loadedFlag, direction](const MTPchannels_AdminLogResults &result) { + requestId = request(MTPchannels_GetAdminLog( + MTP_flags(flags), + _channel->inputChannel, + MTP_string(_searchQuery), + filter, + MTP_vector(admins), + MTP_long(maxId), + MTP_long(minId), + MTP_int(perPage) + )).done([=, &requestId, &loadedFlag](const MTPchannels_AdminLogResults &result) { Expects(result.type() == mtpc_channels_adminLogResults); + requestId = 0; auto &results = result.c_channels_adminLogResults(); - App::feedUsers(results.vusers); - App::feedChats(results.vchats); + _channel->owner().processUsers(results.vusers); + _channel->owner().processChats(results.vchats); if (!loadedFlag) { addEvents(direction, results.vevents.v); } @@ -1167,7 +1177,7 @@ void InnerWidget::suggestRestrictUser(not_null user) { Expects(result.type() == mtpc_channels_channelParticipant); auto &participant = result.c_channels_channelParticipant(); - App::feedUsers(participant.vusers); + _channel->owner().processUsers(participant.vusers); auto type = participant.vparticipant.type(); if (type == mtpc_channelParticipantBanned) { auto &banned = participant.vparticipant.c_channelParticipantBanned(); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index dcb9d8887..658be3dfb 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -128,7 +128,7 @@ PhotoData *GenerateChatPhoto( photoSizes.reserve(2); photoSizes.push_back(MTP_photoSize(MTP_string("a"), photo.vphoto_small, MTP_int(160), MTP_int(160), MTP_int(0))); photoSizes.push_back(MTP_photoSize(MTP_string("c"), photo.vphoto_big, MTP_int(640), MTP_int(640), MTP_int(0))); - return Auth().data().photo(MTP_photo( + return Auth().data().processPhoto(MTP_photo( MTP_flags(0), MTP_long(photoId), MTP_long(0), @@ -253,7 +253,7 @@ TextWithEntities GenerateBannedChangeText( auto GenerateUserString(MTPint userId) { // User name in "User name (@username)" format with entities. - auto user = App::user(userId.v); + auto user = Auth().data().user(userId.v); auto name = TextWithEntities { App::peerName(user) }; auto entityData = QString::number(user->id) + '.' @@ -377,7 +377,7 @@ void GenerateItems( Expects(history->peer->isChannel()); auto id = event.vid.v; - auto from = App::user(event.vuser_id.v); + auto from = Auth().data().user(event.vuser_id.v); auto channel = history->peer->asChannel(); auto &action = event.vaction; auto date = event.vdate.v; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp index 0858cbad2..008e83523 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "base/timer.h" #include "data/data_channel.h" +#include "data/data_session.h" #include "lang/lang_keys.h" #include "styles/style_history.h" #include "styles/style_window.h" @@ -285,7 +286,7 @@ not_null Widget::channel() const { Dialogs::RowDescriptor Widget::activeChat() const { return { - App::history(channel()), + channel()->owner().history(channel()), FullMsgId(channel()->bareId(), ShowAtUnreadMsgId) }; } diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index a2d4af0ce..c830e2bb2 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -766,9 +766,9 @@ void History::eraseFromUnreadMentions(MsgId msgId) { void History::addUnreadMentionsSlice(const MTPmessages_Messages &result) { auto count = 0; auto messages = (const QVector*)nullptr; - auto getMessages = [](auto &list) { - App::feedUsers(list.vusers); - App::feedChats(list.vchats); + auto getMessages = [&](auto &list) { + owner().processUsers(list.vusers); + owner().processChats(list.vchats); return &list.vmessages.v; }; switch (result.type()) { @@ -952,12 +952,11 @@ void History::applyServiceChanges( switch (action.type()) { case mtpc_messageActionChatAddUser: { auto &d = action.c_messageActionChatAddUser(); - if (auto megagroup = peer->asMegagroup()) { - auto mgInfo = megagroup->mgInfo.get(); + if (const auto megagroup = peer->asMegagroup()) { + const auto mgInfo = megagroup->mgInfo.get(); Assert(mgInfo != nullptr); - auto &v = d.vusers.v; - for (auto i = 0, l = v.size(); i != l; ++i) { - if (auto user = App::userLoaded(peerFromUser(v[i]))) { + for (const auto &userId : d.vusers.v) { + if (const auto user = owner().userLoaded(userId.v)) { if (!base::contains(mgInfo->lastParticipants, user)) { mgInfo->lastParticipants.push_front(user); Notify::peerUpdatedDelayed(peer, Notify::PeerUpdate::Flag::MembersChanged); @@ -1003,12 +1002,12 @@ void History::applyServiceChanges( case mtpc_messageActionChatDeleteUser: { auto &d = action.c_messageActionChatDeleteUser(); - auto uid = peerFromUser(d.vuser_id); - if (lastKeyboardFrom == uid) { + auto uid = d.vuser_id.v; + if (lastKeyboardFrom == peerFromUser(uid)) { clearLastKeyboard(); } if (auto megagroup = peer->asMegagroup()) { - if (auto user = App::userLoaded(uid)) { + if (auto user = owner().userLoaded(uid)) { auto mgInfo = megagroup->mgInfo.get(); Assert(mgInfo != nullptr); auto i = ranges::find( @@ -1047,7 +1046,7 @@ void History::applyServiceChanges( if (d.vphoto.type() == mtpc_photo) { auto &sizes = d.vphoto.c_photo().vsizes.v; if (!sizes.isEmpty()) { - auto photo = _owner->photo(d.vphoto.c_photo()); + auto photo = _owner->processPhoto(d.vphoto.c_photo()); if (photo) photo->peer = peer; auto &smallSize = sizes.front(); auto &bigSize = sizes.back(); @@ -1084,7 +1083,7 @@ void History::applyServiceChanges( if (const auto chat = peer->asChat()) { chat->addFlags(MTPDchat::Flag::f_deactivated); const auto &d = action.c_messageActionChatMigrateTo(); - if (const auto channel = App::channelLoaded(d.vchannel_id.v)) { + if (const auto channel = owner().channelLoaded(d.vchannel_id.v)) { Data::ApplyMigration(chat, channel); } } @@ -1094,7 +1093,7 @@ void History::applyServiceChanges( if (const auto channel = peer->asChannel()) { channel->addFlags(MTPDchannel::Flag::f_megagroup); const auto &d = action.c_messageActionChannelMigrateFrom(); - if (const auto chat = App::chatLoaded(d.vchat_id.v)) { + if (const auto chat = owner().chatLoaded(d.vchat_id.v)) { Data::ApplyMigration(chat, channel); } } @@ -1482,7 +1481,7 @@ void History::inboxRead(MsgId upTo) { setInboxReadTill(upTo); updateChatListEntry(); if (peer->migrateTo()) { - if (auto migrateTo = App::historyLoaded(peer->migrateTo()->id)) { + if (auto migrateTo = peer->owner().historyLoaded(peer->migrateTo()->id)) { migrateTo->updateChatListEntry(); } } @@ -1899,7 +1898,7 @@ History *History::migrateSibling() const { } return PeerId(0); }(); - return App::historyLoaded(addFromId); + return owner().historyLoaded(addFromId); } int History::chatListUnreadCount() const { @@ -1997,7 +1996,7 @@ bool History::loadedAtTop() const { bool History::isReadyFor(MsgId msgId) { if (msgId < 0 && -msgId < ServerMaxMsgId && peer->migrateFrom()) { // Old group history. - return App::history(peer->migrateFrom()->id)->isReadyFor(-msgId); + return owner().history(peer->migrateFrom()->id)->isReadyFor(-msgId); } if (msgId == ShowAtTheEndMsgId) { @@ -2005,7 +2004,7 @@ bool History::isReadyFor(MsgId msgId) { } if (msgId == ShowAtUnreadMsgId) { if (const auto migratePeer = peer->migrateFrom()) { - if (const auto migrated = App::historyLoaded(migratePeer)) { + if (const auto migrated = owner().historyLoaded(migratePeer)) { if (migrated->unreadCount()) { return migrated->isReadyFor(msgId); } @@ -2026,7 +2025,7 @@ bool History::isReadyFor(MsgId msgId) { void History::getReadyFor(MsgId msgId) { if (msgId < 0 && -msgId < ServerMaxMsgId && peer->migrateFrom()) { - const auto migrated = App::history(peer->migrateFrom()->id); + const auto migrated = owner().history(peer->migrateFrom()->id); migrated->getReadyFor(-msgId); if (migrated->isEmpty()) { unloadBlocks(); @@ -2035,7 +2034,7 @@ void History::getReadyFor(MsgId msgId) { } if (msgId == ShowAtUnreadMsgId) { if (const auto migratePeer = peer->migrateFrom()) { - if (const auto migrated = App::historyLoaded(migratePeer)) { + if (const auto migrated = owner().historyLoaded(migratePeer)) { if (migrated->unreadCount()) { unloadBlocks(); migrated->getReadyFor(msgId); @@ -2047,7 +2046,7 @@ void History::getReadyFor(MsgId msgId) { if (!isReadyFor(msgId)) { unloadBlocks(); if (const auto migratePeer = peer->migrateFrom()) { - if (const auto migrated = App::historyLoaded(migratePeer)) { + if (const auto migrated = owner().historyLoaded(migratePeer)) { migrated->unloadBlocks(); } } @@ -2383,7 +2382,7 @@ void History::dialogEntryApplied() { } else if (const auto channel = peer->asChannel()) { const auto inviter = channel->inviter; if (inviter != 0 && channel->amIn()) { - if (const auto from = App::userLoaded(inviter)) { + if (const auto from = owner().userLoaded(inviter)) { unloadBlocks(); addNewerSlice(QVector()); insertJoinedMessage(true); @@ -2401,7 +2400,7 @@ void History::dialogEntryApplied() { if (inviter > 0 && chatListTimeId() <= channel->inviteDate && channel->amIn()) { - if (const auto from = App::userLoaded(inviter)) { + if (const auto from = owner().userLoaded(inviter)) { insertJoinedMessage(true); } } @@ -2582,15 +2581,15 @@ bool History::isMegagroup() const { not_null History::migrateToOrMe() const { if (const auto to = peer->migrateTo()) { - return App::history(to); + return owner().history(to); } - // We could get it by App::history(peer), but we optimize. + // We could get it by owner().history(peer), but we optimize. return const_cast(this); } History *History::migrateFrom() const { if (const auto from = peer->migrateFrom()) { - return App::history(from); + return owner().history(from); } return nullptr; } @@ -2636,7 +2635,7 @@ HistoryService *History::insertJoinedMessage(bool unread) { } const auto inviter = (peer->asChannel()->inviter > 0) - ? App::userLoaded(peer->asChannel()->inviter) + ? owner().userLoaded(peer->asChannel()->inviter) : nullptr; if (!inviter) { return nullptr; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index de6226190..e82b6dac3 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -164,7 +164,7 @@ HistoryItem::HistoryItem( UserId from) : id(id) , _history(history) -, _from(from ? App::user(from) : history->peer) +, _from(from ? history->owner().user(from) : history->peer) , _flags(flags) , _date(date) { App::historyRegItem(this); diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 74a885ab6..74fbdcaa7 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -21,11 +21,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_user.h" #include "data/data_file_origin.h" +#include "auth_session.h" #include "styles/style_widgets.h" #include "styles/style_history.h" void HistoryMessageVia::create(UserId userId) { - bot = App::user(peerFromUser(userId)); + bot = Auth().data().user(userId); maxWidth = st::msgServiceNameFont->width( lng_inline_bot_via(lt_inline_bot, '@' + bot->username)); link = std::make_shared([bot = this->bot] { diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 84a2b5321..1620bb131 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -185,7 +185,7 @@ void FastShareMessage(not_null item) { continue; } - const auto history = App::history(peer); + const auto history = peer->owner().history(peer); if (!comment.text.isEmpty()) { auto message = ApiWrap::MessageToSend(history); message.textWithTags = comment; @@ -673,10 +673,12 @@ void HistoryMessage::createComponents(const CreateConfig &config) { } if (const auto forwarded = Get()) { forwarded->originalDate = config.originalDate; - forwarded->originalSender = App::peer(config.senderOriginal); + forwarded->originalSender = history()->owner().peer( + config.senderOriginal); forwarded->originalId = config.originalId; forwarded->originalAuthor = config.authorOriginal; - forwarded->savedFromPeer = App::peerLoaded(config.savedFromPeer); + forwarded->savedFromPeer = history()->owner().peerLoaded( + config.savedFromPeer); forwarded->savedFromMsgId = config.savedFromMsgId; } if (const auto markup = Get()) { @@ -789,7 +791,7 @@ std::unique_ptr HistoryMessage::CreateMedia( return media.vphoto.match([&](const MTPDphoto &photo) -> Result { return std::make_unique( item, - item->history()->owner().photo(photo)); + item->history()->owner().processPhoto(photo)); }, [](const MTPDphotoEmpty &) -> Result { return nullptr; }); @@ -809,7 +811,7 @@ std::unique_ptr HistoryMessage::CreateMedia( return document.match([&](const MTPDdocument &document) -> Result { return std::make_unique( item, - item->history()->owner().document(document)); + item->history()->owner().processDocument(document)); }, [](const MTPDdocumentEmpty &) -> Result { return nullptr; }); @@ -819,11 +821,11 @@ std::unique_ptr HistoryMessage::CreateMedia( }, [&](const MTPDwebPagePending &webpage) -> Result { return std::make_unique( item, - item->history()->owner().webpage(webpage)); + item->history()->owner().processWebpage(webpage)); }, [&](const MTPDwebPage &webpage) -> Result { return std::make_unique( item, - item->history()->owner().webpage(webpage)); + item->history()->owner().processWebpage(webpage)); }, [](const MTPDwebPageNotModified &) -> Result { LOG(("API Error: " "webPageNotModified is unexpected in message media.")); @@ -833,14 +835,14 @@ std::unique_ptr HistoryMessage::CreateMedia( return media.vgame.match([&](const MTPDgame &game) { return std::make_unique( item, - item->history()->owner().game(game)); + item->history()->owner().processGame(game)); }); }, [&](const MTPDmessageMediaInvoice &media) -> Result { return std::make_unique(item, media); }, [&](const MTPDmessageMediaPoll &media) -> Result { return std::make_unique( item, - item->history()->owner().poll(media)); + item->history()->owner().processPoll(media)); }, [](const MTPDmessageMediaEmpty &) -> Result { return nullptr; }, [](const MTPDmessageMediaUnsupported &) -> Result { diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index f5372a206..1935ebfb0 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -39,7 +39,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { auto result = PreparedText{}; auto &users = action.vusers.v; if (users.size() == 1) { - auto u = App::user(peerFromUser(users[0])); + auto u = history()->owner().user(users[0].v); if (u == _from) { result.links.push_back(fromLink()); result.text = lng_action_user_joined(lt_from, fromLinkText()); @@ -54,7 +54,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { } else { result.links.push_back(fromLink()); for (auto i = 0, l = users.size(); i != l; ++i) { - auto user = App::user(peerFromUser(users[i])); + auto user = history()->owner().user(users[i].v); result.links.push_back(user->createOpenLink()); auto linkText = textcmdLink(i + 2, user->name); @@ -113,7 +113,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { result.links.push_back(fromLink()); result.text = lng_action_user_left(lt_from, fromLinkText()); } else { - auto user = App::user(peerFromUser(action.vuser_id)); + auto user = history()->owner().user(action.vuser_id.v); result.links.push_back(fromLink()); result.links.push_back(user->createOpenLink()); result.text = lng_action_kick_user(lt_from, fromLinkText(), lt_user, textcmdLink(2, user->name)); @@ -293,7 +293,7 @@ void HistoryService::applyAction(const MTPMessageAction &action) { _media = std::make_unique( this, history()->peer, - history()->owner().photo(photo)); + history()->owner().processPhoto(photo)); }, [](const MTPDphotoEmpty &) { }); }, [&](const MTPDmessageActionChatCreate &) { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 4c1c29b35..671f34754 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1290,7 +1290,7 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived(const QString &query, U return false; } bot->botInfo->inlineReturnPeerId = 0; - History *h = App::history(toPeerId); + const auto h = bot->owner().history(toPeerId); TextWithTags textWithTags = { '@' + bot->username + ' ' + query, TextWithTags::Tags() }; MessageCursor cursor = { textWithTags.text.size(), textWithTags.text.size(), QFIXED_MAX }; h->setLocalDraft(std::make_unique(textWithTags, 0, cursor, false)); @@ -1596,7 +1596,7 @@ void HistoryWidget::showHistory( _historyInited = false; if (peerId) { - _peer = App::peer(peerId); + _peer = Auth().data().peer(peerId); _channel = peerToChannel(_peer->id); _canSendMessages = _peer->canWrite(); _tabbedSelector->setCurrentPeer(_peer); @@ -1626,7 +1626,7 @@ void HistoryWidget::showHistory( if (_peer) { Auth().downloader().clearPriorities(); - _history = App::history(_peer); + _history = _peer->owner().history(_peer); _migrated = _history->migrateFrom(); if (_migrated && !_migrated->isEmpty() @@ -2153,7 +2153,7 @@ void HistoryWidget::newUnreadMsg( void HistoryWidget::historyToDown(History *history) { history->forgetScrollState(); - if (auto migrated = App::historyLoaded(history->peer->migrateFrom())) { + if (auto migrated = history->owner().historyLoaded(history->peer->migrateFrom())) { migrated->forgetScrollState(); } if (history == _history) { @@ -2218,15 +2218,15 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages switch (messages.type()) { case mtpc_messages_messages: { auto &d(messages.c_messages_messages()); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + _history->owner().processUsers(d.vusers); + _history->owner().processChats(d.vchats); histList = &d.vmessages.v; count = histList->size(); } break; case mtpc_messages_messagesSlice: { auto &d(messages.c_messages_messagesSlice()); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + _history->owner().processUsers(d.vusers); + _history->owner().processChats(d.vchats); histList = &d.vmessages.v; count = d.vcount.v; } break; @@ -2237,8 +2237,8 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages } else { LOG(("API Error: received messages.channelMessages when no channel was passed! (HistoryWidget::messagesReceived)")); } - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + _history->owner().processUsers(d.vusers); + _history->owner().processChats(d.vchats); histList = &d.vmessages.v; count = d.vcount.v; } break; @@ -3449,7 +3449,7 @@ void HistoryWidget::inlineBotResolveDone( const auto &data = result.c_contacts_resolvedPeer(); // Notify::inlineBotRequesting(false); const auto resolvedBot = [&]() -> UserData* { - if (const auto result = App::feedUsers(data.vusers)) { + if (const auto result = Auth().data().processUsers(data.vusers)) { if (result->botInfo && !result->botInfo->inlinePlaceholder.isEmpty()) { return result; @@ -3457,7 +3457,7 @@ void HistoryWidget::inlineBotResolveDone( } return nullptr; }(); - App::feedChats(data.vchats); + Auth().data().processChats(data.vchats); const auto query = ParseInlineBotQuery(_field); if (_inlineBotUsername == query.username) { @@ -4200,7 +4200,7 @@ void HistoryWidget::sendFileConfirmed( Auth().uploader().upload(newId, file); - const auto history = App::history(file->to.peer); + const auto history = Auth().data().history(file->to.peer); const auto peer = history->peer; auto options = ApiWrap::SendOptions(history); @@ -5897,7 +5897,7 @@ void HistoryWidget::gotPreview(QString links, const MTPMessageMedia &result, mtp } if (result.type() == mtpc_messageMediaWebPage) { const auto &data = result.c_messageMediaWebPage().vwebpage; - const auto page = Auth().data().webpage(data); + const auto page = Auth().data().processWebpage(data); _previewCache.insert(links, page->id); if (page->pendingTill > 0 && page->pendingTill <= unixtime()) { page->pendingTill = -1; diff --git a/Telegram/SourceFiles/history/media/history_media_contact.cpp b/Telegram/SourceFiles/history/media/history_media_contact.cpp index 54e18dcab..2b9c71a3c 100644 --- a/Telegram/SourceFiles/history/media/history_media_contact.cpp +++ b/Telegram/SourceFiles/history/media/history_media_contact.cpp @@ -93,7 +93,9 @@ QSize HistoryContact::countOptimalSize() { const auto item = _parent->data(); auto maxWidth = st::msgFileMinWidth; - _contact = _userId ? App::userLoaded(_userId) : nullptr; + _contact = _userId + ? item->history()->owner().userLoaded(_userId) + : nullptr; if (_contact) { _contact->loadUserpic(); } else { diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp index 16ef90930..8a32cfced 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/scroll_area.h" #include "ui/search_field_controller.h" #include "data/data_user.h" +#include "data/data_session.h" #include "apiwrap.h" #include "styles/style_info.h" #include "styles/style_widgets.h" @@ -101,13 +102,13 @@ void ListController::loadMoreRows() { return data.vchats.v; }); if (!chats.empty()) { - for (const auto &chatData : chats) { - if (const auto chat = App::feedChat(chatData)) { - if (!chat->migrateTo()) { + for (const auto &chat : chats) { + if (const auto peer = _user->owner().processChat(chat)) { + if (!peer->migrateTo()) { delegate()->peerListAppendRow( - createRow(chat)); + createRow(peer)); } - _preloadGroupId = chat->bareId(); + _preloadGroupId = peer->bareId(); _allLoaded = false; } } diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp index 6231d9a64..c53c248d5 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp @@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/search_field_controller.h" #include "ui/widgets/scroll_area.h" #include "data/data_user.h" +#include "data/data_session.h" +#include "auth_session.h" #include "styles/style_info.h" namespace Info { @@ -28,7 +30,7 @@ object_ptr Memento::createWidget( auto result = object_ptr( parent, controller, - App::user(userId())); + Auth().data().user(userId())); result->setInternalState(geometry, this); return std::move(result); } diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp index 8dedec384..50322bd3b 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp +++ b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp @@ -111,7 +111,7 @@ auto ChannelsController::createRow(not_null history) std::unique_ptr ChannelsController::createRestoredRow( not_null peer) { - return createRow(App::history(peer)); + return createRow(peer->owner().history(peer)); } void ChannelsController::prepare() { @@ -274,8 +274,8 @@ void NotificationsController::applyFeedDialogs( const MTPmessages_Dialogs &result) { const auto [dialogsList, messagesList] = [&] { const auto process = [&](const auto &data) { - App::feedUsers(data.vusers); - App::feedChats(data.vchats); + _feed->owner().processUsers(data.vusers); + _feed->owner().processChats(data.vchats); return std::make_tuple(&data.vdialogs.v, &data.vmessages.v); }; switch (result.type()) { @@ -303,7 +303,7 @@ void NotificationsController::applyFeedDialogs( case mtpc_dialog: { if (const auto peerId = peerFromMTP(dialog.c_dialog().vpeer)) { if (peerIsChannel(peerId)) { - const auto history = App::history(peerId); + const auto history = Auth().data().history(peerId); const auto channel = history->peer->asChannel(); history->applyDialog(dialog.c_dialog()); channels.emplace_back(channel); @@ -422,7 +422,7 @@ void EditController::loadMoreRows() { // // for (const auto &chat : data.vchats.v) { // if (chat.type() == mtpc_channel) { -// channels.push_back(App::channel(chat.c_channel().vid.v)); +// channels.push_back(_feed->owner().channel(chat.c_channel().vid.v)); // } // } // } break; diff --git a/Telegram/SourceFiles/info/info_content_widget.cpp b/Telegram/SourceFiles/info/info_content_widget.cpp index bad0918eb..9db9a9756 100644 --- a/Telegram/SourceFiles/info/info_content_widget.cpp +++ b/Telegram/SourceFiles/info/info_content_widget.cpp @@ -23,6 +23,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_section_widget.h" #include "info/info_controller.h" #include "boxes/peer_list_box.h" +#include "data/data_session.h" +#include "auth_session.h" #include "styles/style_info.h" #include "styles/style_profile.h" @@ -259,7 +261,7 @@ void ContentWidget::refreshSearchField(bool shown) { Key ContentMemento::key() const { if (const auto peerId = this->peerId()) { - return Key(App::peer(peerId)); + return Key(Auth().data().peer(peerId)); } else if (const auto feed = this->feed()) { return Key(feed); } else { diff --git a/Telegram/SourceFiles/info/info_controller.cpp b/Telegram/SourceFiles/info/info_controller.cpp index 58f244c71..3bdb61134 100644 --- a/Telegram/SourceFiles/info/info_controller.cpp +++ b/Telegram/SourceFiles/info/info_controller.cpp @@ -18,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer.h" #include "data/data_channel.h" #include "data/data_chat.h" +#include "data/data_session.h" +#include "auth_session.h" #include "window/window_controller.h" namespace Info { @@ -26,7 +28,7 @@ namespace { not_null CorrectPeer(PeerId peerId) { Expects(peerId != 0); - auto result = App::peer(peerId); + const auto result = Auth().data().peer(peerId); if (const auto to = result->migrateTo()) { return to; } @@ -84,6 +86,11 @@ rpl::producer AbstractController::mediaSourceQueryValue() const { return rpl::single(QString()); } +AbstractController::AbstractController(not_null parent) +: Navigation(&parent->session()) +, _parent(parent) { +} + PeerId AbstractController::peerId() const { if (const auto peer = key().peer()) { return peer->id; @@ -117,7 +124,7 @@ Controller::Controller( , _widget(widget) , _key(memento->key()) , _migrated(memento->migratedPeerId() - ? App::peer(memento->migratedPeerId()).get() + ? Auth().data().peer(memento->migratedPeerId()).get() : nullptr) , _section(memento->section()) { updateSearchControllers(memento); diff --git a/Telegram/SourceFiles/info/info_controller.h b/Telegram/SourceFiles/info/info_controller.h index 09c1f9024..a8ce32f4d 100644 --- a/Telegram/SourceFiles/info/info_controller.h +++ b/Telegram/SourceFiles/info/info_controller.h @@ -99,9 +99,7 @@ private: class AbstractController : public Window::Navigation { public: - AbstractController(not_null parent) - : _parent(parent) { - } + AbstractController(not_null parent); virtual Key key() const = 0; virtual PeerData *migrated() const = 0; diff --git a/Telegram/SourceFiles/info/info_memento.cpp b/Telegram/SourceFiles/info/info_memento.cpp index 40671525b..d48e7b2ee 100644 --- a/Telegram/SourceFiles/info/info_memento.cpp +++ b/Telegram/SourceFiles/info/info_memento.cpp @@ -20,6 +20,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peer_list_box.h" #include "data/data_channel.h" #include "data/data_chat.h" +#include "data/data_session.h" +#include "auth_session.h" namespace Info { @@ -90,7 +92,7 @@ std::unique_ptr Memento::DefaultContent( Section section) { Expects(peerId != 0); - auto peer = App::peer(peerId); + auto peer = Auth().data().peer(peerId); if (auto to = peer->migrateTo()) { peer = to; } diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 222650fbf..b224f3a25 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -199,7 +199,7 @@ Key WrapWidget::key() const { Dialogs::RowDescriptor WrapWidget::activeChat() const { if (const auto peer = key().peer()) { - return Dialogs::RowDescriptor(App::history(peer), FullMsgId()); + return Dialogs::RowDescriptor(peer->owner().history(peer), FullMsgId()); } else if (const auto feed = key().feed()) { return Dialogs::RowDescriptor(feed, FullMsgId()); } else if (key().settingsSelf()) { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp index 0d33f3ec0..c90e84de8 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp @@ -102,10 +102,10 @@ std::unique_ptr Result::create(uint64 queryId, const MTPBotInlineResult if (r.has_title()) result->_title = qs(r.vtitle); if (r.has_description()) result->_description = qs(r.vdescription); if (r.has_photo()) { - result->_photo = Auth().data().photo(r.vphoto); + result->_photo = Auth().data().processPhoto(r.vphoto); } if (r.has_document()) { - result->_document = Auth().data().document(r.vdocument); + result->_document = Auth().data().processDocument(r.vdocument); } message = &r.vsend_message; } break; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index acf8f438d..8b187fe33 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document.h" #include "data/data_channel.h" #include "data/data_user.h" +#include "data/data_session.h" #include "styles/style_chat_helpers.h" #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" @@ -1023,7 +1024,7 @@ void Widget::inlineResultsDone(const MTPmessages_BotResults &result) { auto adding = (it != _inlineCache.cend()); if (result.type() == mtpc_messages_botResults) { auto &d = result.c_messages_botResults(); - App::feedUsers(d.vusers); + Auth().data().processUsers(d.vusers); auto &v = d.vresults.v; auto queryId = d.vquery_id.v; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index a8629e00b..ffe31f940 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -117,6 +117,13 @@ constexpr auto kSendViewsTimeout = TimeMs(1000); // Cache background scaled image after 3s. constexpr auto kCacheBackgroundTimeout = 3000; +enum class DataIsLoadedResult { + NotLoaded = 0, + FromNotLoaded = 1, + MentionNotLoaded = 2, + Ok = 3, +}; + bool IsForceLogoutNotification(const MTPDupdateServiceNotification &data) { return qs(data.vtype).startsWith(qstr("AUTH_KEY_DROP_")); } @@ -148,6 +155,107 @@ bool HasForceLogoutNotification(const MTPUpdates &updates) { return false; } +bool ForwardedInfoDataLoaded( + not_null session, + const MTPMessageFwdHeader &header) { + if (header.type() != mtpc_messageFwdHeader) { + return true; + } + auto &info = header.c_messageFwdHeader(); + if (info.has_channel_id()) { + if (!session->data().channelLoaded(info.vchannel_id.v)) { + return false; + } + if (info.has_from_id()) { + const auto from = session->data().user(info.vfrom_id.v); + if (from->loadedStatus == PeerData::NotLoaded) { + return false; + } + } + } else { + if (info.has_from_id() && !session->data().userLoaded(info.vfrom_id.v)) { + return false; + } + } + return true; +} + +bool MentionUsersLoaded( + not_null session, + const MTPVector &entities) { + for_const (auto &entity, entities.v) { + auto type = entity.type(); + if (type == mtpc_messageEntityMentionName) { + if (!session->data().userLoaded(entity.c_messageEntityMentionName().vuser_id.v)) { + return false; + } + } else if (type == mtpc_inputMessageEntityMentionName) { + auto &inputUser = entity.c_inputMessageEntityMentionName().vuser_id; + if (inputUser.type() == mtpc_inputUser) { + if (!session->data().userLoaded(inputUser.c_inputUser().vuser_id.v)) { + return false; + } + } + } + } + return true; +} + +DataIsLoadedResult AllDataLoadedForMessage( + not_null session, + const MTPMessage &message) { + return message.match([&](const MTPDmessage &message) { + if (!message.is_post() && message.has_from_id()) { + if (!session->data().userLoaded(message.vfrom_id.v)) { + return DataIsLoadedResult::FromNotLoaded; + } + } + if (message.has_via_bot_id()) { + if (!session->data().userLoaded(message.vvia_bot_id.v)) { + return DataIsLoadedResult::NotLoaded; + } + } + if (message.has_fwd_from() + && !ForwardedInfoDataLoaded(session, message.vfwd_from)) { + return DataIsLoadedResult::NotLoaded; + } + if (message.has_entities() + && !MentionUsersLoaded(session, message.ventities)) { + return DataIsLoadedResult::MentionNotLoaded; + } + return DataIsLoadedResult::Ok; + }, [&](const MTPDmessageService &message) { + if (!message.is_post() && message.has_from_id()) { + if (!session->data().userLoaded(message.vfrom_id.v)) { + return DataIsLoadedResult::FromNotLoaded; + } + } + return message.vaction.match( + [&](const MTPDmessageActionChatAddUser &action) { + for (const MTPint &userId : action.vusers.v) { + if (!session->data().userLoaded(userId.v)) { + return DataIsLoadedResult::NotLoaded; + } + } + return DataIsLoadedResult::Ok; + }, [&](const MTPDmessageActionChatJoinedByLink &action) { + if (!session->data().userLoaded(action.vinviter_id.v)) { + return DataIsLoadedResult::NotLoaded; + } + return DataIsLoadedResult::Ok; + }, [&](const MTPDmessageActionChatDeleteUser &action) { + if (!session->data().userLoaded(action.vuser_id.v)) { + return DataIsLoadedResult::NotLoaded; + } + return DataIsLoadedResult::Ok; + }, [](const auto &) { + return DataIsLoadedResult::Ok; + }); + }, [](const MTPDmessageEmpty &message) { + return DataIsLoadedResult::Ok; + }); +} + } // namespace enum StackItemType { @@ -287,9 +395,9 @@ MainWidget::MainWidget( handleAudioUpdate(audioId); } }); - subscribe(Auth().calls().currentCallChanged(), [this](Calls::Call *call) { setCurrentCall(call); }); + subscribe(session().calls().currentCallChanged(), [this](Calls::Call *call) { setCurrentCall(call); }); - Auth().data().currentExportView( + session().data().currentExportView( ) | rpl::start_with_next([=](Export::View::PanelController *view) { setCurrentExportView(view); }, lifetime()); @@ -301,9 +409,9 @@ MainWidget::MainWidget( updateDialogsWidthAnimated(); }); rpl::merge( - Auth().settings().dialogsWidthRatioChanges() + session().settings().dialogsWidthRatioChanges() | rpl::map([] { return rpl::empty_value(); }), - Auth().settings().thirdColumnWidthChanges() + session().settings().thirdColumnWidthChanges() | rpl::map([] { return rpl::empty_value(); }) ) | rpl::start_with_next( [this] { updateControlsGeometry(); }, @@ -384,6 +492,10 @@ MainWidget::MainWidget( } } +AuthSession &MainWidget::session() const { + return _controller->session(); +} + void MainWidget::setupConnectingWidget() { using namespace rpl::mappers; _connecting = Window::ConnectingWidget::CreateDefaultWidget( @@ -469,7 +581,7 @@ void MainWidget::floatPlayerEnumerateSections(Fn item) { auto isVisible = false; - Auth().data().queryItemVisibility().notify({ item, &isVisible }, true); + session().data().queryItemVisibility().notify({ item, &isVisible }, true); return isVisible; } @@ -486,16 +598,16 @@ void MainWidget::floatPlayerClosed(FullMsgId itemId) { bool MainWidget::setForwardDraft(PeerId peerId, MessageIdsList &&items) { Expects(peerId != 0); - const auto peer = App::peer(peerId); + const auto peer = session().data().peer(peerId); const auto error = GetErrorTextForForward( peer, - Auth().data().idsToItems(items)); + session().data().idsToItems(items)); if (!error.isEmpty()) { Ui::show(Box(error), LayerOption::KeepOther); return false; } - App::history(peer)->setForwardDraft(std::move(items)); + peer->owner().history(peer)->setForwardDraft(std::move(items)); Ui::showPeerHistory(peer, ShowAtUnreadMsgId); _history->cancelReply(); return true; @@ -507,7 +619,7 @@ bool MainWidget::shareUrl( const QString &text) { Expects(peerId != 0); - const auto peer = App::peer(peerId); + const auto peer = session().data().peer(peerId); if (!peer->canWrite()) { Ui::show(Box(lang(lng_share_cant))); return false; @@ -521,7 +633,7 @@ bool MainWidget::shareUrl( url.size() + 1 + text.size(), QFIXED_MAX }; - auto history = App::history(peer->id); + auto history = peer->owner().history(peer); history->setLocalDraft( std::make_unique(textWithTags, 0, cursor, false)); history->clearEditDraft(); @@ -543,12 +655,12 @@ void MainWidget::replyToItem(not_null item) { bool MainWidget::inlineSwitchChosen(PeerId peerId, const QString &botAndQuery) { Expects(peerId != 0); - const auto peer = App::peer(peerId); + const auto peer = session().data().peer(peerId); if (!peer->canWrite()) { Ui::show(Box(lang(lng_inline_switch_cant))); return false; } - History *h = App::history(peer); + const auto h = peer->owner().history(peer); TextWithTags textWithTags = { botAndQuery, TextWithTags::Tags() }; MessageCursor cursor = { botAndQuery.size(), botAndQuery.size(), QFIXED_MAX }; h->setLocalDraft(std::make_unique(textWithTags, 0, cursor, false)); @@ -571,11 +683,11 @@ void MainWidget::finishForwarding(not_null history) { auto toForward = history->validateForwardDraft(); if (!toForward.empty()) { auto options = ApiWrap::SendOptions(history); - Auth().api().forwardMessages(std::move(toForward), options); + session().api().forwardMessages(std::move(toForward), options); cancelForwarding(history); } - Auth().data().sendHistoryChangeNotifications(); + session().data().sendHistoryChangeNotifications(); historyToDown(history); dialogsToUp(); } @@ -583,7 +695,7 @@ void MainWidget::finishForwarding(not_null history) { bool MainWidget::sendPaths(PeerId peerId) { Expects(peerId != 0); - auto peer = App::peer(peerId); + auto peer = session().data().peer(peerId); if (!peer->canWrite()) { Ui::show(Box(lang(lng_forward_send_files_cant))); return false; @@ -603,7 +715,7 @@ void MainWidget::onFilesOrForwardDrop( Expects(peerId != 0); if (data->hasFormat(qsl("application/x-td-forward"))) { - if (!setForwardDraft(peerId, Auth().data().takeMimeForwardIds())) { + if (!setForwardDraft(peerId, session().data().takeMimeForwardIds())) { // We've already released the mouse button, so the forwarding is cancelled. if (_hider) { _hider->startHide(); @@ -611,7 +723,7 @@ void MainWidget::onFilesOrForwardDrop( } } } else { - auto peer = App::peer(peerId); + auto peer = session().data().peer(peerId); if (!peer->canWrite()) { Ui::show(Box(lang(lng_forward_send_files_cant))); return; @@ -747,19 +859,19 @@ void MainWidget::deleteLayer(FullMsgId itemId) { void MainWidget::cancelUploadLayer(not_null item) { const auto itemId = item->fullId(); - Auth().uploader().pause(itemId); + session().uploader().pause(itemId); const auto stopUpload = [=] { Ui::hideLayer(); if (const auto item = App::histItemById(itemId)) { const auto history = item->history(); item->destroy(); history->requestChatListMessage(); - Auth().data().sendHistoryChangeNotifications(); + session().data().sendHistoryChangeNotifications(); } - Auth().uploader().unpause(); + session().uploader().unpause(); }; const auto continueUpload = [=] { - Auth().uploader().unpause(); + session().uploader().unpause(); }; Ui::show(Box( lang(lng_selected_cancel_sure_this), @@ -772,7 +884,7 @@ void MainWidget::cancelUploadLayer(not_null item) { void MainWidget::deletePhotoLayer(PhotoData *photo) { if (!photo) return; Ui::show(Box(lang(lng_delete_photo_sure), lang(lng_box_delete), crl::guard(this, [=] { - Auth().api().clearPeerPhoto(photo); + session().api().clearPeerPhoto(photo); Ui::hideLayer(); }))); } @@ -870,7 +982,7 @@ void MainWidget::deleteMessages( void MainWidget::deletedContact(UserData *user, const MTPcontacts_Link &result) { auto &d(result.c_contacts_link()); - App::feedUsers(MTP_vector(1, d.vuser)); + session().data().processUsers(MTP_vector(1, d.vuser)); App::feedUserLink(MTP_int(peerToUser(user->id)), d.vmy_link, d.vforeign_link); } @@ -884,13 +996,13 @@ void MainWidget::deleteConversation( if (_controller->activeChatCurrent().peer() == peer) { Ui::showChatsList(); } - if (const auto history = App::historyLoaded(peer->id)) { - Auth().data().setPinnedDialog(history, false); + if (const auto history = session().data().historyLoaded(peer->id)) { + session().data().setPinnedDialog(history, false); removeDialog(history); if (const auto channel = peer->asMegagroup()) { channel->addFlags(MTPDchannel::Flag::f_left); if (const auto from = channel->getMigrateFromChat()) { - if (const auto migrated = App::historyLoaded(from)) { + if (const auto migrated = session().data().historyLoaded(from)) { migrated->updateChatListExistence(); } } @@ -919,7 +1031,7 @@ void MainWidget::deleteAndExit(ChatData *chat) { MTP::send( MTPmessages_DeleteChatUser( chat->inputChat, - Auth().user()->inputUser), + session().user()->inputUser), rpcDone(&MainWidget::deleteHistoryAfterLeave, peer), rpcFail(&MainWidget::leaveChatFailed, peer)); } @@ -1057,7 +1169,7 @@ void MainWidget::messagesAffected( ptsUpdateAndApply(data.vpts.v, data.vpts_count.v); } - if (const auto history = App::historyLoaded(peer)) { + if (const auto history = session().data().historyLoaded(peer)) { history->requestChatListMessage(); } } @@ -1085,7 +1197,7 @@ void MainWidget::handleAudioUpdate(const AudioMsgId &audioId) { } if (const auto item = App::histItemById(audioId.contextId())) { - Auth().data().requestItemRepaint(item); + session().data().requestItemRepaint(item); } if (const auto items = InlineBots::Layout::documentItems()) { if (const auto i = items->find(document); i != items->end()) { @@ -1325,7 +1437,7 @@ void MainWidget::exportTopBarHeightUpdated() { void MainWidget::documentLoadProgress(FileLoader *loader) { if (auto documentId = loader ? loader->objId() : 0) { - documentLoadProgress(Auth().data().document(documentId)); + documentLoadProgress(session().data().document(documentId)); } } @@ -1334,8 +1446,8 @@ void MainWidget::documentLoadProgress(DocumentData *document) { document->performActionOnLoad(); } - Auth().data().requestDocumentViewRepaint(document); - Auth().documentUpdated.notify(document, true); + session().data().requestDocumentViewRepaint(document); + session().documentUpdated.notify(document, true); if (!document->loaded() && document->isAudioFile()) { Media::Player::instance()->documentLoadProgress(document); @@ -1346,7 +1458,7 @@ void MainWidget::documentLoadFailed(FileLoader *loader, bool started) { auto documentId = loader ? loader->objId() : 0; if (!documentId) return; - auto document = Auth().data().document(documentId); + auto document = session().data().document(documentId); if (started) { const auto origin = loader->fileOrigin(); const auto failedFileName = loader->fileName(); @@ -1664,7 +1776,7 @@ void MainWidget::ui_showPeerHistory( PeerId peerId, const SectionShow ¶ms, MsgId showAtMsgId) { - if (auto peer = App::peerLoaded(peerId)) { + if (auto peer = session().data().peerLoaded(peerId)) { if (peer->migrateTo()) { peer = peer->migrateTo(); peerId = peer->id; @@ -2324,7 +2436,7 @@ void MainWidget::newUnreadMsg( void MainWidget::markActiveHistoryAsRead() { if (const auto activeHistory = _history->history()) { - Auth().api().readServerHistory(activeHistory); + session().api().readServerHistory(activeHistory); } } @@ -2475,7 +2587,7 @@ void MainWidget::resizeEvent(QResizeEvent *e) { void MainWidget::updateControlsGeometry() { updateWindowAdaptiveLayout(); - if (Auth().settings().dialogsWidthRatio() > 0) { + if (session().settings().dialogsWidthRatio() > 0) { _a_dialogsWidth.finish(); } if (!_a_dialogsWidth.animating()) { @@ -2488,9 +2600,9 @@ void MainWidget::updateControlsGeometry() { Window::SectionShow::Way::ClearStack, anim::type::instant, anim::activation::background); - if (Auth().settings().tabbedSelectorSectionEnabled()) { + if (session().settings().tabbedSelectorSectionEnabled()) { _history->pushTabbedSelectorToThirdSection(params); - } else if (Auth().settings().thirdSectionInfoEnabled()) { + } else if (session().settings().thirdSectionInfoEnabled()) { if (const auto key = _controller->activeChatCurrent()) { _controller->showSection( Info::Memento::Default(key), @@ -2625,14 +2737,14 @@ void MainWidget::ensureFirstColumnResizeAreaCreated() { auto newRatio = (newWidth < st::columnMinimalWidthLeft / 2) ? 0. : float64(newWidth) / width(); - Auth().settings().setDialogsWidthRatio(newRatio); + session().settings().setDialogsWidthRatio(newRatio); }; auto moveFinishedCallback = [=] { if (Adaptive::OneColumn()) { return; } - if (Auth().settings().dialogsWidthRatio() > 0) { - Auth().settings().setDialogsWidthRatio( + if (session().settings().dialogsWidthRatio() > 0) { + session().settings().setDialogsWidthRatio( float64(_dialogsWidth) / width()); } Local::writeUserSettings(); @@ -2649,14 +2761,14 @@ void MainWidget::ensureThirdColumnResizeAreaCreated() { } auto moveLeftCallback = [=](int globalLeft) { auto newWidth = mapToGlobal(QPoint(width(), 0)).x() - globalLeft; - Auth().settings().setThirdColumnWidth(newWidth); + session().settings().setThirdColumnWidth(newWidth); }; auto moveFinishedCallback = [=] { if (!Adaptive::ThreeColumn() || !_thirdSection) { return; } - Auth().settings().setThirdColumnWidth(snap( - Auth().settings().thirdColumnWidth(), + session().settings().setThirdColumnWidth(snap( + session().settings().thirdColumnWidth(), st::columnMinimalWidthThird, st::columnMaximalWidthThird)); Local::writeUserSettings(); @@ -2668,12 +2780,12 @@ void MainWidget::ensureThirdColumnResizeAreaCreated() { } void MainWidget::updateDialogsWidthAnimated() { - if (Auth().settings().dialogsWidthRatio() > 0) { + if (session().settings().dialogsWidthRatio() > 0) { return; } auto dialogsWidth = _dialogsWidth; updateWindowAdaptiveLayout(); - if (!Auth().settings().dialogsWidthRatio() + if (!session().settings().dialogsWidthRatio() && (_dialogsWidth != dialogsWidth || _a_dialogsWidth.animating())) { _dialogs->startWidthAnimation(); @@ -2731,9 +2843,9 @@ void MainWidget::updateThirdColumnToCurrentChat( // Like in _controller->showPeerInfo() // if (Adaptive::ThreeColumn() - && !Auth().settings().thirdSectionInfoEnabled()) { - Auth().settings().setThirdSectionInfoEnabled(true); - Auth().saveSettingsDelayed(); + && !session().settings().thirdSectionInfoEnabled()) { + session().settings().setThirdSectionInfoEnabled(true); + session().saveSettingsDelayed(); } _controller->showSection( @@ -2745,18 +2857,18 @@ void MainWidget::updateThirdColumnToCurrentChat( _history->pushTabbedSelectorToThirdSection(params); }; if (Adaptive::ThreeColumn() - && Auth().settings().tabbedSelectorSectionEnabled() + && session().settings().tabbedSelectorSectionEnabled() && key) { if (!canWrite) { switchInfoFast(); - Auth().settings().setTabbedSelectorSectionEnabled(true); - Auth().settings().setTabbedReplacedWithInfo(true); - } else if (Auth().settings().tabbedReplacedWithInfo()) { - Auth().settings().setTabbedReplacedWithInfo(false); + session().settings().setTabbedSelectorSectionEnabled(true); + session().settings().setTabbedReplacedWithInfo(true); + } else if (session().settings().tabbedReplacedWithInfo()) { + session().settings().setTabbedReplacedWithInfo(false); switchTabbedFast(); } } else { - Auth().settings().setTabbedReplacedWithInfo(false); + session().settings().setTabbedReplacedWithInfo(false); if (!key) { if (_thirdSection) { _thirdSection.destroy(); @@ -2764,7 +2876,7 @@ void MainWidget::updateThirdColumnToCurrentChat( updateControlsGeometry(); } } else if (Adaptive::ThreeColumn() - && Auth().settings().thirdSectionInfoEnabled()) { + && session().settings().thirdSectionInfoEnabled()) { switchInfoFast(); } } @@ -2835,13 +2947,13 @@ void MainWidget::handleAdaptiveLayoutUpdate() { void MainWidget::updateWindowAdaptiveLayout() { auto layout = _controller->computeColumnLayout(); - auto dialogsWidthRatio = Auth().settings().dialogsWidthRatio(); + auto dialogsWidthRatio = session().settings().dialogsWidthRatio(); // Check if we are in a single-column layout in a wide enough window // for the normal layout. If so, switch to the normal layout. if (layout.windowLayout == Adaptive::WindowLayout::OneColumn) { auto chatWidth = layout.chatWidth; - //if (Auth().settings().tabbedSelectorSectionEnabled() + //if (session().settings().tabbedSelectorSectionEnabled() // && chatWidth >= _history->minimalWidthForTabbedSelectorSection()) { // chatWidth -= _history->tabbedSelectorSectionWidth(); //} @@ -2878,7 +2990,7 @@ void MainWidget::updateWindowAdaptiveLayout() { //} } - Auth().settings().setDialogsWidthRatio(dialogsWidthRatio); + session().settings().setDialogsWidthRatio(dialogsWidthRatio); auto useSmallColumnWidth = !Adaptive::OneColumn() && !dialogsWidthRatio @@ -2916,7 +3028,7 @@ void MainWidget::feedUpdateVector( } feedUpdate(update); } - Auth().data().sendHistoryChangeNotifications(); + session().data().sendHistoryChangeNotifications(); } void MainWidget::feedMessageIds(const MTPVector &updates) { @@ -2983,9 +3095,9 @@ void MainWidget::gotChannelDifference( case mtpc_updates_channelDifferenceTooLong: { auto &d = diff.c_updates_channelDifferenceTooLong(); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); - auto history = App::historyLoaded(channel->id); + session().data().processUsers(d.vusers); + session().data().processChats(d.vchats); + auto history = session().data().historyLoaded(channel->id); if (history) { history->setNotLoadedAtBottom(); } @@ -3001,7 +3113,7 @@ void MainWidget::gotChannelDifference( _history->updateHistoryDownVisibility(); _history->preloadHistoryIfNeeded(); } - Auth().api().requestChannelRangeDifference(history); + session().api().requestChannelRangeDifference(history); } if (d.has_timeout()) { @@ -3036,8 +3148,8 @@ void MainWidget::gotChannelDifference( void MainWidget::feedChannelDifference( const MTPDupdates_channelDifference &data) { - App::feedUsers(data.vusers); - App::feedChats(data.vchats); + session().data().processUsers(data.vusers); + session().data().processChats(data.vchats); _handlingChannelDifference = true; feedMessageIds(data.vother_updates); @@ -3184,9 +3296,9 @@ void MainWidget::feedDifference( const MTPVector &chats, const MTPVector &msgs, const MTPVector &other) { - Auth().checkAutoLock(); - App::feedUsers(users); - App::feedChats(chats); + session().checkAutoLock(); + session().data().processUsers(users); + session().data().processChats(chats); feedMessageIds(other); App::feedMsgs(msgs, NewMessageUnread); feedUpdateVector(other, true); @@ -3316,13 +3428,13 @@ void MainWidget::sendPing() { } void MainWidget::start() { - Auth().api().requestNotifySettings(MTP_inputNotifyUsers()); - Auth().api().requestNotifySettings(MTP_inputNotifyChats()); - Auth().api().requestNotifySettings(MTP_inputNotifyBroadcasts()); + session().api().requestNotifySettings(MTP_inputNotifyUsers()); + session().api().requestNotifySettings(MTP_inputNotifyChats()); + session().api().requestNotifySettings(MTP_inputNotifyBroadcasts()); Local::readSavedPeers(); cSetOtherOnline(0); - Auth().user()->loadUserpic(); + session().user()->loadUserpic(); MTP::send(MTPupdates_GetState(), rpcDone(&MainWidget::gotState)); update(); @@ -3334,7 +3446,7 @@ void MainWidget::start() { Local::readFavedStickers(); Local::readSavedGifs(); if (const auto availableAt = Local::ReadExportSettings().availableAt) { - Auth().data().suggestStartExport(availableAt); + session().data().suggestStartExport(availableAt); } _history->start(); @@ -3353,7 +3465,7 @@ void MainWidget::openPeerByName( FullMsgId clickFromMessageId) { Messenger::Instance().hideMediaView(); - if (const auto peer = Auth().data().peerByUsername(username)) { + if (const auto peer = session().data().peerByUsername(username)) { if (msgId == ShowAtGameShareMsgId) { if (peer->isUser() && peer->asUser()->botInfo && !startToken.isEmpty()) { peer->asUser()->botInfo->shareGameShortName = startToken; @@ -3420,12 +3532,12 @@ void MainWidget::usernameResolveDone(QPair msgIdAndStartToken, c if (result.type() != mtpc_contacts_resolvedPeer) return; const auto &d(result.c_contacts_resolvedPeer()); - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + session().data().processUsers(d.vusers); + session().data().processChats(d.vchats); PeerId peerId = peerFromMTP(d.vpeer); if (!peerId) return; - PeerData *peer = App::peer(peerId); + PeerData *peer = session().data().peer(peerId); MsgId msgId = msgIdAndStartToken.first; QString startToken = msgIdAndStartToken.second; if (msgId == ShowAtProfileMsgId && !peer->isChannel()) { @@ -3479,7 +3591,7 @@ void MainWidget::incrementSticker(DocumentData *sticker) { } bool writeRecentStickers = false; - auto &sets = Auth().data().stickerSetsRef(); + auto &sets = session().data().stickerSetsRef(); auto it = sets.find(Stickers::CloudRecentSetId); if (it == sets.cend()) { if (it == sets.cend()) { @@ -3500,7 +3612,7 @@ void MainWidget::incrementSticker(DocumentData *sticker) { auto index = it->stickers.indexOf(sticker); if (index > 0) { if (it->dates.empty()) { - Auth().api().requestRecentStickersForce(); + session().api().requestRecentStickersForce(); } else { Assert(it->dates.size() == it->stickers.size()); it->dates.erase(it->dates.begin() + index); @@ -3532,7 +3644,7 @@ void MainWidget::incrementSticker(DocumentData *sticker) { it->emoji[emoji].push_front(sticker); } } else { - Auth().api().requestRecentStickersForce(); + session().api().requestRecentStickersForce(); } writeRecentStickers = true; @@ -3619,7 +3731,7 @@ bool MainWidget::isActive() const { bool MainWidget::doWeReadServerHistory() const { return isActive() - && !Auth().supportMode() + && !session().supportMode() && !_mainSection && _history->doWeReadServerHistory(); } @@ -3648,7 +3760,7 @@ MainWidget::~MainWidget() { void MainWidget::updateOnline(bool gotOtherOffline) { if (this != App::main()) return; - InvokeQueued(this, [] { Auth().checkAutoLock(); }); + InvokeQueued(this, [=] { session().checkAutoLock(); }); bool isOnline = App::wnd()->isActive(); int updateIn = Global::OnlineUpdatePeriod(); @@ -3677,7 +3789,7 @@ void MainWidget::updateOnline(bool gotOtherOffline) { _lastSetOnline = ms; _onlineRequest = MTP::send(MTPaccount_UpdateStatus(MTP_bool(!isOnline))); - const auto self = Auth().user(); + const auto self = session().user(); self->onlineTill = unixtime() + (isOnline ? (Global::OnlineUpdatePeriod() / 1000) : -1); Notify::peerUpdatedDelayed( self, @@ -3697,14 +3809,14 @@ void MainWidget::saveDraftToCloud() { _history->saveFieldToHistoryLocalDraft(); const auto peer = _history->peer(); - if (const auto history = App::historyLoaded(peer)) { + if (const auto history = session().data().historyLoaded(peer)) { writeDrafts(history); const auto localDraft = history->localDraft(); const auto cloudDraft = history->cloudDraft(); if (!Data::draftsAreEqual(localDraft, cloudDraft) - && !Auth().supportMode()) { - Auth().api().saveDraftToCloudDelayed(history); + && !session().supportMode()) { + session().api().saveDraftToCloudDelayed(history); } } } @@ -3717,7 +3829,7 @@ void MainWidget::writeDrafts(History *history) { Local::MessageDraft storedLocalDraft, storedEditDraft; MessageCursor localCursor, editCursor; if (const auto localDraft = history->localDraft()) { - if (Auth().supportMode() + if (session().supportMode() || !Data::draftsAreEqual(localDraft, history->cloudDraft())) { storedLocalDraft = Local::MessageDraft( localDraft->msgId, @@ -3754,7 +3866,7 @@ void MainWidget::checkIdleFinish() { void MainWidget::updateReceived(const mtpPrime *from, const mtpPrime *end) { if (end <= from) return; - Auth().checkAutoLock(); + session().checkAutoLock(); if (mtpTypeId(*from) == mtpc_new_session_created) { try { @@ -3782,111 +3894,6 @@ void MainWidget::updateReceived(const mtpPrime *from, const mtpPrime *end) { update(); } -namespace { - -bool fwdInfoDataLoaded(const MTPMessageFwdHeader &header) { - if (header.type() != mtpc_messageFwdHeader) { - return true; - } - auto &info = header.c_messageFwdHeader(); - if (info.has_channel_id()) { - if (!App::channelLoaded(peerFromChannel(info.vchannel_id))) { - return false; - } - if (info.has_from_id()) { - const auto from = App::user(peerFromUser(info.vfrom_id)); - if (from->loadedStatus == PeerData::NotLoaded) { - return false; - } - } - } else { - if (info.has_from_id() && !App::userLoaded(peerFromUser(info.vfrom_id))) { - return false; - } - } - return true; -} - -bool mentionUsersLoaded(const MTPVector &entities) { - for_const (auto &entity, entities.v) { - auto type = entity.type(); - if (type == mtpc_messageEntityMentionName) { - if (!App::userLoaded(peerFromUser(entity.c_messageEntityMentionName().vuser_id))) { - return false; - } - } else if (type == mtpc_inputMessageEntityMentionName) { - auto &inputUser = entity.c_inputMessageEntityMentionName().vuser_id; - if (inputUser.type() == mtpc_inputUser) { - if (!App::userLoaded(peerFromUser(inputUser.c_inputUser().vuser_id))) { - return false; - } - } - } - } - return true; -} - -enum class DataIsLoadedResult { - NotLoaded = 0, - FromNotLoaded = 1, - MentionNotLoaded = 2, - Ok = 3, -}; -DataIsLoadedResult allDataLoadedForMessage(const MTPMessage &message) { - return message.match([](const MTPDmessage &message) { - if (!message.is_post() && message.has_from_id()) { - if (!App::userLoaded(peerFromUser(message.vfrom_id))) { - return DataIsLoadedResult::FromNotLoaded; - } - } - if (message.has_via_bot_id()) { - if (!App::userLoaded(peerFromUser(message.vvia_bot_id))) { - return DataIsLoadedResult::NotLoaded; - } - } - if (message.has_fwd_from() - && !fwdInfoDataLoaded(message.vfwd_from)) { - return DataIsLoadedResult::NotLoaded; - } - if (message.has_entities() - && !mentionUsersLoaded(message.ventities)) { - return DataIsLoadedResult::MentionNotLoaded; - } - return DataIsLoadedResult::Ok; - }, [](const MTPDmessageService &message) { - if (!message.is_post() && message.has_from_id()) { - if (!App::userLoaded(peerFromUser(message.vfrom_id))) { - return DataIsLoadedResult::FromNotLoaded; - } - } - return message.vaction.match( - [](const MTPDmessageActionChatAddUser &action) { - for (const MTPint &userId : action.vusers.v) { - if (!App::userLoaded(peerFromUser(userId))) { - return DataIsLoadedResult::NotLoaded; - } - } - return DataIsLoadedResult::Ok; - }, [](const MTPDmessageActionChatJoinedByLink &action) { - if (!App::userLoaded(peerFromUser(action.vinviter_id))) { - return DataIsLoadedResult::NotLoaded; - } - return DataIsLoadedResult::Ok; - }, [](const MTPDmessageActionChatDeleteUser &action) { - if (!App::userLoaded(peerFromUser(action.vuser_id))) { - return DataIsLoadedResult::NotLoaded; - } - return DataIsLoadedResult::Ok; - }, [](const auto &) { - return DataIsLoadedResult::Ok; - }); - }, [](const MTPDmessageEmpty &message) { - return DataIsLoadedResult::Ok; - }); -} - -} // namespace - void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { switch (updates.type()) { case mtpc_updates: { @@ -3902,8 +3909,8 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { } } - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + session().data().processUsers(d.vusers); + session().data().processChats(d.vchats); feedUpdateVector(d.vupdates); updSetState(0, d.vdate.v, updQts, d.vseq.v); @@ -3922,8 +3929,8 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { } } - App::feedUsers(d.vusers); - App::feedChats(d.vchats); + session().data().processUsers(d.vusers); + session().data().processChats(d.vchats); feedUpdateVector(d.vupdates); updSetState(0, d.vdate.v, updQts, d.vseq.v); @@ -3938,10 +3945,10 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { case mtpc_updateShortMessage: { auto &d = updates.c_updateShortMessage(); - if (!App::userLoaded(d.vuser_id.v) - || (d.has_via_bot_id() && !App::userLoaded(d.vvia_bot_id.v)) - || (d.has_entities() && !mentionUsersLoaded(d.ventities)) - || (d.has_fwd_from() && !fwdInfoDataLoaded(d.vfwd_from))) { + if (!session().data().userLoaded(d.vuser_id.v) + || (d.has_via_bot_id() && !session().data().userLoaded(d.vvia_bot_id.v)) + || (d.has_entities() && !MentionUsersLoaded(&session(), d.ventities)) + || (d.has_fwd_from() && !ForwardedInfoDataLoaded(&session(), d.vfwd_from))) { MTP_LOG(0, ("getDifference { good - getting user for updateShortMessage }%1").arg(cTestMode() ? " TESTMODE" : "")); return getDifference(); } @@ -3953,16 +3960,16 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { case mtpc_updateShortChatMessage: { auto &d = updates.c_updateShortChatMessage(); - bool noFrom = !App::userLoaded(d.vfrom_id.v); - const auto chat = App::chatLoaded(d.vchat_id.v); + const auto noFrom = !session().data().userLoaded(d.vfrom_id.v); + const auto chat = session().data().chatLoaded(d.vchat_id.v); if (!chat || noFrom - || (d.has_via_bot_id() && !App::userLoaded(d.vvia_bot_id.v)) - || (d.has_entities() && !mentionUsersLoaded(d.ventities)) - || (d.has_fwd_from() && !fwdInfoDataLoaded(d.vfwd_from))) { + || (d.has_via_bot_id() && !session().data().userLoaded(d.vvia_bot_id.v)) + || (d.has_entities() && !MentionUsersLoaded(&session(), d.ventities)) + || (d.has_fwd_from() && !ForwardedInfoDataLoaded(&session(), d.vfwd_from))) { MTP_LOG(0, ("getDifference { good - getting user for updateShortChatMessage }%1").arg(cTestMode() ? " TESTMODE" : "")); if (chat && noFrom) { - Auth().api().requestFullPeer(chat); + session().api().requestFullPeer(chat); } return getDifference(); } @@ -3986,8 +3993,8 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { feedUpdate(MTP_updateMessageID(d.vid, MTP_long(randomId))); // ignore real date if (peerId) { if (auto item = App::histItemById(peerToChannel(peerId), d.vid.v)) { - if (d.has_entities() && !mentionUsersLoaded(d.ventities)) { - Auth().api().requestMessageData( + if (d.has_entities() && !MentionUsersLoaded(&session(), d.ventities)) { + session().api().requestMessageData( item->history()->peer->asChannel(), item->id, ApiWrap::RequestMessageDataCallback()); @@ -4016,7 +4023,7 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { return getDifference(); } break; } - Auth().data().sendHistoryChangeNotifications(); + session().data().sendHistoryChangeNotifications(); } void MainWidget::feedUpdate(const MTPUpdate &update) { @@ -4026,7 +4033,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateNewMessage: { auto &d = update.c_updateNewMessage(); - DataIsLoadedResult isDataLoaded = allDataLoadedForMessage(d.vmessage); + const auto isDataLoaded = AllDataLoadedForMessage(&session(), d.vmessage); if (!requestingDifference() && isDataLoaded != DataIsLoadedResult::Ok) { MTP_LOG(0, ("getDifference { good - " "after not all data loaded in updateNewMessage }%1" @@ -4042,8 +4049,8 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateNewChannelMessage: { auto &d = update.c_updateNewChannelMessage(); - auto channel = App::channelLoaded(peerToChannel(PeerFromMessage(d.vmessage))); - auto isDataLoaded = allDataLoadedForMessage(d.vmessage); + auto channel = session().data().channelLoaded(peerToChannel(PeerFromMessage(d.vmessage))); + const auto isDataLoaded = AllDataLoadedForMessage(&session(), d.vmessage); if (!requestingDifference() && (!channel || isDataLoaded != DataIsLoadedResult::Ok)) { MTP_LOG(0, ("getDifference { good - " "after not all data loaded in updateNewChannelMessage }%1" @@ -4053,7 +4060,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { // This will optimize similar getDifference() calls for almost all next messages. if (isDataLoaded == DataIsLoadedResult::FromNotLoaded && channel && channel->isMegagroup()) { if (channel->mgInfo->lastParticipants.size() < Global::ChatSizeMax() && (channel->mgInfo->lastParticipants.empty() || channel->mgInfo->lastParticipants.size() < channel->membersCount())) { - Auth().api().requestLastParticipants(channel); + session().api().requestLastParticipants(channel); } } @@ -4068,7 +4075,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } channel->ptsUpdateAndApply(d.vpts.v, d.vpts_count.v, update); } else { - Auth().api().applyUpdateNoPtsCheck(update); + session().api().applyUpdateNoPtsCheck(update); } } break; @@ -4103,7 +4110,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateChannelReadMessagesContents: { auto &d = update.c_updateChannelReadMessagesContents(); - auto channel = App::channelLoaded(d.vchannel_id.v); + auto channel = session().data().channelLoaded(d.vchannel_id.v); if (!channel) { if (!_byMinChannelTimer.isActive()) { // getDifference after timeout. @@ -4116,14 +4123,14 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { if (auto item = App::histItemById(channel, msgId.v)) { if (item->isUnreadMedia() || item->isUnreadMention()) { item->markMediaRead(); - Auth().data().requestItemRepaint(item); + session().data().requestItemRepaint(item); } } else { // Perhaps it was an unread mention! possiblyReadMentions.insert(msgId.v); } } - Auth().api().checkForUnreadMentions(possiblyReadMentions, channel); + session().api().checkForUnreadMentions(possiblyReadMentions, channel); } break; // Edited messages. @@ -4134,7 +4141,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateEditChannelMessage: { auto &d = update.c_updateEditChannelMessage(); - auto channel = App::channelLoaded(peerToChannel(PeerFromMessage(d.vmessage))); + auto channel = session().data().channelLoaded(peerToChannel(PeerFromMessage(d.vmessage))); if (channel && !_handlingChannelDifference) { if (channel->ptsRequesting()) { // skip global updates while getting channel difference @@ -4143,7 +4150,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { channel->ptsUpdateAndApply(d.vpts.v, d.vpts_count.v, update); } } else { - Auth().api().applyUpdateNoPtsCheck(update); + session().api().applyUpdateNoPtsCheck(update); } } break; @@ -4180,7 +4187,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { //case mtpc_updateReadFeed: { // #feed // const auto &d = update.c_updateReadFeed(); // const auto feedId = d.vfeed_id.v; - // if (const auto feed = Auth().data().feedLoaded(feedId)) { + // if (const auto feed = session().data().feedLoaded(feedId)) { // feed->setUnreadPosition( // Data::FeedPositionFromMTP(d.vmax_position)); // if (d.has_unread_count() && d.has_unread_muted_count()) { @@ -4188,7 +4195,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { // d.vunread_count.v, // d.vunread_muted_count.v); // } else { - // Auth().api().requestDialogEntry(feed); + // session().api().requestDialogEntry(feed); // } // } //} break; @@ -4198,7 +4205,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { const auto history = data.vpeer.match( [&](const MTPDdialogPeer &data) { const auto peerId = peerFromMTP(data.vpeer); - return App::historyLoaded(peerId); + return session().data().historyLoaded(peerId); //}, [&](const MTPDdialogPeerFeed &data) { // #feed }); if (history) { @@ -4215,7 +4222,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateDeleteChannelMessages: { auto &d = update.c_updateDeleteChannelMessages(); - auto channel = App::channelLoaded(d.vchannel_id.v); + auto channel = session().data().channelLoaded(d.vchannel_id.v); if (channel && !_handlingChannelDifference) { if (channel->ptsRequesting()) { // skip global updates while getting channel difference @@ -4223,7 +4230,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } channel->ptsUpdateAndApply(d.vpts.v, d.vpts_count.v, update); } else { - Auth().api().applyUpdateNoPtsCheck(update); + session().api().applyUpdateNoPtsCheck(update); } } break; @@ -4231,9 +4238,9 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { auto &d = update.c_updateWebPage(); // Update web page anyway. - Auth().data().webpage(d.vwebpage); + session().data().processWebpage(d.vwebpage); _history->updatePreview(); - Auth().data().sendWebPageGamePollNotifications(); + session().data().sendWebPageGamePollNotifications(); ptsUpdateAndApply(d.vpts.v, d.vpts_count.v, update); } break; @@ -4242,11 +4249,11 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { auto &d = update.c_updateChannelWebPage(); // Update web page anyway. - Auth().data().webpage(d.vwebpage); + session().data().processWebpage(d.vwebpage); _history->updatePreview(); - Auth().data().sendWebPageGamePollNotifications(); + session().data().sendWebPageGamePollNotifications(); - auto channel = App::channelLoaded(d.vchannel_id.v); + auto channel = session().data().channelLoaded(d.vchannel_id.v); if (channel && !_handlingChannelDifference) { if (channel->ptsRequesting()) { // skip global updates while getting channel difference return; @@ -4254,67 +4261,67 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { channel->ptsUpdateAndApply(d.vpts.v, d.vpts_count.v, update); } } else { - Auth().api().applyUpdateNoPtsCheck(update); + session().api().applyUpdateNoPtsCheck(update); } } break; case mtpc_updateMessagePoll: { - Auth().data().applyUpdate(update.c_updateMessagePoll()); + session().data().applyUpdate(update.c_updateMessagePoll()); } break; case mtpc_updateUserTyping: { auto &d = update.c_updateUserTyping(); const auto userId = peerFromUser(d.vuser_id); - const auto history = App::historyLoaded(userId); - const auto user = App::userLoaded(d.vuser_id.v); + const auto history = session().data().historyLoaded(userId); + const auto user = session().data().userLoaded(d.vuser_id.v); if (history && user) { const auto when = requestingDifference() ? 0 : unixtime(); - Auth().data().registerSendAction(history, user, d.vaction, when); + session().data().registerSendAction(history, user, d.vaction, when); } } break; case mtpc_updateChatUserTyping: { auto &d = update.c_updateChatUserTyping(); const auto history = [&]() -> History* { - if (auto chat = App::chatLoaded(d.vchat_id.v)) { - return App::historyLoaded(chat->id); - } else if (auto channel = App::channelLoaded(d.vchat_id.v)) { - return App::historyLoaded(channel->id); + if (const auto chat = session().data().chatLoaded(d.vchat_id.v)) { + return session().data().historyLoaded(chat->id); + } else if (const auto channel = session().data().channelLoaded(d.vchat_id.v)) { + return session().data().historyLoaded(channel->id); } return nullptr; }(); - const auto user = (d.vuser_id.v == Auth().userId()) + const auto user = (d.vuser_id.v == session().userId()) ? nullptr - : App::userLoaded(d.vuser_id.v); + : session().data().userLoaded(d.vuser_id.v); if (history && user) { const auto when = requestingDifference() ? 0 : unixtime(); - Auth().data().registerSendAction(history, user, d.vaction, when); + session().data().registerSendAction(history, user, d.vaction, when); } } break; case mtpc_updateChatParticipants: { - Auth().data().applyUpdate(update.c_updateChatParticipants()); + session().data().applyUpdate(update.c_updateChatParticipants()); } break; case mtpc_updateChatParticipantAdd: { - Auth().data().applyUpdate(update.c_updateChatParticipantAdd()); + session().data().applyUpdate(update.c_updateChatParticipantAdd()); } break; case mtpc_updateChatParticipantDelete: { - Auth().data().applyUpdate(update.c_updateChatParticipantDelete()); + session().data().applyUpdate(update.c_updateChatParticipantDelete()); } break; case mtpc_updateChatParticipantAdmin: { - Auth().data().applyUpdate(update.c_updateChatParticipantAdmin()); + session().data().applyUpdate(update.c_updateChatParticipantAdmin()); } break; case mtpc_updateChatDefaultBannedRights: { - Auth().data().applyUpdate(update.c_updateChatDefaultBannedRights()); + session().data().applyUpdate(update.c_updateChatDefaultBannedRights()); } break; case mtpc_updateUserStatus: { auto &d = update.c_updateUserStatus(); - if (auto user = App::userLoaded(d.vuser_id.v)) { + if (auto user = session().data().userLoaded(d.vuser_id.v)) { switch (d.vstatus.type()) { case mtpc_userStatusEmpty: user->onlineTill = 0; break; case mtpc_userStatusRecently: @@ -4331,7 +4338,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { user, Notify::PeerUpdate::Flag::UserOnlineChanged); } - if (d.vuser_id.v == Auth().userId()) { + if (d.vuser_id.v == session().userId()) { if (d.vstatus.type() == mtpc_userStatusOffline || d.vstatus.type() == mtpc_userStatusEmpty) { updateOnline(true); if (d.vstatus.type() == mtpc_userStatusOffline) { @@ -4345,7 +4352,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateUserName: { auto &d = update.c_updateUserName(); - if (auto user = App::userLoaded(d.vuser_id.v)) { + if (auto user = session().data().userLoaded(d.vuser_id.v)) { if (user->contactStatus() != UserData::ContactStatus::Contact) { user->setName( TextUtilities::SingleLine(qs(d.vfirst_name)), @@ -4364,15 +4371,15 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateUserPhoto: { auto &d = update.c_updateUserPhoto(); - if (auto user = App::userLoaded(d.vuser_id.v)) { + if (auto user = session().data().userLoaded(d.vuser_id.v)) { user->setPhoto(d.vphoto); user->loadUserpic(); if (mtpIsTrue(d.vprevious) || !user->userpicPhotoId()) { - Auth().storage().remove(Storage::UserPhotosRemoveAfter( + session().storage().remove(Storage::UserPhotosRemoveAfter( user->bareId(), user->userpicPhotoId())); } else { - Auth().storage().add(Storage::UserPhotosAddNew( + session().storage().add(Storage::UserPhotosAddNew( user->bareId(), user->userpicPhotoId())); } @@ -4386,7 +4393,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateNotifySettings: { auto &d = update.c_updateNotifySettings(); - Auth().data().applyNotifySetting(d.vpeer, d.vnotify_settings); + session().data().applyNotifySetting(d.vpeer, d.vnotify_settings); } break; case mtpc_updateDcOptions: { @@ -4400,7 +4407,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateUserPhone: { auto &d = update.c_updateUserPhone(); - if (auto user = App::userLoaded(d.vuser_id.v)) { + if (auto user = session().data().userLoaded(d.vuser_id.v)) { auto newPhone = qs(d.vphone); if (newPhone != user->phone()) { user->setPhone(newPhone); @@ -4444,7 +4451,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateUserBlocked: { auto &d = update.c_updateUserBlocked(); - if (auto user = App::userLoaded(d.vuser_id.v)) { + if (auto user = session().data().userLoaded(d.vuser_id.v)) { user->setBlockStatus(mtpIsTrue(d.vblocked) ? UserData::BlockStatus::Blocked : UserData::BlockStatus::NotBlocked); } } break; @@ -4460,14 +4467,14 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } else if (d.is_popup()) { Ui::show(Box(text)); } else { - Auth().data().serviceNotification(text, d.vmedia); - Auth().data().checkNewAuthorization(); + session().data().serviceNotification(text, d.vmedia); + session().data().checkNewAuthorization(); } } break; case mtpc_updatePrivacy: { auto &d = update.c_updatePrivacy(); - Auth().api().handlePrivacyChange(d.vkey.type(), d.vrules); + session().api().handlePrivacyChange(d.vkey.type(), d.vrules); } break; case mtpc_updatePinnedDialogs: { @@ -4480,7 +4487,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_dialogPeer: { const auto &peer = dialogPeer.c_dialogPeer(); const auto peerId = peerFromMTP(peer.vpeer); - if (!App::historyLoaded(peerId)) { + if (!session().data().historyLoaded(peerId)) { DEBUG_LOG(("API Error: " "pinned chat not loaded for peer %1" ).arg(peerId @@ -4491,7 +4498,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { //case mtpc_dialogPeerFeed: { // #feed // const auto &feed = dialogPeer.c_dialogPeerFeed(); // const auto feedId = feed.vfeed_id.v; - // if (!Auth().data().feedLoaded(feedId)) { + // if (!session().data().feedLoaded(feedId)) { // DEBUG_LOG(("API Error: " // "pinned feed not loaded for feedId %1" // ).arg(feedId @@ -4504,7 +4511,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { return true; }(); if (allLoaded) { - Auth().data().applyPinnedDialogs(order); + session().data().applyPinnedDialogs(order); } else { _dialogs->loadPinnedDialogs(); } @@ -4518,8 +4525,8 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { switch (d.vpeer.type()) { case mtpc_dialogPeer: { const auto peerId = peerFromMTP(d.vpeer.c_dialogPeer().vpeer); - if (const auto history = App::historyLoaded(peerId)) { - Auth().data().setPinnedDialog(history, d.is_pinned()); + if (const auto history = session().data().historyLoaded(peerId)) { + session().data().setPinnedDialog(history, d.is_pinned()); } else { DEBUG_LOG(("API Error: " "pinned chat not loaded for peer %1" @@ -4530,8 +4537,8 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } break; //case mtpc_dialogPeerFeed: { // #feed // const auto feedId = d.vpeer.c_dialogPeerFeed().vfeed_id.v; - // if (const auto feed = Auth().data().feedLoaded(feedId)) { - // Auth().data().setPinnedDialog(feed, d.is_pinned()); + // if (const auto feed = session().data().feedLoaded(feedId)) { + // session().data().setPinnedDialog(feed, d.is_pinned()); // } else { // DEBUG_LOG(("API Error: " // "pinned feed not loaded for feedId %1" @@ -4545,10 +4552,10 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateChannel: { auto &d = update.c_updateChannel(); - if (const auto channel = App::channelLoaded(d.vchannel_id.v)) { + if (const auto channel = session().data().channelLoaded(d.vchannel_id.v)) { channel->inviter = UserId(0); if (channel->amIn()) { - const auto history = App::history(channel); + const auto history = channel->owner().history(channel); if (const auto feed = channel->feed()) { feed->requestChatListMessage(); if (!feed->unreadCountKnown()) { @@ -4561,7 +4568,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } } if (!channel->amCreator()) { - Auth().api().requestSelfParticipant(channel); + session().api().requestSelfParticipant(channel); } } } @@ -4569,7 +4576,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateChannelTooLong: { auto &d = update.c_updateChannelTooLong(); - if (auto channel = App::channelLoaded(d.vchannel_id.v)) { + if (auto channel = session().data().channelLoaded(d.vchannel_id.v)) { if (!d.has_pts() || channel->pts() < d.vpts.v) { getChannelDifference(channel); } @@ -4585,9 +4592,9 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateChannelAvailableMessages: { auto &d = update.c_updateChannelAvailableMessages(); - if (const auto channel = App::channelLoaded(d.vchannel_id.v)) { + if (const auto channel = session().data().channelLoaded(d.vchannel_id.v)) { channel->setAvailableMinId(d.vavailable_min_id.v); - if (const auto history = App::historyLoaded(channel)) { + if (const auto history = session().data().historyLoaded(channel)) { history->clearUpTill(d.vavailable_min_id.v); } } @@ -4596,21 +4603,21 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { // Pinned message. case mtpc_updateUserPinnedMessage: { const auto &d = update.c_updateUserPinnedMessage(); - if (const auto user = App::userLoaded(d.vuser_id.v)) { + if (const auto user = session().data().userLoaded(d.vuser_id.v)) { user->setPinnedMessageId(d.vid.v); } } break; case mtpc_updateChatPinnedMessage: { const auto &d = update.c_updateChatPinnedMessage(); - if (const auto chat = App::chatLoaded(d.vchat_id.v)) { + if (const auto chat = session().data().chatLoaded(d.vchat_id.v)) { chat->setPinnedMessageId(d.vid.v); } } break; case mtpc_updateChannelPinnedMessage: { const auto &d = update.c_updateChannelPinnedMessage(); - if (const auto channel = App::channelLoaded(d.vchannel_id.v)) { + if (const auto channel = session().data().channelLoaded(d.vchannel_id.v)) { channel->setPinnedMessageId(d.vid.v); } } break; @@ -4628,7 +4635,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { "updateNewStickerSet without install_date flag.")); } if (!s.is_masks()) { - auto &sets = Auth().data().stickerSetsRef(); + auto &sets = session().data().stickerSetsRef(); auto it = sets.find(s.vid.v); if (it == sets.cend()) { it = sets.insert(s.vid.v, Stickers::Set( @@ -4655,7 +4662,8 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { it->stickers.clear(); it->stickers.reserve(v.size()); for (const auto &item : v) { - const auto document = Auth().data().document(item); + const auto document = session().data().processDocument( + item); if (!document->sticker()) continue; it->stickers.push_back(document); @@ -4675,7 +4683,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { Stickers::Pack p; p.reserve(stickers.size()); for (auto j = 0, c = stickers.size(); j != c; ++j) { - auto doc = Auth().data().document(stickers[j].v); + auto doc = session().data().document(stickers[j].v); if (!doc->sticker()) continue; p.push_back(doc); @@ -4684,7 +4692,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } } - auto &order = Auth().data().stickerSetsOrderRef(); + auto &order = session().data().stickerSetsOrderRef(); int32 insertAtIndex = 0, currentIndex = order.indexOf(s.vid.v); if (currentIndex != insertAtIndex) { if (currentIndex > 0) { @@ -4705,7 +4713,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } Local::writeInstalledStickers(); if (writeArchived) Local::writeArchivedStickers(); - Auth().data().notifyStickersUpdated(); + session().data().notifyStickersUpdated(); } } } @@ -4715,7 +4723,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { auto &d = update.c_updateStickerSetsOrder(); if (!d.is_masks()) { auto &order = d.vorder.v; - auto &sets = Auth().data().stickerSets(); + auto &sets = session().data().stickerSets(); Stickers::Order result; for (const auto &item : order) { if (sets.constFind(item.v) == sets.cend()) { @@ -4723,44 +4731,44 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { } result.push_back(item.v); } - if (result.size() != Auth().data().stickerSetsOrder().size() || result.size() != order.size()) { - Auth().data().setLastStickersUpdate(0); - Auth().api().updateStickers(); + if (result.size() != session().data().stickerSetsOrder().size() || result.size() != order.size()) { + session().data().setLastStickersUpdate(0); + session().api().updateStickers(); } else { - Auth().data().stickerSetsOrderRef() = std::move(result); + session().data().stickerSetsOrderRef() = std::move(result); Local::writeInstalledStickers(); - Auth().data().notifyStickersUpdated(); + session().data().notifyStickersUpdated(); } } } break; case mtpc_updateStickerSets: { - Auth().data().setLastStickersUpdate(0); - Auth().api().updateStickers(); + session().data().setLastStickersUpdate(0); + session().api().updateStickers(); } break; case mtpc_updateRecentStickers: { - Auth().data().setLastRecentStickersUpdate(0); - Auth().api().updateStickers(); + session().data().setLastRecentStickersUpdate(0); + session().api().updateStickers(); } break; case mtpc_updateFavedStickers: { - Auth().data().setLastFavedStickersUpdate(0); - Auth().api().updateStickers(); + session().data().setLastFavedStickersUpdate(0); + session().api().updateStickers(); } break; case mtpc_updateReadFeaturedStickers: { // We read some of the featured stickers, perhaps not all of them. // Here we don't know what featured sticker sets were read, so we // request all of them once again. - Auth().data().setLastFeaturedStickersUpdate(0); - Auth().api().updateStickers(); + session().data().setLastFeaturedStickersUpdate(0); + session().api().updateStickers(); } break; ////// Cloud saved GIFs case mtpc_updateSavedGifs: { - Auth().data().setLastSavedGifsUpdate(0); - Auth().api().updateStickers(); + session().data().setLastSavedGifsUpdate(0); + session().api().updateStickers(); } break; ////// Cloud drafts diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 5a67724a9..1b381cc21 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/player/media_player_float.h" #include "data/data_pts_waiter.h" +class AuthSession; struct HistoryMessageMarkupButton; class MainWindow; class ConfirmBox; @@ -97,6 +98,8 @@ public: MainWidget(QWidget *parent, not_null controller); + AuthSession &session() const; + bool isMainSectionShown() const; bool isThirdSectionShown() const; diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index f33e161f8..64c465f37 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -2647,7 +2647,7 @@ void MediaView::setContext(base::optional_variant< } else if (auto peer = base::get_if>(&context)) { _msgid = FullMsgId(); _canForwardItem = _canDeleteItem = false; - _history = App::history(*peer); + _history = (*peer)->owner().history(*peer); _peer = *peer; } else { _msgid = FullMsgId(); @@ -2658,10 +2658,10 @@ void MediaView::setContext(base::optional_variant< _migrated = nullptr; if (_history) { if (_history->peer->migrateFrom()) { - _migrated = App::history(_history->peer->migrateFrom()->id); + _migrated = _history->owner().history(_history->peer->migrateFrom()); } else if (_history->peer->migrateTo()) { _migrated = _history; - _history = App::history(_history->peer->migrateTo()->id); + _history = _history->owner().history(_history->peer->migrateTo()); } } _user = _peer ? _peer->asUser() : nullptr; diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index 8df3166fe..27c684fd3 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -2491,7 +2491,7 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) { const auto &data = result.c_account_authorizationForm(); - App::feedUsers(data.vusers); + Auth().data().processUsers(data.vusers); for (const auto &value : data.vvalues.v) { auto parsed = parseValue(value); @@ -2525,7 +2525,7 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) { if (!ValidateForm(_form)) { return false; } - _bot = App::userLoaded(_request.botId); + _bot = Auth().data().userLoaded(_request.botId); _form.pendingErrors = data.verrors.v; return true; } diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 875583128..18552902b 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_button.h" #include "info/profile/info_profile_cover.h" #include "data/data_user.h" +#include "data/data_session.h" #include "lang/lang_keys.h" #include "storage/localstorage.h" #include "auth_session.h" @@ -224,8 +225,7 @@ void SetupHelp(not_null container) { st::settingsSectionButton); button->addClickHandler([=] { const auto ready = crl::guard(button, [](const MTPUser &data) { - const auto users = MTP_vector(1, data); - if (const auto user = App::feedUsers(users)) { + if (const auto user = Auth().data().processUser(data)) { Ui::showPeerHistory(user, ShowAtUnreadMsgId); } }); diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 37b4290a8..08963084d 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "auth_session.h" #include "storage/localstorage.h" #include "data/data_user.h" +#include "data/data_session.h" #include "history/history.h" #include "calls/calls_instance.h" #include "ui/widgets/checkbox.h" @@ -111,7 +112,10 @@ void BlockedBoxController::loadMoreRows() { return; } - _loadRequestId = request(MTPcontacts_GetBlocked(MTP_int(_offset), MTP_int(kBlockedPerPage))).done([this](const MTPcontacts_Blocked &result) { + _loadRequestId = request(MTPcontacts_GetBlocked( + MTP_int(_offset), + MTP_int(kBlockedPerPage) + )).done([=](const MTPcontacts_Blocked &result) { _loadRequestId = 0; if (!_offset) { @@ -119,7 +123,7 @@ void BlockedBoxController::loadMoreRows() { } auto handleContactsBlocked = [](auto &list) { - App::feedUsers(list.vusers); + Auth().data().processUsers(list.vusers); return list.vblocked.v; }; switch (result.type()) { @@ -162,7 +166,7 @@ void BlockedBoxController::receivedUsers(const QVector &resul } auto &contactBlocked = item.c_contactBlocked(); auto userId = contactBlocked.vuser_id.v; - if (auto user = App::userLoaded(userId)) { + if (auto user = Auth().data().userLoaded(userId)) { appendRow(user); user->setBlockStatus(UserData::BlockStatus::Blocked); } diff --git a/Telegram/SourceFiles/storage/file_upload.cpp b/Telegram/SourceFiles/storage/file_upload.cpp index c5e45b719..cf9196dcf 100644 --- a/Telegram/SourceFiles/storage/file_upload.cpp +++ b/Telegram/SourceFiles/storage/file_upload.cpp @@ -139,13 +139,16 @@ Uploader::Uploader() { connect(&stopSessionsTimer, SIGNAL(timeout()), this, SLOT(stopSessions())); } -void Uploader::uploadMedia(const FullMsgId &msgId, const SendMediaReady &media) { +void Uploader::uploadMedia( + const FullMsgId &msgId, + const SendMediaReady &media) { if (media.type == SendMediaType::Photo) { - Auth().data().photo(media.photo, media.photoThumbs); - } else if (media.type == SendMediaType::File || media.type == SendMediaType::Audio) { + Auth().data().processPhoto(media.photo, media.photoThumbs); + } else if (media.type == SendMediaType::File + || media.type == SendMediaType::Audio) { const auto document = media.photoThumbs.isEmpty() - ? Auth().data().document(media.document) - : Auth().data().document( + ? Auth().data().processDocument(media.document) + : Auth().data().processDocument( media.document, base::duplicate(media.photoThumbs.begin().value())); if (!media.data.isEmpty()) { @@ -171,15 +174,20 @@ void Uploader::upload( const FullMsgId &msgId, const std::shared_ptr &file) { if (file->type == SendMediaType::Photo) { - auto photo = Auth().data().photo(file->photo, file->photoThumbs); - photo->uploadingData = std::make_unique(file->partssize); - } else if (file->type == SendMediaType::File || file->type == SendMediaType::Audio) { - auto document = file->thumb.isNull() - ? Auth().data().document(file->document) - : Auth().data().document( + const auto photo = Auth().data().processPhoto( + file->photo, + file->photoThumbs); + photo->uploadingData = std::make_unique( + file->partssize); + } else if (file->type == SendMediaType::File + || file->type == SendMediaType::Audio) { + const auto document = file->thumb.isNull() + ? Auth().data().processDocument(file->document) + : Auth().data().processDocument( file->document, std::move(file->thumb)); - document->uploadingData = std::make_unique(document->size); + document->uploadingData = std::make_unique( + document->size); document->setGoodThumbnail( std::move(file->goodThumbnail), std::move(file->goodThumbnailBytes)); diff --git a/Telegram/SourceFiles/storage/serialize_common.cpp b/Telegram/SourceFiles/storage/serialize_common.cpp index 510b1c1eb..8d905e4fa 100644 --- a/Telegram/SourceFiles/storage/serialize_common.cpp +++ b/Telegram/SourceFiles/storage/serialize_common.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_user.h" +#include "data/data_session.h" #include "ui/image/image.h" namespace Serialize { @@ -154,10 +155,10 @@ PeerData *readPeer(int streamAppVersion, QDataStream &stream) { streamAppVersion, stream); - PeerData *result = App::peerLoaded(peerId); + PeerData *result = Auth().data().peerLoaded(peerId); bool wasLoaded = (result != nullptr); if (!wasLoaded) { - result = App::peer(peerId); + result = Auth().data().peer(peerId); result->loadedStatus = PeerData::FullLoaded; } if (const auto user = result->asUser()) { diff --git a/Telegram/SourceFiles/storage/storage_user_photos.h b/Telegram/SourceFiles/storage/storage_user_photos.h index 2585afe78..ffd648790 100644 --- a/Telegram/SourceFiles/storage/storage_user_photos.h +++ b/Telegram/SourceFiles/storage/storage_user_photos.h @@ -80,7 +80,7 @@ struct UserPhotosKey { return !(*this == other); } - PeerId userId = 0; + UserId userId = 0; PhotoId photoId = 0; }; diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index d0be9b0da..b5f051191 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_key.h" #include "data/data_drafts.h" #include "data/data_user.h" +#include "data/data_session.h" #include "history/history.h" #include "boxes/abstract_box.h" #include "ui/toast/toast.h" @@ -579,7 +580,7 @@ QString InterpretSendPath(const QString &path) { return "App Error: Invalid command: " + line; } } - const auto history = App::historyLoaded(toId); + const auto history = Auth().data().historyLoaded(toId); if (!history) { return "App Error: Could not find channel with id: " + QString::number(peerToChannel(toId)); } diff --git a/Telegram/SourceFiles/ui/text/text_entity.cpp b/Telegram/SourceFiles/ui/text/text_entity.cpp index 7f38bf94e..362175ff1 100644 --- a/Telegram/SourceFiles/ui/text/text_entity.cpp +++ b/Telegram/SourceFiles/ui/text/text_entity.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qthelp_url.h" #include "ui/emoji_config.h" #include "data/data_user.h" +#include "data/data_session.h" namespace TextUtilities { namespace { @@ -1472,7 +1473,7 @@ EntitiesInText EntitiesFromMTP(const QVector &entities) { case mtpc_messageEntityMentionName: { auto &d = entity.c_messageEntityMentionName(); auto data = [&d] { - if (auto user = App::userLoaded(peerFromUser(d.vuser_id))) { + if (auto user = Auth().data().userLoaded(d.vuser_id.v)) { return MentionNameDataFromFields({ d.vuser_id.v, user->accessHash() }); diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 4245eb16b..847c9a112 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -586,7 +586,7 @@ void MainWindow::launchDrag(std::unique_ptr data) { void MainWindow::checkAuthSession() { if (AuthSession::Exists()) { - _controller = std::make_unique(this); + _controller = std::make_unique(&Auth(), this); } else { _controller = nullptr; } diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index 93e13665e..a471aa0b8 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -396,7 +396,7 @@ Manager::DisplayOptions Manager::getNotificationOptions(HistoryItem *item) { void Manager::notificationActivated(PeerId peerId, MsgId msgId) { onBeforeNotificationActivated(peerId, msgId); if (auto window = App::wnd()) { - auto history = App::history(peerId); + auto history = Auth().data().history(peerId); window->showFromTray(); window->reActivateWindow(); if (Messenger::Instance().locked()) { @@ -447,7 +447,7 @@ void Manager::notificationReplied( const TextWithTags &reply) { if (!peerId) return; - const auto history = App::history(peerId); + const auto history = Auth().data().history(peerId); auto message = ApiWrap::MessageToSend(history); message.textWithTags = reply; diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index 34d56d00a..c77079962 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -50,10 +50,61 @@ void DateClickHandler::onClick(ClickContext context) const { App::wnd()->controller()->showJumpToDate(_chat, _date); } -Controller::Controller(not_null window) -: _window(window) { - Auth().data().animationPlayInlineRequest( - ) | rpl::start_with_next([this](auto item) { +Navigation::Navigation(not_null session) : _session(session) { +} + +AuthSession &Navigation::session() const { + return *_session; +} + +void Navigation::showPeerInfo( + PeerId peerId, + const SectionShow ¶ms) { + //if (Adaptive::ThreeColumn() + // && !_session->settings().thirdSectionInfoEnabled()) { + // _session->settings().setThirdSectionInfoEnabled(true); + // _session->saveSettingsDelayed(); + //} + showSection(Info::Memento(peerId), params); +} + +void Navigation::showPeerInfo( + not_null peer, + const SectionShow ¶ms) { + showPeerInfo(peer->id, params); +} + +void Navigation::showPeerInfo( + not_null history, + const SectionShow ¶ms) { + showPeerInfo(history->peer->id, params); +} + +void Navigation::showSettings( + Settings::Type type, + const SectionShow ¶ms) { + showSection( + Info::Memento( + Info::Settings::Tag{ _session->user() }, + Info::Section(type)), + params); +} + +void Navigation::showSettings(const SectionShow ¶ms) { + showSettings(Settings::Type::Main, params); +} + +Controller::Controller( + not_null session, + not_null window) +: Navigation(session) +, _window(window) { + init(); +} + +void Controller::init() { + session().data().animationPlayInlineRequest( + ) | rpl::start_with_next([=](auto item) { if (const auto video = roundVideo(item)) { video->pauseResume(); } else { @@ -61,13 +112,13 @@ Controller::Controller(not_null window) } }, lifetime()); - if (Auth().supportMode()) { + if (session().supportMode()) { initSupportMode(); } } void Controller::initSupportMode() { - Auth().supportHelper().registerWindow(this); + session().supportHelper().registerWindow(this); Shortcuts::Requests( ) | rpl::start_with_next([=](not_null request) { @@ -84,7 +135,7 @@ void Controller::initSupportMode() { void Controller::setActiveChatEntry(Dialogs::RowDescriptor row) { _activeChatEntry = row; - if (Auth().supportMode()) { + if (session().supportMode()) { pushToChatEntryHistory(row); } } @@ -229,8 +280,8 @@ Controller::ColumnLayout Controller::computeColumnLayout() const { if (bodyWidth < minimalThreeColumnWidth()) { return true; } - if (!Auth().settings().tabbedSelectorSectionEnabled() - && !Auth().settings().thirdSectionInfoEnabled()) { + if (!session().settings().tabbedSelectorSectionEnabled() + && !session().settings().thirdSectionInfoEnabled()) { return true; } return false; @@ -260,14 +311,14 @@ Controller::ColumnLayout Controller::computeColumnLayout() const { } int Controller::countDialogsWidthFromRatio(int bodyWidth) const { - auto result = qRound(bodyWidth * Auth().settings().dialogsWidthRatio()); + auto result = qRound(bodyWidth * session().settings().dialogsWidthRatio()); accumulate_max(result, st::columnMinimalWidthLeft); // accumulate_min(result, st::columnMaximalWidthLeft); return result; } int Controller::countThirdColumnWidthFromRatio(int bodyWidth) const { - auto result = Auth().settings().thirdColumnWidth(); + auto result = session().settings().thirdColumnWidth(); accumulate_max(result, st::columnMinimalWidthThird); accumulate_min(result, st::columnMaximalWidthThird); return result; @@ -320,11 +371,11 @@ void Controller::resizeForThirdSection() { auto layout = computeColumnLayout(); auto tabbedSelectorSectionEnabled = - Auth().settings().tabbedSelectorSectionEnabled(); + session().settings().tabbedSelectorSectionEnabled(); auto thirdSectionInfoEnabled = - Auth().settings().thirdSectionInfoEnabled(); - Auth().settings().setTabbedSelectorSectionEnabled(false); - Auth().settings().setThirdSectionInfoEnabled(false); + session().settings().thirdSectionInfoEnabled(); + session().settings().setTabbedSelectorSectionEnabled(false); + session().settings().setThirdSectionInfoEnabled(false); auto wanted = countThirdColumnWidthFromRatio(layout.bodyWidth); auto minimal = st::columnMinimalWidthThird; @@ -345,20 +396,20 @@ void Controller::resizeForThirdSection() { return window()->tryToExtendWidthBy(minimal); }(); if (extendedBy) { - if (extendBy != Auth().settings().thirdColumnWidth()) { - Auth().settings().setThirdColumnWidth(extendBy); + if (extendBy != session().settings().thirdColumnWidth()) { + session().settings().setThirdColumnWidth(extendBy); } auto newBodyWidth = layout.bodyWidth + extendedBy; - auto currentRatio = Auth().settings().dialogsWidthRatio(); - Auth().settings().setDialogsWidthRatio( + auto currentRatio = session().settings().dialogsWidthRatio(); + session().settings().setDialogsWidthRatio( (currentRatio * layout.bodyWidth) / newBodyWidth); } auto savedValue = (extendedBy == extendBy) ? -1 : extendedBy; - Auth().settings().setThirdSectionExtendedBy(savedValue); + session().settings().setThirdSectionExtendedBy(savedValue); - Auth().settings().setTabbedSelectorSectionEnabled( + session().settings().setTabbedSelectorSectionEnabled( tabbedSelectorSectionEnabled); - Auth().settings().setThirdSectionInfoEnabled( + session().settings().setThirdSectionInfoEnabled( thirdSectionInfoEnabled); } @@ -368,23 +419,23 @@ void Controller::closeThirdSection() { if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) { auto noResize = window()->isFullScreen() || window()->isMaximized(); - auto savedValue = Auth().settings().thirdSectionExtendedBy(); + auto savedValue = session().settings().thirdSectionExtendedBy(); auto extendedBy = (savedValue == -1) ? layout.thirdWidth : savedValue; auto newBodyWidth = noResize ? layout.bodyWidth : (layout.bodyWidth - extendedBy); - auto currentRatio = Auth().settings().dialogsWidthRatio(); - Auth().settings().setDialogsWidthRatio( + auto currentRatio = session().settings().dialogsWidthRatio(); + session().settings().setDialogsWidthRatio( (currentRatio * layout.bodyWidth) / newBodyWidth); newWindowSize = QSize( window()->width() + (newBodyWidth - layout.bodyWidth), window()->height()); } - Auth().settings().setTabbedSelectorSectionEnabled(false); - Auth().settings().setThirdSectionInfoEnabled(false); - Auth().saveSettingsDelayed(); + session().settings().setTabbedSelectorSectionEnabled(false); + session().settings().setThirdSectionInfoEnabled(false); + session().saveSettingsDelayed(); if (window()->size() != newWindowSize) { window()->resize(newWindowSize); } else { @@ -400,7 +451,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) { } else if (history->loadedAtTop() && !history->isEmpty() && history->peer->migrateFrom()) { - if (const auto migrated = App::historyLoaded(history->peer->migrateFrom())) { + if (const auto migrated = history->owner().historyLoaded(history->peer->migrateFrom())) { if (migrated->scrollTopItem) { // We're up in the migrated history. // So current date is the date of first message here. @@ -422,7 +473,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) { const auto maxPeerDate = [](Dialogs::Key chat) { if (auto history = chat.history()) { if (const auto channel = history->peer->migrateTo()) { - history = App::historyLoaded(channel); + history = channel->owner().historyLoaded(channel); } if (history && history->chatListTimeId() != 0) { return ParseDateTime(history->chatListTimeId()).date(); @@ -441,7 +492,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) { }; if (const auto history = chat.history()) { if (const auto chat = history->peer->migrateFrom()) { - if (const auto history = App::historyLoaded(chat)) { + if (const auto history = chat->owner().historyLoaded(chat)) { if (history->loadedAtTop()) { if (!history->isEmpty()) { return history->blocks.front()->messages.front()->dateTime().date(); @@ -467,7 +518,7 @@ void Controller::showJumpToDate(Dialogs::Key chat, QDate requestedDate) { : requestedDate; const auto month = highlighted; auto callback = [=](const QDate &date) { - Auth().api().jumpToDate(chat, date); + session().api().jumpToDate(chat, date); }; auto box = Box( month, @@ -523,43 +574,6 @@ void Controller::showPeerHistory( msgId); } -void Navigation::showPeerInfo( - PeerId peerId, - const SectionShow ¶ms) { - //if (Adaptive::ThreeColumn() - // && !Auth().settings().thirdSectionInfoEnabled()) { - // Auth().settings().setThirdSectionInfoEnabled(true); - // Auth().saveSettingsDelayed(); - //} - showSection(Info::Memento(peerId), params); -} - -void Navigation::showPeerInfo( - not_null peer, - const SectionShow ¶ms) { - showPeerInfo(peer->id, params); -} - -void Navigation::showPeerInfo( - not_null history, - const SectionShow ¶ms) { - showPeerInfo(history->peer->id, params); -} - -void Navigation::showSettings( - Settings::Type type, - const SectionShow ¶ms) { - showSection( - Info::Memento( - Info::Settings::Tag{ Auth().user() }, - Info::Section(type)), - params); -} - -void Navigation::showSettings(const SectionShow ¶ms) { - showSettings(Settings::Type::Main, params); -} - void Controller::showSection( SectionMemento &&memento, const SectionShow ¶ms) { diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index 754b797d0..8ad0bea45 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/flags.h" #include "dialogs/dialogs_key.h" +class AuthSession; class MainWidget; class HistoryMessage; class HistoryService; @@ -103,6 +104,10 @@ class Controller; class Navigation { public: + explicit Navigation(not_null session); + + AuthSession &session() const; + virtual void showSection( SectionMemento &&memento, const SectionShow ¶ms = SectionShow()) = 0; @@ -127,11 +132,16 @@ public: virtual ~Navigation() = default; +private: + const not_null _session; + }; class Controller : public Navigation { public: - Controller(not_null window); + Controller( + not_null session, + not_null window); not_null window() const { return _window; @@ -260,6 +270,7 @@ public: ~Controller(); private: + void init(); void initSupportMode(); int minimalThreeColumnWidth() const; @@ -278,7 +289,7 @@ private: void pushToChatEntryHistory(Dialogs::RowDescriptor row); bool chatEntryHistoryMove(int steps); - not_null _window; + const not_null _window; std::unique_ptr _passportForm; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 1e7d853c3..896deea1f 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -188,7 +188,7 @@ bool Filler::showInfo() { void Filler::addPinToggle() { auto peer = _peer; auto isPinned = false; - if (auto history = App::historyLoaded(peer)) { + if (auto history = peer->owner().historyLoaded(peer)) { isPinned = history->isPinnedDialog(); } auto pinText = [](bool isPinned) { @@ -197,7 +197,7 @@ void Filler::addPinToggle() { : lng_context_pin_to_top); }; auto pinToggle = [=] { - TogglePinnedDialog(App::history(peer)); + TogglePinnedDialog(peer->owner().history(peer)); }; auto pinAction = _addAction(pinText(isPinned), pinToggle); @@ -206,7 +206,7 @@ void Filler::addPinToggle() { peer, Notify::PeerUpdate::Flag::ChatPinnedChanged ) | rpl::start_with_next([peer, pinAction, pinText] { - auto isPinned = App::history(peer)->isPinnedDialog(); + auto isPinned = peer->owner().history(peer)->isPinnedDialog(); pinAction->setText(pinText(isPinned)); }, *lifetime); } @@ -226,14 +226,14 @@ void Filler::addInfo() { void Filler::addSearch() { _addAction(lang(lng_profile_search_messages), [peer = _peer] { - App::main()->searchInChat(App::history(peer)); + App::main()->searchInChat(peer->owner().history(peer)); }); } void Filler::addToggleUnreadMark() { const auto peer = _peer; const auto isUnread = [](not_null peer) { - if (const auto history = App::historyLoaded(peer)) { + if (const auto history = peer->owner().historyLoaded(peer)) { return (history->chatListUnreadCount() > 0) || (history->chatListUnreadMark()); } @@ -253,7 +253,7 @@ void Filler::addToggleUnreadMark() { Auth().api().changeDialogUnreadMark(history, !markAsRead); } }; - const auto history = App::history(peer); + const auto history = peer->owner().history(peer); handle(history); if (markAsRead) { if (const auto migrated = history->migrateSibling()) { @@ -447,7 +447,7 @@ void Filler::addChannelActions(not_null channel) { void Filler::fill() { if (_source == PeerMenuSource::ChatsList) { - if (const auto history = App::historyLoaded(_peer)) { + if (const auto history = _peer->owner().historyLoaded(_peer)) { if (!history->useProxyPromotion()) { addPinToggle(); } @@ -598,7 +598,7 @@ void PeerMenuShareContactBox(not_null user) { LayerOption::KeepOther); return; } else if (peer->isSelf()) { - auto options = ApiWrap::SendOptions(App::history(peer)); + auto options = ApiWrap::SendOptions(peer->owner().history(peer)); Auth().api().shareContact(user, options); Ui::Toast::Show(lang(lng_share_done)); if (auto strong = *weak) { @@ -613,7 +613,7 @@ void PeerMenuShareContactBox(not_null user) { lng_forward_share_contact(lt_recipient, recipient), lang(lng_forward_send), [peer, user] { - const auto history = App::history(peer); + const auto history = peer->owner().history(peer); Ui::showPeerHistory(history, ShowAtTheEndMsgId); auto options = ApiWrap::SendOptions(history); Auth().api().shareContact(user, options); @@ -636,7 +636,7 @@ void PeerMenuCreatePoll(not_null peer) { if (std::exchange(*lock, true)) { return; } - const auto options = ApiWrap::SendOptions(App::history(peer)); + const auto options = ApiWrap::SendOptions(peer->owner().history(peer)); Auth().api().createPoll(result, options, crl::guard(box, [=] { box->closeBox(); }), crl::guard(box, [=](const RPCError &error) { @@ -658,7 +658,7 @@ QPointer ShowForwardMessagesBox( if (peer->isSelf()) { auto items = Auth().data().idsToItems(ids); if (!items.empty()) { - auto options = ApiWrap::SendOptions(App::history(peer)); + auto options = ApiWrap::SendOptions(peer->owner().history(peer)); options.generateLocal = false; Auth().api().forwardMessages(std::move(items), options, [] { Ui::Toast::Show(lang(lng_share_done)); @@ -704,7 +704,7 @@ void PeerMenuAddChannelMembers(not_null channel) { return data.vuser_id.v; }); }) | ranges::view::transform([](UserId userId) { - return App::userLoaded(userId); + return Auth().data().userLoaded(userId); }) | ranges::view::filter([](UserData *user) { return (user != nullptr); }) | ranges::to_vector;