From 2e5930eb582cf46ab024eb0e7e32a640e735c027 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 26 Jul 2017 14:53:49 +0300 Subject: [PATCH] Update full peer in profile and settings. Not more than once in five seconds get the full info to update bio. --- Telegram/SourceFiles/apiwrap.cpp | 6 +++-- Telegram/SourceFiles/config.h | 1 - .../SourceFiles/profile/profile_cover.cpp | 2 ++ .../SourceFiles/settings/settings_cover.cpp | 3 +++ Telegram/SourceFiles/structs.cpp | 24 +++++++++++++------ Telegram/SourceFiles/structs.h | 15 ++++++------ 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 82aeb1a936..05c6a7aff3 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -299,6 +299,7 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt chat->photoId = 0; } chat->setInviteLink((f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString()); + chat->fullUpdated(); notifySettingReceived(MTP_inputNotifyPeer(peer->input), f.vnotify_settings); } else if (auto channel = peer->asChannel()) { @@ -426,6 +427,7 @@ void ApiWrap::gotUserFull(UserData *user, const MTPUserFull &result, mtpRequestI user->setCallsStatus(d.is_phone_calls_private() ? UserData::CallsStatus::Private : d.is_phone_calls_available() ? UserData::CallsStatus::Enabled : UserData::CallsStatus::Disabled); user->setAbout(d.has_about() ? qs(d.vabout) : QString()); user->setCommonChatsCount(d.vcommon_chats_count.v); + user->fullUpdated(); if (req) { auto i = _fullPeerRequests.find(user); @@ -763,7 +765,7 @@ void ApiWrap::unblockParticipant(PeerData *peer, UserData *user) { if (channel->kickedCount() > 0) { channel->setKickedCount(channel->kickedCount() - 1); } else { - channel->updateFull(true); + channel->updateFullForced(); } } }).fail([this, kick](const RPCError &error) { @@ -1443,7 +1445,7 @@ void ApiWrap::resolveWebPages() { void ApiWrap::requestParticipantsCountDelayed(ChannelData *channel) { _participantsCountRequestTimer.call(kReloadChannelMembersTimeout, [this, channel] { - channel->updateFull(true); + channel->updateFullForced(); }); } diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 5341d6c510..bacf4a43a0 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -328,7 +328,6 @@ enum { UpdateChunk = 100 * 1024, // 100kb parts when downloading the update IdleMsecs = 60 * 1000, // after 60secs without user input we think we are idle - UpdateFullChannelTimeout = 5000, // not more than once in 5 seconds SendViewsTimeout = 1000, // send views each second ForwardOnAdd = 100, // how many messages from chat history server should forward to user, that was added to this chat diff --git a/Telegram/SourceFiles/profile/profile_cover.cpp b/Telegram/SourceFiles/profile/profile_cover.cpp index 434f0a8de3..f5eb080125 100644 --- a/Telegram/SourceFiles/profile/profile_cover.cpp +++ b/Telegram/SourceFiles/profile/profile_cover.cpp @@ -58,6 +58,8 @@ CoverWidget::CoverWidget(QWidget *parent, PeerData *peer) : TWidget(parent) , _peerMegagroup(peer->isMegagroup() ? _peerChannel : nullptr) , _userpicButton(this, peer) , _name(this, st::profileNameLabel) { + _peer->updateFull(); + subscribe(Lang::Current().updated(), [this] { refreshLang(); }); setAttribute(Qt::WA_OpaquePaintEvent); diff --git a/Telegram/SourceFiles/settings/settings_cover.cpp b/Telegram/SourceFiles/settings/settings_cover.cpp index f088aa211a..da9c7ada87 100644 --- a/Telegram/SourceFiles/settings/settings_cover.cpp +++ b/Telegram/SourceFiles/settings/settings_cover.cpp @@ -45,6 +45,9 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent, , _editNameInline(this, st::settingsEditButton) , _setPhoto(this, langFactory(lng_settings_upload), st::settingsPrimaryButton) , _editName(this, langFactory(lng_settings_edit), st::settingsSecondaryButton) { + if (_self) { + _self->updateFull(); + } setAcceptDrops(true); _name->setSelectable(true); diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index 0caacf67a3..ba899ad504 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -41,6 +41,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace { +constexpr auto kUpdateFullPeerTimeout = TimeMs(5000); // Not more than once in 5 seconds. + int peerColorIndex(const PeerId &peer) { auto myId = AuthSession::CurrentUserId(); auto peerId = peerToBareInt(peer); @@ -722,16 +724,24 @@ void ChannelData::setName(const QString &newName, const QString &newUsername) { updateNameDelayed(newName.isEmpty() ? name : newName, QString(), newUsername); } -void ChannelData::updateFull(bool force) { - if (!_lastFullUpdate || force || getms(true) > _lastFullUpdate + UpdateFullChannelTimeout) { - if (App::api()) { - App::api()->requestFullPeer(this); - if (!amCreator() && !inviter) App::api()->requestSelfParticipant(this); +void PeerData::updateFull() { + if (!_lastFullUpdate || getms(true) > _lastFullUpdate + kUpdateFullPeerTimeout) { + updateFullForced(); + } +} + +void PeerData::updateFullForced() { + if (App::api()) { + App::api()->requestFullPeer(this); + if (auto channel = asChannel()) { + if (!channel->amCreator() && !channel->inviter) { + App::api()->requestSelfParticipant(channel); + } } } } -void ChannelData::fullUpdated() { +void PeerData::fullUpdated() { _lastFullUpdate = getms(true); } @@ -842,7 +852,7 @@ void ChannelData::applyEditAdmin(gsl::not_null user, const MTPChannel // We added an admin. setAdminsCount(adminsCount() + 1); if (App::main()) emit App::main()->peerUpdated(this); - updateFull(true); + updateFullForced(); } Notify::peerUpdatedDelayed(this, flags); } diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index 7d72f5560f..c01a8e1677 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -330,6 +330,13 @@ public: ChatData *migrateFrom() const; ChannelData *migrateTo() const; + void updateFull(); + void updateFullForced(); + void fullUpdated(); + bool wasFullUpdated() const { + return (_lastFullUpdate != 0); + } + const Text &dialogName() const; const QString &shortName() const; const QString &userName() const; @@ -411,6 +418,7 @@ private: ClickHandlerPtr _openLink; int _colorIndex = 0; + TimeMs _lastFullUpdate = 0; }; @@ -762,12 +770,6 @@ public: void setName(const QString &name, const QString &username); - void updateFull(bool force = false); - void fullUpdated(); - bool wasFullUpdated() const { - return (_lastFullUpdate != 0); - } - uint64 access = 0; MTPinputChannel inputChannel; @@ -986,7 +988,6 @@ private: bool canNotEditLastAdmin(gsl::not_null user) const; PtsWaiter _ptsWaiter; - TimeMs _lastFullUpdate = 0; bool _isForbidden = true; int _membersCount = 1;