Update full peer in profile and settings.

Not more than once in five seconds get the full info to update bio.
This commit is contained in:
John Preston 2017-07-26 14:53:49 +03:00
parent 24b3b2a658
commit 2e5930eb58
6 changed files with 34 additions and 17 deletions

View File

@ -299,6 +299,7 @@ void ApiWrap::gotChatFull(PeerData *peer, const MTPmessages_ChatFull &result, mt
chat->photoId = 0; chat->photoId = 0;
} }
chat->setInviteLink((f.vexported_invite.type() == mtpc_chatInviteExported) ? qs(f.vexported_invite.c_chatInviteExported().vlink) : QString()); 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); notifySettingReceived(MTP_inputNotifyPeer(peer->input), f.vnotify_settings);
} else if (auto channel = peer->asChannel()) { } 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->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->setAbout(d.has_about() ? qs(d.vabout) : QString());
user->setCommonChatsCount(d.vcommon_chats_count.v); user->setCommonChatsCount(d.vcommon_chats_count.v);
user->fullUpdated();
if (req) { if (req) {
auto i = _fullPeerRequests.find(user); auto i = _fullPeerRequests.find(user);
@ -763,7 +765,7 @@ void ApiWrap::unblockParticipant(PeerData *peer, UserData *user) {
if (channel->kickedCount() > 0) { if (channel->kickedCount() > 0) {
channel->setKickedCount(channel->kickedCount() - 1); channel->setKickedCount(channel->kickedCount() - 1);
} else { } else {
channel->updateFull(true); channel->updateFullForced();
} }
} }
}).fail([this, kick](const RPCError &error) { }).fail([this, kick](const RPCError &error) {
@ -1443,7 +1445,7 @@ void ApiWrap::resolveWebPages() {
void ApiWrap::requestParticipantsCountDelayed(ChannelData *channel) { void ApiWrap::requestParticipantsCountDelayed(ChannelData *channel) {
_participantsCountRequestTimer.call(kReloadChannelMembersTimeout, [this, channel] { _participantsCountRequestTimer.call(kReloadChannelMembersTimeout, [this, channel] {
channel->updateFull(true); channel->updateFullForced();
}); });
} }

View File

@ -328,7 +328,6 @@ enum {
UpdateChunk = 100 * 1024, // 100kb parts when downloading the update UpdateChunk = 100 * 1024, // 100kb parts when downloading the update
IdleMsecs = 60 * 1000, // after 60secs without user input we think we are idle 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 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 ForwardOnAdd = 100, // how many messages from chat history server should forward to user, that was added to this chat

View File

@ -58,6 +58,8 @@ CoverWidget::CoverWidget(QWidget *parent, PeerData *peer) : TWidget(parent)
, _peerMegagroup(peer->isMegagroup() ? _peerChannel : nullptr) , _peerMegagroup(peer->isMegagroup() ? _peerChannel : nullptr)
, _userpicButton(this, peer) , _userpicButton(this, peer)
, _name(this, st::profileNameLabel) { , _name(this, st::profileNameLabel) {
_peer->updateFull();
subscribe(Lang::Current().updated(), [this] { refreshLang(); }); subscribe(Lang::Current().updated(), [this] { refreshLang(); });
setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_OpaquePaintEvent);

View File

@ -45,6 +45,9 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent,
, _editNameInline(this, st::settingsEditButton) , _editNameInline(this, st::settingsEditButton)
, _setPhoto(this, langFactory(lng_settings_upload), st::settingsPrimaryButton) , _setPhoto(this, langFactory(lng_settings_upload), st::settingsPrimaryButton)
, _editName(this, langFactory(lng_settings_edit), st::settingsSecondaryButton) { , _editName(this, langFactory(lng_settings_edit), st::settingsSecondaryButton) {
if (_self) {
_self->updateFull();
}
setAcceptDrops(true); setAcceptDrops(true);
_name->setSelectable(true); _name->setSelectable(true);

View File

@ -41,6 +41,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace { namespace {
constexpr auto kUpdateFullPeerTimeout = TimeMs(5000); // Not more than once in 5 seconds.
int peerColorIndex(const PeerId &peer) { int peerColorIndex(const PeerId &peer) {
auto myId = AuthSession::CurrentUserId(); auto myId = AuthSession::CurrentUserId();
auto peerId = peerToBareInt(peer); auto peerId = peerToBareInt(peer);
@ -722,16 +724,24 @@ void ChannelData::setName(const QString &newName, const QString &newUsername) {
updateNameDelayed(newName.isEmpty() ? name : newName, QString(), newUsername); updateNameDelayed(newName.isEmpty() ? name : newName, QString(), newUsername);
} }
void ChannelData::updateFull(bool force) { void PeerData::updateFull() {
if (!_lastFullUpdate || force || getms(true) > _lastFullUpdate + UpdateFullChannelTimeout) { if (!_lastFullUpdate || getms(true) > _lastFullUpdate + kUpdateFullPeerTimeout) {
if (App::api()) { updateFullForced();
App::api()->requestFullPeer(this); }
if (!amCreator() && !inviter) App::api()->requestSelfParticipant(this); }
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); _lastFullUpdate = getms(true);
} }
@ -842,7 +852,7 @@ void ChannelData::applyEditAdmin(gsl::not_null<UserData*> user, const MTPChannel
// We added an admin. // We added an admin.
setAdminsCount(adminsCount() + 1); setAdminsCount(adminsCount() + 1);
if (App::main()) emit App::main()->peerUpdated(this); if (App::main()) emit App::main()->peerUpdated(this);
updateFull(true); updateFullForced();
} }
Notify::peerUpdatedDelayed(this, flags); Notify::peerUpdatedDelayed(this, flags);
} }

View File

@ -330,6 +330,13 @@ public:
ChatData *migrateFrom() const; ChatData *migrateFrom() const;
ChannelData *migrateTo() const; ChannelData *migrateTo() const;
void updateFull();
void updateFullForced();
void fullUpdated();
bool wasFullUpdated() const {
return (_lastFullUpdate != 0);
}
const Text &dialogName() const; const Text &dialogName() const;
const QString &shortName() const; const QString &shortName() const;
const QString &userName() const; const QString &userName() const;
@ -411,6 +418,7 @@ private:
ClickHandlerPtr _openLink; ClickHandlerPtr _openLink;
int _colorIndex = 0; int _colorIndex = 0;
TimeMs _lastFullUpdate = 0;
}; };
@ -762,12 +770,6 @@ public:
void setName(const QString &name, const QString &username); void setName(const QString &name, const QString &username);
void updateFull(bool force = false);
void fullUpdated();
bool wasFullUpdated() const {
return (_lastFullUpdate != 0);
}
uint64 access = 0; uint64 access = 0;
MTPinputChannel inputChannel; MTPinputChannel inputChannel;
@ -986,7 +988,6 @@ private:
bool canNotEditLastAdmin(gsl::not_null<UserData*> user) const; bool canNotEditLastAdmin(gsl::not_null<UserData*> user) const;
PtsWaiter _ptsWaiter; PtsWaiter _ptsWaiter;
TimeMs _lastFullUpdate = 0;
bool _isForbidden = true; bool _isForbidden = true;
int _membersCount = 1; int _membersCount = 1;