Remove main()->peerUpdated and some other signals.

This commit is contained in:
John Preston 2017-08-11 12:42:52 +02:00
parent 8e433971c9
commit e13ed9b909
19 changed files with 161 additions and 247 deletions

View File

@ -283,7 +283,7 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
return;
}
auto &f = d.vfull_chat.c_chatFull();
App::feedParticipants(f.vparticipants, false, false);
App::feedParticipants(f.vparticipants, false);
auto &v = f.vbot_info.v;
for_const (auto &item, v) {
switch (item.type()) {
@ -291,7 +291,6 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
auto &b = item.c_botInfo();
if (auto user = App::userLoaded(b.vuser_id.v)) {
user->setBotInfo(item);
App::clearPeerUpdated(user);
fullPeerUpdated().notify(user);
}
} break;
@ -351,7 +350,6 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
}
if (updatedTo) {
Notify::migrateUpdated(cfrom);
App::main()->peerUpdated(cfrom);
}
}
auto &v = f.vbot_info.v;
@ -361,7 +359,6 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
auto &b = item.c_botInfo();
if (auto user = App::userLoaded(b.vuser_id.v)) {
user->setBotInfo(item);
App::clearPeerUpdated(user);
fullPeerUpdated().notify(user);
}
} break;
@ -423,7 +420,6 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
}
requestPeer(peer);
}
App::clearPeerUpdated(peer);
fullPeerUpdated().notify(peer);
}
@ -455,7 +451,6 @@ void ApiWrap::gotUserFull(UserData *user, const MTPUserFull &result, mtpRequestI
_fullPeerRequests.erase(i);
}
}
App::clearPeerUpdated(user);
fullPeerUpdated().notify(user);
}
@ -986,7 +981,6 @@ void ApiWrap::blockUser(UserData *user) {
auto requestId = request(MTPcontacts_Block(user->inputUser)).done([this, user](const MTPBool &result) {
_blockRequests.remove(user);
user->setBlockStatus(UserData::BlockStatus::Blocked);
emit App::main()->peerUpdated(user);
}).fail([this, user](const RPCError &error) {
_blockRequests.remove(user);
}).send();
@ -1002,7 +996,6 @@ void ApiWrap::unblockUser(UserData *user) {
auto requestId = request(MTPcontacts_Unblock(user->inputUser)).done([this, user](const MTPBool &result) {
_blockRequests.remove(user);
user->setBlockStatus(UserData::BlockStatus::NotBlocked);
emit App::main()->peerUpdated(user);
}).fail([this, user](const RPCError &error) {
_blockRequests.remove(user);
}).send();

View File

@ -61,9 +61,6 @@ namespace {
using MutedPeers = QMap<PeerData*, bool>;
MutedPeers mutedPeers;
using UpdatedPeers = QMap<PeerData*, bool>;
UpdatedPeers updatedPeers;
PhotosData photosData;
DocumentsData documentsData;
@ -535,8 +532,6 @@ namespace {
if ((data->contact > 0 && !wasContact) || (wasContact && data->contact < 1)) {
Notify::userIsContactChanged(data);
}
markPeerUpdated(data);
if (update.flags) {
update.peer = data;
Notify::peerUpdatedDelayed(update);
@ -760,12 +755,9 @@ namespace {
} else if (data->loadedStatus != PeerData::FullLoaded) {
data->loadedStatus = PeerData::FullLoaded;
}
if (App::main()) {
markPeerUpdated(data);
if (update.flags) {
update.peer = data;
Notify::peerUpdatedDelayed(update);
}
if (update.flags) {
update.peer = data;
Notify::peerUpdatedDelayed(update);
}
return data;
}
@ -780,7 +772,7 @@ namespace {
return result;
}
void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos, bool emitPeerUpdated) {
void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos) {
ChatData *chat = 0;
switch (p.type()) {
case mtpc_chatParticipantsForbidden: {
@ -872,28 +864,14 @@ namespace {
} break;
}
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged | Notify::PeerUpdate::Flag::AdminsChanged);
if (chat && App::main()) {
if (emitPeerUpdated) {
App::main()->peerUpdated(chat);
} else {
markPeerUpdated(chat);
}
}
}
void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d, bool emitPeerUpdated) {
void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d) {
ChatData *chat = App::chat(d.vchat_id.v);
if (chat->version + 1 < d.vversion.v) {
chat->version = d.vversion.v;
chat->invalidateParticipants();
Auth().api().requestPeer(chat);
if (App::main()) {
if (emitPeerUpdated) {
App::main()->peerUpdated(chat);
} else {
markPeerUpdated(chat);
}
}
} else if (chat->version <= d.vversion.v && chat->count >= 0) {
chat->version = d.vversion.v;
UserData *user = App::userLoaded(d.vuser_id.v);
@ -921,29 +899,15 @@ namespace {
chat->count++;
}
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged);
if (App::main()) {
if (emitPeerUpdated) {
App::main()->peerUpdated(chat);
} else {
markPeerUpdated(chat);
}
}
}
}
void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d, bool emitPeerUpdated) {
void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d) {
ChatData *chat = App::chat(d.vchat_id.v);
if (chat->version + 1 < d.vversion.v) {
chat->version = d.vversion.v;
chat->invalidateParticipants();
Auth().api().requestPeer(chat);
if (App::main()) {
if (emitPeerUpdated) {
App::main()->peerUpdated(chat);
} else {
markPeerUpdated(chat);
}
}
} else if (chat->version <= d.vversion.v && chat->count > 0) {
chat->version = d.vversion.v;
auto canEdit = chat->canEdit();
@ -991,17 +955,10 @@ namespace {
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::ChatCanEdit);
}
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::MembersChanged);
if (App::main()) {
if (emitPeerUpdated) {
App::main()->peerUpdated(chat);
} else {
markPeerUpdated(chat);
}
}
}
}
void feedChatAdmins(const MTPDupdateChatAdmins &d, bool emitPeerUpdated) {
void feedChatAdmins(const MTPDupdateChatAdmins &d) {
ChatData *chat = App::chat(d.vchat_id.v);
if (chat->version <= d.vversion.v) {
bool badVersion = (chat->version + 1 < d.vversion.v);
@ -1019,27 +976,15 @@ namespace {
chat->flags &= ~MTPDchat::Flag::f_admins_enabled;
}
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::AdminsChanged);
if (emitPeerUpdated) {
App::main()->peerUpdated(chat);
} else {
markPeerUpdated(chat);
}
}
}
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d, bool emitPeerUpdated) {
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d) {
ChatData *chat = App::chat(d.vchat_id.v);
if (chat->version + 1 < d.vversion.v) {
chat->version = d.vversion.v;
chat->invalidateParticipants();
Auth().api().requestPeer(chat);
if (App::main()) {
if (emitPeerUpdated) {
App::main()->peerUpdated(chat);
} else {
markPeerUpdated(chat);
}
}
} else if (chat->version <= d.vversion.v && chat->count > 0) {
chat->version = d.vversion.v;
auto canEdit = chat->canEdit();
@ -1067,13 +1012,6 @@ namespace {
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::ChatCanEdit);
}
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::AdminsChanged);
if (App::main()) {
if (emitPeerUpdated) {
App::main()->peerUpdated(chat);
} else {
markPeerUpdated(chat);
}
}
}
}
@ -1324,26 +1262,6 @@ namespace {
if (showPhoneChanged) {
user->setName(TextUtilities::SingleLine(user->firstName), TextUtilities::SingleLine(user->lastName), showPhone ? App::formatPhone(user->phone()) : QString(), TextUtilities::SingleLine(user->username));
}
markPeerUpdated(user);
}
}
void markPeerUpdated(PeerData *data) {
updatedPeers.insert(data, true);
}
void clearPeerUpdated(PeerData *data) {
updatedPeers.remove(data);
}
void emitPeerUpdated() {
if (!updatedPeers.isEmpty() && App::main()) {
UpdatedPeers upd = updatedPeers;
updatedPeers.clear();
for (UpdatedPeers::const_iterator i = upd.cbegin(), e = upd.cend(); i != e; ++i) {
App::main()->peerUpdated(i.key());
}
}
}
@ -2066,7 +1984,6 @@ namespace {
randomData.clear();
sentData.clear();
mutedPeers.clear();
updatedPeers.clear();
cSetSavedPeers(SavedPeers());
cSetSavedPeersByTime(SavedPeersByTime());
cSetRecentInlineBots(RecentInlineBots());

View File

@ -65,11 +65,11 @@ namespace App {
PeerData *feedChat(const MTPChat &chat);
PeerData *feedChats(const MTPVector<MTPChat> &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);
void feedChatAdmins(const MTPDupdateChatAdmins &d, bool emitPeerUpdated = true);
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d, bool emitPeerUpdated = true);
void feedParticipants(const MTPChatParticipants &p, bool requestBotInfos);
void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d);
void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d);
void feedChatAdmins(const MTPDupdateChatAdmins &d);
void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d);
bool checkEntitiesAndViewsUpdate(const MTPDmessage &m); // returns true if item found and it is not detached
void updateEditedMessage(const MTPMessage &m);
void addSavedGif(DocumentData *doc);
@ -81,9 +81,6 @@ namespace App {
void feedWereDeleted(ChannelId channelId, const QVector<MTPint> &msgsIds);
void feedUserLink(MTPint userId, const MTPContactLink &myLink, const MTPContactLink &foreignLink);
void markPeerUpdated(PeerData *data);
void clearPeerUpdated(PeerData *data);
ImagePtr image(const MTPPhotoSize &size);
StorageImageLocation imageLocation(int32 w, int32 h, const MTPFileLocation &loc);
StorageImageLocation imageLocation(const MTPPhotoSize &size);

View File

@ -1151,7 +1151,11 @@ void EditChannelBox::prepare() {
addButton(langFactory(lng_settings_save), [this] { onSave(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
connect(App::main(), SIGNAL(peerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&)), this, SLOT(peerUpdated(PeerData*)));
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::NameChanged, [this](const Notify::PeerUpdate &update) {
if (update.peer == _channel) {
handleChannelNameChange();
}
}));
setMouseTracking(true);
@ -1185,11 +1189,9 @@ void EditChannelBox::keyPressEvent(QKeyEvent *e) {
}
}
void EditChannelBox::peerUpdated(PeerData *peer) {
if (peer == _channel) {
_publicLink->setText(lang(_channel->isPublic() ? lng_profile_edit_public_link : lng_profile_create_public_link));
_sign->setChecked(_channel->addsSignature());
}
void EditChannelBox::handleChannelNameChange() {
_publicLink->setText(lang(_channel->isPublic() ? lng_profile_edit_public_link : lng_profile_create_public_link));
_sign->setChecked(_channel->addsSignature());
}
void EditChannelBox::onDescriptionResized() {

View File

@ -278,8 +278,6 @@ protected:
void paintEvent(QPaintEvent *e) override;
private slots:
void peerUpdated(PeerData *peer);
void onSave();
void onDescriptionResized();
void onPublicLink();
@ -291,6 +289,7 @@ private:
void updateMaxHeight();
bool canEditSignatures() const;
bool canEditInvites() const;
void handleChannelNameChange();
void onSaveTitleDone(const MTPUpdates &result);
void onSaveDescriptionDone(const MTPBool &result);

View File

@ -30,6 +30,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "ui/effects/ripple_animation.h"
#include "ui/effects/widget_slide_wrap.h"
#include "lang/lang_keys.h"
#include "observer_peer.h"
#include "storage/file_download.h"
#include "window/themes/window_theme.h"
@ -526,9 +527,15 @@ PeerListBox::Inner::Inner(QWidget *parent, gsl::not_null<PeerListController*> co
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) {
subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
connect(App::main(), SIGNAL(peerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&)), this, SLOT(onPeerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&)));
connect(App::main(), SIGNAL(peerPhotoChanged(PeerData*)), this, SLOT(peerUpdated(PeerData*)));
using UpdateFlag = Notify::PeerUpdate::Flag;
auto changes = UpdateFlag::NameChanged | UpdateFlag::PhotoChanged;
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(changes, [this](const Notify::PeerUpdate &update) {
if (update.flags & UpdateFlag::PhotoChanged) {
this->update();
} else if (update.flags & UpdateFlag::NameChanged) {
handleNameChanged(update);
}
}));
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) {
if (update.paletteChanged()) {
invalidatePixmapsCache();
@ -1208,10 +1215,6 @@ QRect PeerListBox::Inner::getActionRect(gsl::not_null<PeerListRow*> row, RowInde
return myrtlrect(actionLeft, rowTop + actionTop, actionSize.width(), actionSize.height());
}
void PeerListBox::Inner::peerUpdated(PeerData *peer) {
update();
}
int PeerListBox::Inner::rowsTop() const {
return _aboveHeight + st::membersMarginTop;
}
@ -1304,8 +1307,8 @@ PeerListBox::Inner::RowIndex PeerListBox::Inner::findRowIndex(gsl::not_null<Peer
return result;
}
void PeerListBox::Inner::onPeerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
auto byPeer = _rowsByPeer.find(peer);
void PeerListBox::Inner::handleNameChanged(const Notify::PeerUpdate &update) {
auto byPeer = _rowsByPeer.find(update.peer);
if (byPeer != _rowsByPeer.cend()) {
for (auto row : byPeer->second) {
if (addingToSearchIndex()) {

View File

@ -33,6 +33,10 @@ class WidgetSlideWrap;
class FlatLabel;
} // namespace Ui
namespace Notify {
struct PeerUpdate;
} // namespace Notify
inline auto PaintUserpicCallback(PeerData *peer) {
return [peer](Painter &p, int x, int y, int outerWidth, int size) {
peer->paintUserpicLeft(p, x, y, outerWidth, size);
@ -438,8 +442,6 @@ signals:
void mustScrollTo(int ymin, int ymax);
public slots:
void peerUpdated(PeerData *peer);
void onPeerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
protected:
int resizeGetHeight(int newWidth) override;
@ -454,6 +456,7 @@ protected:
private:
void refreshIndices();
void removeRowAtIndex(std::vector<std::unique_ptr<PeerListRow>> &from, int index);
void handleNameChanged(const Notify::PeerUpdate &update);
void invalidatePixmapsCache();

View File

@ -84,8 +84,6 @@ DialogsInner::DialogsInner(QWidget *parent, gsl::not_null<Window::Controller*> c
_dialogsImportant = std::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Date);
_importantSwitch = std::make_unique<ImportantSwitch>();
}
connect(main, SIGNAL(peerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&)), this, SLOT(onPeerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&)));
connect(main, SIGNAL(peerPhotoChanged(PeerData*)), this, SLOT(onPeerPhotoChanged(PeerData*)));
connect(main, SIGNAL(dialogRowReplaced(Dialogs::Row*, Dialogs::Row*)), this, SLOT(onDialogRowReplaced(Dialogs::Row*, Dialogs::Row*)));
connect(_addContactLnk, SIGNAL(clicked()), App::wnd(), SLOT(onShowAddContact()));
_cancelSearchInPeer->setClickedCallback([this] { cancelSearchInPeer(); });
@ -108,8 +106,21 @@ DialogsInner::DialogsInner(QWidget *parent, gsl::not_null<Window::Controller*> c
}
});
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::PinnedChanged, [this](const Notify::PeerUpdate &update) {
stopReorderPinned();
using UpdateFlag = Notify::PeerUpdate::Flag;
auto changes = UpdateFlag::PinnedChanged
| UpdateFlag::NameChanged
| UpdateFlag::PhotoChanged;
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(changes, [this](const Notify::PeerUpdate &update) {
if (update.flags & UpdateFlag::PinnedChanged) {
stopReorderPinned();
}
if (update.flags & UpdateFlag::NameChanged) {
handlePeerNameChange(update.peer, update.oldNames, update.oldNameFirstChars);
}
if (update.flags & UpdateFlag::PhotoChanged) {
this->update();
emit App::main()->dialogsUpdated();
}
}));
refresh();
@ -1253,7 +1264,7 @@ void DialogsInner::onParentGeometryChanged() {
}
}
void DialogsInner::onPeerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
void DialogsInner::handlePeerNameChange(gsl::not_null<PeerData*> peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
_dialogs->peerNameChanged(Dialogs::Mode::All, peer, oldNames, oldChars);
if (_dialogsImportant) {
_dialogsImportant->peerNameChanged(Dialogs::Mode::Important, peer, oldNames, oldChars);
@ -1263,10 +1274,6 @@ void DialogsInner::onPeerNameChanged(PeerData *peer, const PeerData::Names &oldN
update();
}
void DialogsInner::onPeerPhotoChanged(PeerData *peer) {
update();
}
void DialogsInner::onFilterUpdate(QString newFilter, bool force) {
auto words = TextUtilities::PrepareSearchWords(newFilter);
newFilter = words.isEmpty() ? QString() : words.join(' ');

View File

@ -115,10 +115,8 @@ public:
~DialogsInner();
public slots:
public slots:
void onParentGeometryChanged();
void onPeerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
void onPeerPhotoChanged(PeerData *peer);
void onDialogRowReplaced(Dialogs::Row *oldRow, Dialogs::Row *newRow);
void onMenuDestroyed(QObject*);
@ -172,6 +170,7 @@ private:
bool isSelected() const {
return _importantSwitchSelected || _selected || (_hashtagSelected >= 0) || (_filteredSelected >= 0) || (_peerSearchSelected >= 0) || (_searchedSelected >= 0);
}
void handlePeerNameChange(gsl::not_null<PeerData*> peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
void itemRemoved(HistoryItem *item);
enum class UpdateRowSection {

View File

@ -1055,7 +1055,7 @@ HistoryItem *History::createItem(const MTPMessage &msg, bool applyServiceAction,
case mtpc_messageActionPinMessage: {
if (m.has_reply_to_msg_id() && result && result->history()->peer->isMegagroup()) {
result->history()->peer->asChannel()->mgInfo->pinnedMsgId = m.vreply_to_msg_id.v;
if (App::main()) emit App::main()->peerUpdated(result->history()->peer);
Notify::peerUpdatedDelayed(result->history()->peer, Notify::PeerUpdate::Flag::ChannelPinnedChanged);
}
} break;

View File

@ -772,10 +772,52 @@ HistoryWidget::HistoryWidget(QWidget *parent, gsl::not_null<Window::Controller*>
scrollToCurrentVoiceMessage(pair.from.contextId(), pair.to);
}
});
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::ChannelRightsChanged | Notify::PeerUpdate::Flag::UnreadMentionsChanged, [this](const Notify::PeerUpdate &update) {
using UpdateFlag = Notify::PeerUpdate::Flag;
auto changes = UpdateFlag::ChannelRightsChanged
| UpdateFlag::UnreadMentionsChanged
| UpdateFlag::MigrationChanged
| UpdateFlag::RestrictionReasonChanged
| UpdateFlag::ChannelPinnedChanged
| UpdateFlag::UserIsBlocked
| UpdateFlag::AdminsChanged
| UpdateFlag::MembersChanged
| UpdateFlag::UserOnlineChanged;
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(changes, [this](const Notify::PeerUpdate &update) {
if (update.peer == _peer) {
if (update.flags & Notify::PeerUpdate::Flag::ChannelRightsChanged) onPreviewCheck();
if (update.flags & Notify::PeerUpdate::Flag::UnreadMentionsChanged) updateUnreadMentionsVisibility();
if (update.flags & UpdateFlag::ChannelRightsChanged) {
onPreviewCheck();
}
if (update.flags & UpdateFlag::UnreadMentionsChanged) {
updateUnreadMentionsVisibility();
}
if (update.flags & UpdateFlag::MigrationChanged) {
if (auto channel = _peer->migrateTo()) {
Ui::showPeerHistory(channel, ShowAtUnreadMsgId);
Auth().api().requestParticipantsCountDelayed(channel);
return;
}
}
if (update.flags & UpdateFlag::RestrictionReasonChanged) {
auto restriction = _peer->restrictionReason();
if (!restriction.isEmpty()) {
App::main()->showBackFromStack();
Ui::show(Box<InformBox>(restriction));
return;
}
}
if (update.flags & UpdateFlag::ChannelPinnedChanged) {
if (pinnedMsgVisibilityUpdated()) {
updateHistoryGeometry();
updateControlsVisibility();
updateControlsGeometry();
}
}
if (update.flags & (UpdateFlag::UserIsBlocked
| UpdateFlag::AdminsChanged
| UpdateFlag::MembersChanged
| UpdateFlag::UserOnlineChanged)) {
handlePeerUpdate();
}
}
}));
subscribe(controller->window()->widgetGrabbed(), [this] {
@ -1763,7 +1805,7 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
doneShow();
}
emit App::main()->peerUpdated(_peer);
handlePeerUpdate();
Local::readDraftsWithCursors(_history);
if (_migrated) {
@ -2774,7 +2816,6 @@ void HistoryWidget::unblockDone(PeerData *peer, const MTPBool &result, mtpReques
if (!peer->isUser()) return;
if (_unblockRequest == req) _unblockRequest = 0;
peer->asUser()->setBlockStatus(UserData::BlockStatus::NotBlocked);
emit App::main()->peerUpdated(peer);
}
bool HistoryWidget::unblockFail(const RPCError &error, mtpRequestId req) {
@ -2788,7 +2829,6 @@ void HistoryWidget::blockDone(PeerData *peer, const MTPBool &result) {
if (!peer->isUser()) return;
peer->asUser()->setBlockStatus(UserData::BlockStatus::Blocked);
emit App::main()->peerUpdated(peer);
}
void HistoryWidget::onBotStart() {
@ -5312,7 +5352,7 @@ bool HistoryWidget::pinnedMsgVisibilityUpdated() {
auto result = false;
auto pinnedMsgId = (_peer && _peer->isMegagroup()) ? _peer->asChannel()->mgInfo->pinnedMsgId : 0;
if (pinnedMsgId && !_peer->asChannel()->canPinMessages()) {
Global::HiddenPinnedMessagesMap::const_iterator it = Global::HiddenPinnedMessages().constFind(_peer->id);
auto it = Global::HiddenPinnedMessages().constFind(_peer->id);
if (it != Global::HiddenPinnedMessages().cend()) {
if (it.value() == pinnedMsgId) {
pinnedMsgId = 0;
@ -5954,6 +5994,8 @@ void HistoryWidget::fullPeerUpdated(PeerData *peer) {
onCheckFieldAutocomplete();
updateReportSpamStatus();
_list->updateBotInfo();
handlePeerUpdate();
}
if (updateCmdStartShown()) {
updateControlsVisibility();
@ -5964,51 +6006,35 @@ void HistoryWidget::fullPeerUpdated(PeerData *peer) {
}
}
void HistoryWidget::peerUpdated(PeerData *data) {
if (data && data == _peer) {
if (auto channel = data->migrateTo()) {
Ui::showPeerHistory(channel, ShowAtUnreadMsgId);
Auth().api().requestParticipantsCountDelayed(channel);
return;
}
QString restriction = _peer->restrictionReason();
if (!restriction.isEmpty()) {
App::main()->showBackFromStack();
Ui::show(Box<InformBox>(restriction));
return;
}
bool resize = false;
if (pinnedMsgVisibilityUpdated()) {
void HistoryWidget::handlePeerUpdate() {
bool resize = false;
updateHistoryGeometry();
if (_peer->isChannel()) updateReportSpamStatus();
if (_peer->isChat() && _peer->asChat()->noParticipantInfo()) {
Auth().api().requestFullPeer(_peer);
} else if (_peer->isUser() && (_peer->asUser()->blockStatus() == UserData::BlockStatus::Unknown || _peer->asUser()->callsStatus() == UserData::CallsStatus::Unknown)) {
Auth().api().requestFullPeer(_peer);
} else if (_peer->isMegagroup() && !_peer->asChannel()->mgInfo->botStatus) {
Auth().api().requestBots(_peer->asChannel());
}
if (!_a_show.animating()) {
if (_unblock->isHidden() == isBlocked() || (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) {
resize = true;
}
updateHistoryGeometry();
if (_peer->isChannel()) updateReportSpamStatus();
if (data->isChat() && data->asChat()->noParticipantInfo()) {
Auth().api().requestFullPeer(data);
} else if (data->isUser() && (data->asUser()->blockStatus() == UserData::BlockStatus::Unknown || data->asUser()->callsStatus() == UserData::CallsStatus::Unknown)) {
Auth().api().requestFullPeer(data);
} else if (data->isMegagroup() && !data->asChannel()->mgInfo->botStatus) {
Auth().api().requestBots(data->asChannel());
bool newCanSendMessages = canSendMessages(_peer);
if (newCanSendMessages != _canSendMessages) {
_canSendMessages = newCanSendMessages;
if (!_canSendMessages) {
cancelReply();
}
resize = true;
}
if (!_a_show.animating()) {
if (_unblock->isHidden() == isBlocked() || (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) {
resize = true;
}
bool newCanSendMessages = canSendMessages(_peer);
if (newCanSendMessages != _canSendMessages) {
_canSendMessages = newCanSendMessages;
if (!_canSendMessages) {
cancelReply();
}
resize = true;
}
updateControlsVisibility();
if (resize) {
updateControlsGeometry();
}
updateControlsVisibility();
if (resize) {
updateControlsGeometry();
}
App::main()->updateOnlineDisplay();
}
App::main()->updateOnlineDisplay();
}
void HistoryWidget::onForwardSelected() {

View File

@ -398,8 +398,6 @@ public slots:
void onPreviewCheck();
void onPreviewTimeout();
void peerUpdated(PeerData *data);
void onPhotoUploaded(const FullMsgId &msgId, bool silent, const MTPInputFile &file);
void onDocumentUploaded(const FullMsgId &msgId, bool silent, const MTPInputFile &file);
void onThumbDocumentUploaded(const FullMsgId &msgId, bool silent, const MTPInputFile &file, const MTPInputFile &thumb);
@ -492,6 +490,7 @@ private:
void setReportSpamStatus(DBIPeerReportSpamStatus status);
void historyDownClicked();
void showNextUnreadMention();
void handlePeerUpdate();
void animationCallback();
void updateOverStates(QPoint pos);

View File

@ -133,7 +133,6 @@ MainWidget::MainWidget(QWidget *parent, gsl::not_null<Window::Controller*> contr
connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled()));
connect(this, SIGNAL(dialogsUpdated()), _dialogs, SLOT(onListScroll()));
connect(_history, SIGNAL(cancelled()), _dialogs, SLOT(activate()));
connect(this, SIGNAL(peerPhotoChanged(PeerData*)), this, SIGNAL(dialogsUpdated()));
connect(&noUpdatesTimer, SIGNAL(timeout()), this, SLOT(mtpPing()));
connect(&_onlineTimer, SIGNAL(timeout()), this, SLOT(updateOnline()));
connect(&_onlineUpdater, SIGNAL(timeout()), this, SLOT(updateOnlineDisplay()));
@ -142,7 +141,6 @@ MainWidget::MainWidget(QWidget *parent, gsl::not_null<Window::Controller*> contr
connect(&_byPtsTimer, SIGNAL(timeout()), this, SLOT(onGetDifferenceTimeByPts()));
connect(&_byMinChannelTimer, SIGNAL(timeout()), this, SLOT(getDifference()));
connect(&_failDifferenceTimer, SIGNAL(timeout()), this, SLOT(onGetDifferenceTimeAfterFail()));
connect(this, SIGNAL(peerUpdated(PeerData*)), _history, SLOT(peerUpdated(PeerData*)));
connect(_history, SIGNAL(historyShown(History*,MsgId)), this, SLOT(onHistoryShown(History*,MsgId)));
connect(&updateNotifySettingTimer, SIGNAL(timeout()), this, SLOT(onUpdateNotifySettings()));
subscribe(Media::Player::Updated(), [this](const AudioMsgId &audioId) {
@ -151,9 +149,6 @@ MainWidget::MainWidget(QWidget *parent, gsl::not_null<Window::Controller*> contr
}
});
subscribe(Auth().calls().currentCallChanged(), [this](Calls::Call *call) { setCurrentCall(call); });
subscribe(Auth().api().fullPeerUpdated(), [this](PeerData *peer) {
emit peerUpdated(peer);
});
subscribe(_controller->dialogsListFocused(), [this](bool) {
updateDialogsWidthAnimated();
});
@ -2325,7 +2320,6 @@ void MainWidget::fillPeerMenu(PeerData *peer, base::lambda<QAction*(const QStrin
auto willBeBlocked = !user->isBlocked();
auto handler = ::rpcDone([user, willBeBlocked](const MTPBool &result) {
user->setBlockStatus(willBeBlocked ? UserData::BlockStatus::Blocked : UserData::BlockStatus::NotBlocked);
emit App::main()->peerUpdated(user);
});
if (willBeBlocked) {
MTP::send(MTPcontacts_Block(user->inputUser), std::move(handler));
@ -5015,23 +5009,23 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
} break;
case mtpc_updateChatParticipants: {
App::feedParticipants(update.c_updateChatParticipants().vparticipants, true, false);
App::feedParticipants(update.c_updateChatParticipants().vparticipants, true);
} break;
case mtpc_updateChatParticipantAdd: {
App::feedParticipantAdd(update.c_updateChatParticipantAdd(), false);
App::feedParticipantAdd(update.c_updateChatParticipantAdd());
} break;
case mtpc_updateChatParticipantDelete: {
App::feedParticipantDelete(update.c_updateChatParticipantDelete(), false);
App::feedParticipantDelete(update.c_updateChatParticipantDelete());
} break;
case mtpc_updateChatAdmins: {
App::feedChatAdmins(update.c_updateChatAdmins(), false);
App::feedChatAdmins(update.c_updateChatAdmins());
} break;
case mtpc_updateChatParticipantAdmin: {
App::feedParticipantAdmin(update.c_updateChatParticipantAdmin(), false);
App::feedParticipantAdmin(update.c_updateChatParticipantAdmin());
} break;
case mtpc_updateUserStatus: {
@ -5049,7 +5043,6 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
case mtpc_userStatusOffline: user->onlineTill = d.vstatus.c_userStatusOffline().vwas_online.v; break;
case mtpc_userStatusOnline: user->onlineTill = d.vstatus.c_userStatusOnline().vexpires.v; break;
}
App::markPeerUpdated(user);
Notify::peerUpdatedDelayed(user, Notify::PeerUpdate::Flag::UserOnlineChanged);
}
if (d.vuser_id.v == Auth().userId()) {
@ -5072,7 +5065,6 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
} else {
user->setName(TextUtilities::SingleLine(user->firstName), TextUtilities::SingleLine(user->lastName), user->nameOrPhone, TextUtilities::SingleLine(qs(d.vusername)));
}
App::markPeerUpdated(user);
}
} break;
@ -5093,7 +5085,6 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
user->photos.clear();
}
}
App::markPeerUpdated(user);
Notify::mediaOverviewUpdated(user, OverviewCount);
}
} break;
@ -5133,7 +5124,6 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
if (newPhone != user->phone()) {
user->setPhone(newPhone);
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);
}
@ -5164,7 +5154,6 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
auto &d = update.c_updateUserBlocked();
if (auto user = App::userLoaded(d.vuser_id.v)) {
user->setBlockStatus(mtpIsTrue(d.vblocked) ? UserData::BlockStatus::Blocked : UserData::BlockStatus::NotBlocked);
App::markPeerUpdated(user);
}
} break;
@ -5225,7 +5214,6 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
case mtpc_updateChannel: {
auto &d = update.c_updateChannel();
if (auto channel = App::channelLoaded(d.vchannel_id.v)) {
App::markPeerUpdated(channel);
channel->inviter = 0;
if (!channel->amIn()) {
deleteConversation(channel, false);

View File

@ -407,9 +407,6 @@ public:
~MainWidget();
signals:
void peerUpdated(PeerData *peer);
void peerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars);
void peerPhotoChanged(PeerData *peer);
void dialogRowReplaced(Dialogs::Row *oldRow, Dialogs::Row *newRow);
void dialogsUpdated();

View File

@ -22,11 +22,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "base/observer.h"
namespace App {
// Temp forward declaration (while all peer updates are not done through observers).
void emitPeerUpdated();
} // namespace App
namespace Notify {
namespace {
@ -93,8 +88,6 @@ void peerUpdatedDelayed(const PeerUpdate &update) {
}
void peerUpdatedSendDelayed() {
App::emitPeerUpdated();
if (!SmallUpdates || !AllUpdates || SmallUpdates->empty()) return;
auto smallList = base::take(*SmallUpdates);

View File

@ -45,13 +45,14 @@ struct PeerUpdate {
SharedMediaChanged = 0x00000020U,
MigrationChanged = 0x00000040U,
PinnedChanged = 0x00000080U,
RestrictionReasonChanged = 0x00000100U,
// For chats and channels
InviteLinkChanged = 0x00000100U,
MembersChanged = 0x00000200U,
AdminsChanged = 0x00000400U,
BannedUsersChanged = 0x00000800U,
UnreadMentionsChanged = 0x00001000U,
InviteLinkChanged = 0x00000200U,
MembersChanged = 0x00000400U,
AdminsChanged = 0x00000800U,
BannedUsersChanged = 0x00001000U,
UnreadMentionsChanged = 0x00002000U,
// For users
UserCanShareContact = 0x00010000U,
@ -71,6 +72,7 @@ struct PeerUpdate {
ChannelAmIn = 0x00010000U,
ChannelRightsChanged = 0x00020000U,
ChannelStickersChanged = 0x00040000U,
ChannelPinnedChanged = 0x00080000U,
};
using Flags = QFlags<Flag>;
Flags flags = 0;

View File

@ -4152,10 +4152,6 @@ PeerData *_readPeer(FileReadDescriptor &from, int32 fileVersion = 0) {
channel->setUserpic(photoLoc.isNull() ? ImagePtr() : ImagePtr(photoLoc));
}
}
if (!wasLoaded) {
App::markPeerUpdated(result);
emit App::main()->peerPhotoChanged(result);
}
return result;
}

View File

@ -317,9 +317,6 @@ void PeerData::updateNameDelayed(const QString &newName, const QString &newNameO
}
}
fillNames();
if (App::main()) {
emit App::main()->peerNameChanged(this, update.oldNames, update.oldNameFirstChars);
}
Notify::peerUpdatedDelayed(update);
}
@ -453,9 +450,6 @@ void UserData::setPhoto(const MTPUserProfilePhoto &p) { // see Local::readPeer a
photoId = newPhotoId;
setUserpic(newPhoto);
photoLoc = newPhotoLoc;
if (App::main()) {
emit App::main()->peerPhotoChanged(this);
}
Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged);
}
}
@ -491,6 +485,13 @@ bool UserData::setAbout(const QString &newAbout) {
return true;
}
void UserData::setRestrictionReason(const QString &text) {
if (_restrictionReason != text) {
_restrictionReason = text;
Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::RestrictionReasonChanged);
}
}
void UserData::setCommonChatsCount(int count) {
if (_commonChatsCount != count) {
_commonChatsCount = count;
@ -605,11 +606,9 @@ void UserData::madeAction(TimeId when) {
if (onlineTill <= 0 && -onlineTill < when) {
onlineTill = -when - SetOnlineAfterActivity;
App::markPeerUpdated(this);
Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::UserOnlineChanged);
} else if (onlineTill > 0 && onlineTill < when + 1) {
onlineTill = when + SetOnlineAfterActivity;
App::markPeerUpdated(this);
Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::UserOnlineChanged);
}
}
@ -657,9 +656,6 @@ void ChatData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see Loc
photoId = newPhotoId;
setUserpic(newPhoto);
photoLoc = newPhotoLoc;
if (App::main()) {
emit App::main()->peerPhotoChanged(this);
}
Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged);
}
}
@ -713,9 +709,6 @@ void ChannelData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see
photoId = newPhotoId;
setUserpic(newPhoto);
photoLoc = newPhotoLoc;
if (App::main()) {
emit App::main()->peerPhotoChanged(this);
}
Notify::peerUpdatedDelayed(this, UpdateFlag::PhotoChanged);
}
}
@ -839,17 +832,14 @@ void ChannelData::applyEditAdmin(gsl::not_null<UserData*> user, const MTPChannel
// We removed an admin.
if (adminsCount() > 1) {
setAdminsCount(adminsCount() - 1);
if (App::main()) emit App::main()->peerUpdated(this);
}
if (!isMegagroup() && user->botInfo && membersCount() > 1) {
// Removing bot admin removes it from channel.
setMembersCount(membersCount() - 1);
if (App::main()) emit App::main()->peerUpdated(this);
}
} else if (!oldRights.c_channelAdminRights().vflags.v && newRights.c_channelAdminRights().vflags.v) {
// We added an admin.
setAdminsCount(adminsCount() + 1);
if (App::main()) emit App::main()->peerUpdated(this);
updateFullForced();
}
Notify::peerUpdatedDelayed(this, flags);
@ -918,6 +908,13 @@ void ChannelData::flagsUpdated() {
}
}
void ChannelData::setRestrictionReason(const QString &text) {
if (_restrictionReason != text) {
_restrictionReason = text;
Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::RestrictionReasonChanged);
}
}
bool ChannelData::canNotEditLastAdmin(gsl::not_null<UserData*> user) const {
if (mgInfo) {
auto i = mgInfo->lastAdmins.constFind(user);

View File

@ -562,9 +562,7 @@ public:
QString restrictionReason() const override {
return _restrictionReason;
}
void setRestrictionReason(const QString &reason) {
_restrictionReason = reason;
}
void setRestrictionReason(const QString &reason);
int commonChatsCount() const {
return _commonChatsCount;
@ -985,9 +983,7 @@ public:
QString restrictionReason() const override {
return _restrictionReason;
}
void setRestrictionReason(const QString &reason) {
_restrictionReason = reason;
}
void setRestrictionReason(const QString &reason);
private:
bool canNotEditLastAdmin(gsl::not_null<UserData*> user) const;