From 91d516f18c33ba3212e01788fac2ebbd8ef008fc Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 2 Jun 2016 16:57:49 +0300 Subject: [PATCH] Notify::peerUpdatedSendDelayed() now is always called from the event loop. --- Telegram/SourceFiles/apiwrap.cpp | 22 +--- Telegram/SourceFiles/app.cpp | 34 ++---- Telegram/SourceFiles/app.h | 6 +- Telegram/SourceFiles/application.cpp | 1 - Telegram/SourceFiles/boxes/addcontactbox.cpp | 3 - Telegram/SourceFiles/boxes/contactsbox.cpp | 2 +- Telegram/SourceFiles/dialogswidget.cpp | 2 - Telegram/SourceFiles/historywidget.cpp | 12 -- Telegram/SourceFiles/localstorage.cpp | 7 +- Telegram/SourceFiles/mainwidget.cpp | 120 ++++++++----------- Telegram/SourceFiles/structs.cpp | 15 --- Telegram/SourceFiles/structs.h | 11 -- 12 files changed, 73 insertions(+), 162 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 7baab31b1..7d7ac9b5b 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -183,8 +183,8 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt badVersion = (!vc.isEmpty() && vc.at(0).type() == mtpc_channel && vc.at(0).c_channel().vversion.v < peer->asChannel()->version); } - App::feedUsersDelayed(d.vusers); - App::feedChatsDelayed(d.vchats); + App::feedUsers(d.vusers); + App::feedChats(d.vchats); if (peer->isChat()) { if (d.vfull_chat.type() != mtpc_chatFull) { @@ -322,17 +322,15 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt } App::clearPeerUpdated(peer); emit fullPeerUpdated(peer); - - Notify::peerUpdatedSendDelayed(); } void ApiWrap::gotUserFull(PeerData *peer, const MTPUserFull &result, mtpRequestId req) { const auto &d(result.c_userFull()); - App::feedUsersDelayed(MTP_vector(1, d.vuser)); + App::feedUsers(MTP_vector(1, d.vuser)); if (d.has_profile_photo()) { App::feedPhoto(d.vprofile_photo); } - App::feedUserLinkDelayed(MTP_int(peerToUser(peer->id)), d.vlink.c_contacts_link().vmy_link, d.vlink.c_contacts_link().vforeign_link); + App::feedUserLink(MTP_int(peerToUser(peer->id)), d.vlink.c_contacts_link().vmy_link, d.vlink.c_contacts_link().vforeign_link); if (App::main()) { notifySettingReceived(MTP_inputNotifyPeer(peer->input), d.vnotify_settings); } @@ -353,8 +351,6 @@ void ApiWrap::gotUserFull(PeerData *peer, const MTPUserFull &result, mtpRequestI } App::clearPeerUpdated(peer); emit fullPeerUpdated(peer); - - Notify::peerUpdatedSendDelayed(); } bool ApiWrap::gotPeerFullFailed(PeerData *peer, const RPCError &error) { @@ -558,7 +554,6 @@ void ApiWrap::lastParticipantsDone(ChannelData *peer, const MTPchannels_ChannelP } peer->mgInfo->botStatus = botStatus; if (App::main()) emit fullPeerUpdated(peer); - Notify::peerUpdatedSendDelayed(); } bool ApiWrap::lastParticipantsFail(ChannelData *peer, const RPCError &error, mtpRequestId req) { @@ -663,7 +658,6 @@ void ApiWrap::kickParticipantDone(KickRequest kick, const MTPUpdates &result, mt } } emit fullPeerUpdated(kick.first); - Notify::peerUpdatedSendDelayed(); } bool ApiWrap::kickParticipantFail(KickRequest kick, const RPCError &error, mtpRequestId req) { @@ -708,7 +702,6 @@ void ApiWrap::leaveChannel(ChannelData *channel) { void ApiWrap::channelAmInUpdated(ChannelData *channel) { Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::ChannelAmIn); - Notify::peerUpdatedSendDelayed(); } void ApiWrap::channelAmInDone(ChannelData *channel, const MTPUpdates &updates) { @@ -727,7 +720,6 @@ bool ApiWrap::channelAmInFail(ChannelData *channel, const RPCError &error) { void ApiWrap::blockUser(UserData *user) { if (user->isBlocked()) { Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserIsBlocked); - Notify::peerUpdatedSendDelayed(); } else if (!_blockRequests.contains(user)) { auto requestId = MTP::send(MTPcontacts_Block(user->inputUser), rpcDone(&ApiWrap::blockDone, user), rpcFail(&ApiWrap::blockFail, user)); _blockRequests.insert(user, requestId); @@ -737,7 +729,6 @@ void ApiWrap::blockUser(UserData *user) { void ApiWrap::unblockUser(UserData *user) { if (!user->isBlocked()) { Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserIsBlocked); - Notify::peerUpdatedSendDelayed(); } else if (!_blockRequests.contains(user)) { auto requestId = MTP::send(MTPcontacts_Unblock(user->inputUser), rpcDone(&ApiWrap::unblockDone, user), rpcFail(&ApiWrap::blockFail, user)); _blockRequests.insert(user, requestId); @@ -748,14 +739,12 @@ void ApiWrap::blockDone(UserData *user, const MTPBool &result) { _blockRequests.remove(user); user->setBlockStatus(UserData::BlockStatus::Blocked); emit App::main()->peerUpdated(user); - Notify::peerUpdatedSendDelayed(); } void ApiWrap::unblockDone(UserData *user, const MTPBool &result) { _blockRequests.remove(user); user->setBlockStatus(UserData::BlockStatus::NotBlocked); emit App::main()->peerUpdated(user); - Notify::peerUpdatedSendDelayed(); } bool ApiWrap::blockFail(UserData *user, const RPCError &error) { @@ -788,7 +777,6 @@ void ApiWrap::exportInviteDone(PeerData *peer, const MTPExportedChatInvite &resu } else if (auto channel = peer->asChannel()) { channel->setInviteLink((result.type() == mtpc_chatInviteExported) ? qs(result.c_chatInviteExported().vlink) : QString()); } - Notify::peerUpdatedSendDelayed(); } bool ApiWrap::exportInviteFail(PeerData *peer, const RPCError &error) { @@ -809,7 +797,6 @@ void ApiWrap::requestNotifySetting(PeerData *peer) { void ApiWrap::notifySettingDone(MTPInputNotifyPeer notifyPeer, const MTPPeerNotifySettings &result) { if (auto requestedPeer = notifySettingReceived(notifyPeer, result)) { _notifySettingRequests.remove(requestedPeer); - Notify::peerUpdatedSendDelayed(); } } @@ -842,7 +829,6 @@ bool ApiWrap::notifySettingFail(PeerData *peer, const RPCError &error) { notifySettingReceived(MTP_inputNotifyPeer(peer->input), MTP_peerNotifySettingsEmpty()); _notifySettingRequests.remove(peer); - Notify::peerUpdatedSendDelayed(); return true; } diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 3b449d87c..b159f8e54 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -365,7 +365,7 @@ namespace { return (online > now); } - UserData *feedUsersDelayed(const MTPVector &users) { + UserData *feedUsers(const MTPVector &users) { UserData *result = nullptr; for_const (auto &user, users.c_vector().v) { UserData *data = nullptr; @@ -386,7 +386,7 @@ namespace { data->input = MTP_inputPeerUser(d.vid, MTP_long(0)); data->inputUser = MTP_inputUser(d.vid, MTP_long(0)); - data->setNameDelayed(lang(lng_deleted), QString(), QString(), QString()); + data->setName(lang(lng_deleted), QString(), QString(), QString()); data->setPhoto(MTP_userProfilePhotoEmpty()); data->access = UserNoAccess; data->flags = 0; @@ -432,7 +432,7 @@ namespace { data->setPhone(QString()); update.flags |= UpdateFlag::UserPhoneChanged; } - data->setNameDelayed(lang(lng_deleted), QString(), QString(), QString()); + data->setName(lang(lng_deleted), QString(), QString(), QString()); data->setPhoto(MTP_userProfilePhotoEmpty()); data->access = UserNoAccess; status = &emptyStatus; @@ -467,7 +467,7 @@ namespace { if (!minimal && d.is_self() && uname != data->username) { SignalHandlers::setCrashAnnotation("Username", uname); } - data->setNameDelayed(fname, lname, pname, uname); + data->setName(fname, lname, pname, uname); if (d.has_photo()) { data->setPhoto(d.vphoto); } else { @@ -547,7 +547,7 @@ namespace { return result; } - PeerData *feedChatsDelayed(const MTPVector &chats) { + PeerData *feedChats(const MTPVector &chats) { PeerData *result = nullptr; for_const (auto &chat, chats.c_vector().v) { PeerData *data = nullptr; @@ -565,7 +565,7 @@ namespace { auto canEdit = cdata->canEdit(); data->input = MTP_inputPeerChat(d.vid); - cdata->setNameDelayed(qs(d.vtitle)); + cdata->setName(qs(d.vtitle)); cdata->setPhoto(d.vphoto); cdata->date = d.vdate.v; @@ -627,7 +627,7 @@ namespace { auto canEdit = cdata->canEdit(); data->input = MTP_inputPeerChat(d.vid); - cdata->setNameDelayed(qs(d.vtitle)); + cdata->setName(qs(d.vtitle)); cdata->setPhoto(MTP_chatPhotoEmpty()); cdata->date = 0; cdata->count = -1; @@ -679,7 +679,7 @@ namespace { } } QString uname = d.has_username() ? textOneLine(qs(d.vusername)) : QString(); - cdata->setNameDelayed(qs(d.vtitle), uname); + cdata->setName(qs(d.vtitle), uname); cdata->isForbidden = false; cdata->flagsUpdated(); @@ -709,7 +709,7 @@ namespace { cdata->inputChannel = MTP_inputChannel(d.vid, d.vaccess_hash); - cdata->setNameDelayed(qs(d.vtitle), QString()); + cdata->setName(qs(d.vtitle), QString()); cdata->access = d.vaccess_hash.v; cdata->setPhoto(MTP_chatPhotoEmpty()); @@ -746,18 +746,6 @@ namespace { return result; } - UserData *feedUsers(const MTPVector &users) { - auto result = feedUsersDelayed(users); - Notify::peerUpdatedSendDelayed(); - return result; - } - - PeerData *feedChats(const MTPVector &chats) { - auto result = feedChatsDelayed(chats); - Notify::peerUpdatedSendDelayed(); - return result; - } - void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos, bool emitPeerUpdated) { ChatData *chat = 0; switch (p.type()) { @@ -1234,7 +1222,7 @@ namespace { } } - void feedUserLinkDelayed(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink) { + void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink) { UserData *user = userLoaded(userId.v); if (user) { auto wasContact = user->isContact(); @@ -1271,7 +1259,7 @@ namespace { bool showPhone = !isServiceUser(user->id) && !user->isSelf() && !user->contact; bool showPhoneChanged = !isServiceUser(user->id) && !user->isSelf() && ((showPhone && !wasShowPhone) || (!showPhone && wasShowPhone)); if (showPhoneChanged) { - user->setNameDelayed(textOneLine(user->firstName), textOneLine(user->lastName), showPhone ? App::formatPhone(user->phone()) : QString(), textOneLine(user->username)); + user->setName(textOneLine(user->firstName), textOneLine(user->lastName), showPhone ? App::formatPhone(user->phone()) : QString(), textOneLine(user->username)); } markPeerUpdated(user); } diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index c4428e309..f0150dbde 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -67,10 +67,6 @@ namespace App { UserData *feedUsers(const MTPVector &users); // returns last user PeerData *feedChats(const MTPVector &chats); // returns last chat - // Requires Notify::peerUpdatedSendDelayed() call after. - UserData *feedUsersDelayed(const MTPVector &users); // returns last user - PeerData *feedChatsDelayed(const MTPVector &chats); // returns last chat - void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos, bool emitPeerUpdated = true); void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d, bool emitPeerUpdated = true); void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d, bool emitPeerUpdated = true); @@ -85,7 +81,7 @@ namespace App { void feedInboxRead(const PeerId &peer, MsgId upTo); void feedOutboxRead(const PeerId &peer, MsgId upTo); void feedWereDeleted(ChannelId channelId, const QVector &msgsIds); - void feedUserLinkDelayed(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink); + void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink); void markPeerUpdated(PeerData *data); void clearPeerUpdated(PeerData *data); diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 17b9174e7..b001e8a9f 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -819,7 +819,6 @@ void AppClass::doMtpUnpause() { void AppClass::selfPhotoCleared(const MTPUserProfilePhoto &result) { if (!App::self()) return; App::self()->setPhoto(result); - Notify::peerUpdatedSendDelayed(); emit peerPhotoDone(App::self()->id); } diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index 81afd5c95..109707f01 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -545,7 +545,6 @@ void GroupInfoBox::exportDone(const MTPExportedChatInvite &result) { _creationRequestId = 0; if (result.type() == mtpc_chatInviteExported) { _createdChannel->setInviteLink(qs(result.c_chatInviteExported().vlink)); - Notify::peerUpdatedSendDelayed(); } Ui::showLayer(new SetupChannelBox(_createdChannel)); } @@ -1357,7 +1356,6 @@ bool EditChannelBox::onSaveFail(const RPCError &error, mtpRequestId req) { if (App::api()) { emit App::api()->fullPeerUpdated(_channel); } - Notify::peerUpdatedSendDelayed(); } saveSign(); return true; @@ -1388,7 +1386,6 @@ void EditChannelBox::onSaveDescriptionDone(const MTPBool &result) { if (App::api()) { emit App::api()->fullPeerUpdated(_channel); } - Notify::peerUpdatedSendDelayed(); } saveSign(); } diff --git a/Telegram/SourceFiles/boxes/contactsbox.cpp b/Telegram/SourceFiles/boxes/contactsbox.cpp index 389d3e055..aea2517ec 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.cpp +++ b/Telegram/SourceFiles/boxes/contactsbox.cpp @@ -2124,7 +2124,7 @@ void MembersInner::membersReceived(const MTPchannels_ChannelParticipants &result _channel->setAdminsCount(d.vcount.v); if (App::main()) emit App::main()->peerUpdated(_channel); } - App::feedUsersDelayed(d.vusers); + App::feedUsers(d.vusers); for (QVector::const_iterator i = v.cbegin(), e = v.cend(); i != e; ++i) { int32 userId = 0, addedTime = 0; diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index 0ac5a7052..a39dcc0a7 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -31,7 +31,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "boxes/addcontactbox.h" #include "boxes/contactsbox.h" #include "boxes/confirmbox.h" -#include "observer_peer.h" #include "localstorage.h" #include "apiwrap.h" @@ -728,7 +727,6 @@ void DialogsInner::onContextToggleBlock() { void DialogsInner::contextBlockDone(QPair data, const MTPBool &result) { data.first->setBlockStatus(data.second ? UserData::BlockStatus::Blocked : UserData::BlockStatus::NotBlocked); emit App::main()->peerUpdated(data.first); - Notify::peerUpdatedSendDelayed(); } void DialogsInner::onMenuDestroyed(QObject *obj) { diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index d403c497b..82bef9576 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -4967,7 +4967,6 @@ void HistoryWidget::unblockDone(PeerData *peer, const MTPBool &result, mtpReques if (_unblockRequest == req) _unblockRequest = 0; peer->asUser()->setBlockStatus(UserData::BlockStatus::NotBlocked); emit App::main()->peerUpdated(peer); - Notify::peerUpdatedSendDelayed(); } bool HistoryWidget::unblockFail(const RPCError &error, mtpRequestId req) { @@ -4982,7 +4981,6 @@ void HistoryWidget::blockDone(PeerData *peer, const MTPBool &result) { peer->asUser()->setBlockStatus(UserData::BlockStatus::Blocked); emit App::main()->peerUpdated(peer); - Notify::peerUpdatedSendDelayed(); } void HistoryWidget::onBotStart() { @@ -5096,8 +5094,6 @@ void HistoryWidget::shareContact(const PeerId &peer, const QString &phone, const App::main()->finishForwarding(h, _broadcast.checked(), _silent.checked()); cancelReply(lastKeyboardUsed); - - Notify::peerUpdatedSendDelayed(); } void HistoryWidget::onSendPaths(const PeerId &peer) { @@ -6290,8 +6286,6 @@ void HistoryWidget::confirmSendFile(const FileLoadResultPtr &file, bool ctrlShif } App::main()->dialogsToUp(); peerMessagesUpdated(file->to.peer); - - Notify::peerUpdatedSendDelayed(); } void HistoryWidget::cancelSendFile(const FileLoadResultPtr &file) { @@ -6926,7 +6920,6 @@ void HistoryWidget::addMessagesToFront(PeerData *peer, const QVector } updateBotKeyboard(); } - Notify::peerUpdatedSendDelayed(); } void HistoryWidget::addMessagesToBack(PeerData *peer, const QVector &messages, const QVector *collapsed) { @@ -6934,7 +6927,6 @@ void HistoryWidget::addMessagesToBack(PeerData *peer, const QVector if (!_firstLoadRequest) { updateListSize(false, true, { ScrollChangeNoJumpToBottom, 0 }); } - Notify::peerUpdatedSendDelayed(); } void HistoryWidget::countHistoryShowFrom() { @@ -7182,8 +7174,6 @@ void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot App::main()->finishForwarding(_history, _broadcast.checked(), _silent.checked()); cancelReply(lastKeyboardUsed); - Notify::peerUpdatedSendDelayed(); - App::historyRegRandom(randomId, newId); clearFieldText(); @@ -7971,7 +7961,6 @@ void HistoryWidget::onDeleteSelectedSure() { for (SelectedItemSet::const_iterator i = sel.cbegin(), e = sel.cend(); i != e; ++i) { i.value()->destroy(); } - Notify::peerUpdatedSendDelayed(); for (QMap >::const_iterator i = ids.cbegin(), e = ids.cend(); i != e; ++i) { App::main()->deleteMessages(i.key(), i.value()); @@ -7990,7 +7979,6 @@ void HistoryWidget::onDeleteContextSure() { History *h = item->history(); bool wasOnServer = (item->id > 0), wasLast = (h->lastMsg == item); item->destroy(); - Notify::peerUpdatedSendDelayed(); if (!wasOnServer && wasLast && !h->lastMsg) { App::main()->checkPeerHistory(h->peer); diff --git a/Telegram/SourceFiles/localstorage.cpp b/Telegram/SourceFiles/localstorage.cpp index 02e3c4607..48026481e 100644 --- a/Telegram/SourceFiles/localstorage.cpp +++ b/Telegram/SourceFiles/localstorage.cpp @@ -3491,7 +3491,7 @@ namespace Local { if (!wasLoaded) { user->setPhone(phone); - user->setNameDelayed(first, last, pname, username); + user->setName(first, last, pname, username); user->access = access; user->flags = MTPDuser::Flags(flags); @@ -3526,7 +3526,7 @@ namespace Local { flags = (flagsData == 1) ? MTPDchat::Flags(MTPDchat::Flag::f_left) : MTPDchat::Flags(0); } if (!wasLoaded) { - chat->setNameDelayed(name); + chat->setName(name); chat->count = count; chat->date = date; chat->version = version; @@ -3549,7 +3549,7 @@ namespace Local { from.stream >> name >> access >> date >> version >> forbidden >> flags >> inviteLink; if (!wasLoaded) { - channel->setNameDelayed(name, QString()); + channel->setName(name, QString()); channel->access = access; channel->date = date; channel->version = version; @@ -3746,7 +3746,6 @@ namespace Local { peers.push_back(peer); } - Notify::peerUpdatedSendDelayed(); if (App::api()) App::api()->requestPeers(peers); } diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index d85b401df..325484da5 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -697,12 +697,10 @@ void MainWidget::deleteHistoryPart(PeerData *peer, const MTPmessages_AffectedHis if (peer && peer->isChannel()) { if (peer->asChannel()->ptsUpdated(d.vpts.v, d.vpts_count.v)) { peer->asChannel()->ptsApplySkippedUpdates(); - Notify::peerUpdatedSendDelayed(); } } else { if (ptsUpdated(d.vpts.v, d.vpts_count.v)) { ptsApplySkippedUpdates(); - Notify::peerUpdatedSendDelayed(); } } @@ -727,9 +725,8 @@ void MainWidget::deleteMessages(PeerData *peer, const QVector &ids) { void MainWidget::deletedContact(UserData *user, const MTPcontacts_Link &result) { auto &d(result.c_contacts_link()); - App::feedUsersDelayed(MTP_vector(1, d.vuser)); - App::feedUserLinkDelayed(MTP_int(peerToUser(user->id)), d.vmy_link, d.vforeign_link); - Notify::peerUpdatedSendDelayed(); + App::feedUsers(MTP_vector(1, d.vuser)); + App::feedUserLink(MTP_int(peerToUser(user->id)), d.vmy_link, d.vforeign_link); } void MainWidget::removeDialog(History *history) { @@ -764,7 +761,6 @@ void MainWidget::deleteConversation(PeerData *peer, bool deleteHistory) { if (deleteHistory) { MTP::send(MTPmessages_DeleteHistory(peer->input, MTP_int(0)), rpcDone(&MainWidget::deleteHistoryPart, peer)); } - Notify::peerUpdatedSendDelayed(); } void MainWidget::deleteAndExit(ChatData *chat) { @@ -789,7 +785,6 @@ void MainWidget::deleteAllFromUser(ChannelData *channel, UserData *from) { item->destroy(); } } - Notify::peerUpdatedSendDelayed(); } MTP::send(MTPchannels_DeleteUserHistory(channel->inputChannel, from->inputUser), rpcDone(&MainWidget::deleteAllFromUserPart, { channel, from })); } @@ -798,7 +793,6 @@ void MainWidget::deleteAllFromUserPart(DeleteAllFromUserParams params, const MTP const auto &d(result.c_messages_affectedHistory()); if (params.channel->ptsUpdated(d.vpts.v, d.vpts_count.v)) { params.channel->ptsApplySkippedUpdates(); - Notify::peerUpdatedSendDelayed(); } int32 offset = d.voffset.v; @@ -822,7 +816,6 @@ void MainWidget::clearHistory(PeerData *peer) { } Ui::showPeerHistory(peer->id, ShowAtUnreadMsgId); MTP::send(MTPmessages_DeleteHistory(peer->input, MTP_int(0)), rpcDone(&MainWidget::deleteHistoryPart, peer)); - Notify::peerUpdatedSendDelayed(); } void MainWidget::addParticipants(PeerData *chatOrChannel, const QVector &users) { @@ -979,7 +972,6 @@ void MainWidget::checkedHistory(PeerData *peer, const MTPmessages_Messages &resu } } } - Notify::peerUpdatedSendDelayed(); } bool MainWidget::sendMessageFail(const RPCError &error) { @@ -1285,7 +1277,6 @@ void MainWidget::overviewPreloaded(PeerData *peer, const MTPmessages_Messages &r App::history(peer->id)->overviewSliceDone(type, result, true); if (App::wnd()) App::wnd()->mediaOverviewUpdated(peer, type); - Notify::peerUpdatedSendDelayed(); } void MainWidget::mediaOverviewUpdated(PeerData *peer, MediaOverviewType type) { @@ -1423,7 +1414,6 @@ void MainWidget::overviewLoaded(History *history, const MTPmessages_Messages &re history->overviewSliceDone(type, result); if (App::wnd()) App::wnd()->mediaOverviewUpdated(history->peer, type); - Notify::peerUpdatedSendDelayed(); } void MainWidget::sendReadRequest(PeerData *peer, MsgId upTo) { @@ -1465,12 +1455,10 @@ void MainWidget::messagesAffected(PeerData *peer, const MTPmessages_AffectedMess if (peer && peer->isChannel()) { if (peer->asChannel()->ptsUpdated(d.vpts.v, d.vpts_count.v)) { peer->asChannel()->ptsApplySkippedUpdates(); - Notify::peerUpdatedSendDelayed(); } } else { if (ptsUpdated(d.vpts.v, d.vpts_count.v)) { ptsApplySkippedUpdates(); - Notify::peerUpdatedSendDelayed(); } } if (History *h = App::historyLoaded(peer ? peer->id : 0)) { @@ -2425,7 +2413,6 @@ void MainWidget::windowShown() { void MainWidget::sentUpdatesReceived(uint64 randomId, const MTPUpdates &result) { feedUpdates(result, randomId); - Notify::peerUpdatedSendDelayed(); } bool MainWidget::deleteChannelFailed(const RPCError &error) { @@ -2873,8 +2860,8 @@ void MainWidget::gotChannelDifference(ChannelData *channel, const MTPupdates_Cha case mtpc_updates_channelDifference: { const auto &d(diff.c_updates_channelDifference()); - App::feedUsersDelayed(d.vusers); - App::feedChatsDelayed(d.vchats); + App::feedUsers(d.vusers); + App::feedChats(d.vchats); _handlingChannelDifference = true; feedMessageIds(d.vother_updates); @@ -2943,8 +2930,6 @@ void MainWidget::gotChannelDifference(ChannelData *channel, const MTPupdates_Cha } else if (activePeer() == channel) { channel->ptsWaitingForShortPoll(timeout ? (timeout * 1000) : WaitForChannelGetDifference); } - - Notify::peerUpdatedSendDelayed(); } void MainWidget::gotRangeDifference(ChannelData *channel, const MTPupdates_ChannelDifference &diff) { @@ -2960,8 +2945,8 @@ void MainWidget::gotRangeDifference(ChannelData *channel, const MTPupdates_Chann case mtpc_updates_channelDifferenceTooLong: { const auto &d(diff.c_updates_channelDifferenceTooLong()); - App::feedUsersDelayed(d.vusers); - App::feedChatsDelayed(d.vchats); + App::feedUsers(d.vusers); + App::feedChats(d.vchats); nextRequestPts = d.vpts.v; isFinal = d.is_final(); @@ -2970,8 +2955,8 @@ void MainWidget::gotRangeDifference(ChannelData *channel, const MTPupdates_Chann case mtpc_updates_channelDifference: { const auto &d(diff.c_updates_channelDifference()); - App::feedUsersDelayed(d.vusers); - App::feedChatsDelayed(d.vchats); + App::feedUsers(d.vusers); + App::feedChats(d.vchats); _handlingChannelDifference = true; feedMessageIds(d.vother_updates); @@ -2990,8 +2975,6 @@ void MainWidget::gotRangeDifference(ChannelData *channel, const MTPupdates_Chann h->asChannelHistory()->getRangeDifferenceNext(nextRequestPts); } } - - Notify::peerUpdatedSendDelayed(); } bool MainWidget::failChannelDifference(ChannelData *channel, const RPCError &error) { @@ -3012,8 +2995,6 @@ void MainWidget::gotState(const MTPupdates_State &state) { _dialogs->loadDialogs(); updateOnline(); - - Notify::peerUpdatedSendDelayed(); } void MainWidget::gotDifference(const MTPupdates_Difference &diff) { @@ -3048,7 +3029,6 @@ void MainWidget::gotDifference(const MTPupdates_Difference &diff) { gotState(d.vstate); } break; }; - Notify::peerUpdatedSendDelayed(); } bool MainWidget::getDifferenceTimeChanged(ChannelData *channel, int32 ms, ChannelGetDifferenceTime &channelCurTime, uint64 &curTime) { @@ -3138,8 +3118,8 @@ void MainWidget::ptsApplySkippedUpdates() { void MainWidget::feedDifference(const MTPVector &users, const MTPVector &chats, const MTPVector &msgs, const MTPVector &other) { App::wnd()->checkAutoLock(); - App::feedUsersDelayed(users); - App::feedChatsDelayed(chats); + App::feedUsers(users); + App::feedChats(chats); feedMessageIds(other); App::feedMsgs(msgs, NewMessageUnread); feedUpdateVector(other, true); @@ -3541,6 +3521,7 @@ void MainWidget::startFull(const MTPVector &users) { void MainWidget::applyNotifySetting(const MTPNotifyPeer &peer, const MTPPeerNotifySettings &settings, History *h) { PeerData *updatePeer = nullptr; + bool changed = false; switch (settings.type()) { case mtpc_peerNotifySettingsEmpty: switch (peer.type()) { @@ -3548,15 +3529,17 @@ void MainWidget::applyNotifySetting(const MTPNotifyPeer &peer, const MTPPeerNoti case mtpc_notifyUsers: globalNotifyUsersPtr = EmptyNotifySettings; break; case mtpc_notifyChats: globalNotifyChatsPtr = EmptyNotifySettings; break; case mtpc_notifyPeer: { - updatePeer = App::peerLoaded(peerFromMTP(peer.c_notifyPeer().vpeer)); - if (updatePeer && updatePeer->notify != EmptyNotifySettings) { - if (updatePeer->notify != UnknownNotifySettings) { - delete updatePeer->notify; + if ((updatePeer = App::peerLoaded(peerFromMTP(peer.c_notifyPeer().vpeer)))) { + changed = (updatePeer->notify != EmptyNotifySettings); + if (changed) { + if (updatePeer->notify != UnknownNotifySettings) { + delete updatePeer->notify; + } + updatePeer->notify = EmptyNotifySettings; + App::unregMuted(updatePeer); + if (!h) h = App::history(updatePeer->id); + h->setMute(false); } - updatePeer->notify = EmptyNotifySettings; - App::unregMuted(updatePeer); - if (!h) h = App::history(updatePeer->id); - h->setMute(false); } } break; } @@ -3569,29 +3552,32 @@ void MainWidget::applyNotifySetting(const MTPNotifyPeer &peer, const MTPPeerNoti case mtpc_notifyUsers: setTo = globalNotifyUsersPtr = &globalNotifyUsers; break; case mtpc_notifyChats: setTo = globalNotifyChatsPtr = &globalNotifyChats; break; case mtpc_notifyPeer: { - updatePeer = App::peerLoaded(peerFromMTP(peer.c_notifyPeer().vpeer)); - if (!updatePeer) break; - - if (updatePeer->notify == UnknownNotifySettings || updatePeer->notify == EmptyNotifySettings) { - updatePeer->notify = new NotifySettings(); + if ((updatePeer = App::peerLoaded(peerFromMTP(peer.c_notifyPeer().vpeer)))) { + if (updatePeer->notify == UnknownNotifySettings || updatePeer->notify == EmptyNotifySettings) { + changed = true; + updatePeer->notify = new NotifySettings(); + } + setTo = updatePeer->notify; } - setTo = updatePeer->notify; } break; } if (setTo == UnknownNotifySettings) break; - setTo->flags = d.vflags.v; - setTo->mute = d.vmute_until.v; - setTo->sound = d.vsound.c_string().v; - if (updatePeer) { - if (!h) h = App::history(updatePeer->id); - int32 changeIn = 0; - if (isNotifyMuted(setTo, &changeIn)) { - App::wnd()->notifyClear(h); - h->setMute(true); - App::regMuted(updatePeer, changeIn); - } else { - h->setMute(false); + changed = (setTo->flags != d.vflags.v) || (setTo->mute != d.vmute_until.v) || (setTo->sound != d.vsound.c_string().v); + if (changed) { + setTo->flags = d.vflags.v; + setTo->mute = d.vmute_until.v; + setTo->sound = d.vsound.c_string().v; + if (updatePeer) { + if (!h) h = App::history(updatePeer->id); + int32 changeIn = 0; + if (isNotifyMuted(setTo, &changeIn)) { + App::wnd()->notifyClear(h); + h->setMute(true); + App::regMuted(updatePeer, changeIn); + } else { + h->setMute(false); + } } } } break; @@ -3602,8 +3588,9 @@ void MainWidget::applyNotifySetting(const MTPNotifyPeer &peer, const MTPPeerNoti _history->updateNotifySettings(); } _dialogs->updateNotifySettings(updatePeer); - - Notify::peerUpdatedDelayed(updatePeer, Notify::PeerUpdate::Flag::NotificationsEnabled); + if (changed) { + Notify::peerUpdatedDelayed(updatePeer, Notify::PeerUpdate::Flag::NotificationsEnabled); + } } } @@ -3845,7 +3832,6 @@ void MainWidget::updateReceived(const mtpPrime *from, const mtpPrime *end) { if (!_ptsWaiter.requesting()) { feedUpdates(updates); } - Notify::peerUpdatedSendDelayed(); } catch (mtpErrorUnexpected &) { // just some other type } } @@ -3965,8 +3951,8 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { } } - App::feedUsersDelayed(d.vusers); - App::feedChatsDelayed(d.vchats); + App::feedUsers(d.vusers); + App::feedChats(d.vchats); feedUpdateVector(d.vupdates); updSetState(0, d.vdate.v, updQts, d.vseq.v); @@ -3982,8 +3968,8 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { } } - App::feedUsersDelayed(d.vusers); - App::feedChatsDelayed(d.vchats); + App::feedUsers(d.vusers); + App::feedChats(d.vchats); feedUpdateVector(d.vupdates); updSetState(0, d.vdate.v, updQts, d.vseq.v); @@ -4311,9 +4297,9 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { auto &d(update.c_updateUserName()); if (auto user = App::userLoaded(d.vuser_id.v)) { if (user->contact <= 0) { - user->setNameDelayed(textOneLine(qs(d.vfirst_name)), textOneLine(qs(d.vlast_name)), user->nameOrPhone, textOneLine(qs(d.vusername))); + user->setName(textOneLine(qs(d.vfirst_name)), textOneLine(qs(d.vlast_name)), user->nameOrPhone, textOneLine(qs(d.vusername))); } else { - user->setNameDelayed(textOneLine(user->firstName), textOneLine(user->lastName), user->nameOrPhone, textOneLine(qs(d.vusername))); + user->setName(textOneLine(user->firstName), textOneLine(user->lastName), user->nameOrPhone, textOneLine(qs(d.vusername))); } App::markPeerUpdated(user); } @@ -4354,7 +4340,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { case mtpc_updateContactLink: { const auto &d(update.c_updateContactLink()); - App::feedUserLinkDelayed(d.vuser_id, d.vmy_link, d.vforeign_link); + App::feedUserLink(d.vuser_id, d.vmy_link, d.vforeign_link); } break; case mtpc_updateNotifySettings: { @@ -4373,7 +4359,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { auto newPhone = qs(d.vphone); if (newPhone != user->phone()) { user->setPhone(newPhone); - user->setNameDelayed(user->firstName, user->lastName, (user->contact || isServiceUser(user->id) || user->isSelf() || user->phone().isEmpty()) ? QString() : App::formatPhone(user->phone()), user->username); + user->setName(user->firstName, user->lastName, (user->contact || isServiceUser(user->id) || user->isSelf() || user->phone().isEmpty()) ? QString() : App::formatPhone(user->phone()), user->username); App::markPeerUpdated(user); Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserPhoneChanged); diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index 30d1bfc03..3494471a4 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -271,11 +271,6 @@ bool UserData::setAbout(const QString &newAbout) { } void UserData::setName(const QString &newFirstName, const QString &newLastName, const QString &newPhoneName, const QString &newUsername) { - setNameDelayed(newFirstName, newLastName, newPhoneName, newUsername); - Notify::peerUpdatedSendDelayed(); -} - -void UserData::setNameDelayed(const QString &newFirstName, const QString &newLastName, const QString &newPhoneName, const QString &newUsername) { bool changeName = !newFirstName.isEmpty() || !newLastName.isEmpty(); QString newFullName; @@ -431,11 +426,6 @@ void ChatData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see Loc } void ChatData::setName(const QString &newName) { - setNameDelayed(newName); - Notify::peerUpdatedSendDelayed(); -} - -void ChatData::setNameDelayed(const QString &newName) { updateNameDelayed(newName.isEmpty() ? name : newName, QString(), QString()); } @@ -479,11 +469,6 @@ void ChannelData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see } void ChannelData::setName(const QString &newName, const QString &newUsername) { - setNameDelayed(newName, newUsername); - Notify::peerUpdatedSendDelayed(); -} - -void ChannelData::setNameDelayed(const QString &newName, const QString &newUsername) { updateNameDelayed(newName.isEmpty() ? name : newName, QString(), newUsername); } diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index c631972db..3cf2906d8 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -337,7 +337,6 @@ public: } protected: - // Requires Notify::peerUpdatedSendDelayed() call after. void updateNameDelayed(const QString &newName, const QString &newNameOrPhone, const QString &newUsername); ImagePtr _userpic; @@ -399,10 +398,6 @@ public: void setName(const QString &newFirstName, const QString &newLastName , const QString &newPhoneName, const QString &newUsername); - // Requires Notify::peerUpdatedSendDelayed() call after. - void setNameDelayed(const QString &newFirstName, const QString &newLastName - , const QString &newPhoneName, const QString &newUsername); - void setPhone(const QString &newPhone); void setBotInfoVersion(int version); void setBotInfo(const MTPBotInfo &info); @@ -499,9 +494,6 @@ public: void setName(const QString &newName); - // Requires Notify::peerUpdatedSendDelayed() call after. - void setNameDelayed(const QString &newName); - void invalidateParticipants() { participants = ChatData::Participants(); admins = ChatData::Admins(); @@ -679,9 +671,6 @@ public: void setName(const QString &name, const QString &username); - // Requires Notify::peerUpdatedSendDelayed() call after. - void setNameDelayed(const QString &name, const QString &username); - void updateFull(bool force = false); void fullUpdated();