From 04b0932780601cef385f24b672b84f3c7c6b0d8e Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 1 Nov 2015 21:28:24 -0500 Subject: [PATCH] some fixes in admins and participants counts requesting --- Telegram/SourceFiles/app.cpp | 35 +++++++++++++++------- Telegram/SourceFiles/boxes/contactsbox.cpp | 10 +++++-- Telegram/SourceFiles/dropdown.cpp | 16 ++++------ Telegram/SourceFiles/history.cpp | 4 +-- Telegram/SourceFiles/historywidget.cpp | 2 +- Telegram/SourceFiles/profilewidget.cpp | 10 +++---- Telegram/SourceFiles/structs.h | 6 ++-- 7 files changed, 49 insertions(+), 34 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 69acb85372..85ec3e94cf 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -504,7 +504,7 @@ namespace App { cdata->date = d.vdate.v; if (!(cdata->flags & MTPDchat::flag_admins_enabled) && (d.vflags.v & MTPDchat::flag_admins_enabled)) { - cdata->invalidateParticipants(false); + cdata->invalidateParticipants(); } cdata->flags = d.vflags.v; @@ -512,7 +512,7 @@ namespace App { cdata->isForbidden = false; if (cdata->version < d.vversion.v) { cdata->version = d.vversion.v; - cdata->invalidateParticipants(false); + cdata->invalidateParticipants(); } } break; case mtpc_chatForbidden: { @@ -527,7 +527,7 @@ namespace App { cdata->setPhoto(MTP_chatPhotoEmpty()); cdata->date = 0; cdata->count = -1; - cdata->invalidateParticipants(false); + cdata->invalidateParticipants(); cdata->flags = 0; cdata->isForbidden = true; } break; @@ -594,7 +594,7 @@ namespace App { const MTPDchatParticipantsForbidden &d(p.c_chatParticipantsForbidden()); chat = App::chat(d.vchat_id.v); chat->count = -1; - chat->invalidateParticipants(false); + chat->invalidateParticipants(); } break; case mtpc_chatParticipants: { @@ -638,7 +638,7 @@ namespace App { chat->admins[user] = true; } } else { - chat->invalidateParticipants(false); + chat->invalidateParticipants(); break; } } @@ -682,7 +682,9 @@ namespace App { void feedParticipantAdd(const MTPDupdateChatParticipantAdd &d, bool emitPeerUpdated) { ChatData *chat = App::chat(d.vchat_id.v); if (chat->version + 1 < d.vversion.v) { + chat->version = d.vversion.v; chat->invalidateParticipants(); + App::api()->requestPeer(chat); if (App::main()) { if (emitPeerUpdated) { App::main()->peerUpdated(chat); @@ -711,7 +713,7 @@ namespace App { } } } else { - chat->invalidateParticipants(false); + chat->invalidateParticipants(); chat->count++; } if (App::main()) { @@ -727,7 +729,9 @@ namespace App { void feedParticipantDelete(const MTPDupdateChatParticipantDelete &d, bool emitPeerUpdated) { ChatData *chat = App::chat(d.vchat_id.v); if (chat->version + 1 < d.vversion.v) { + chat->version = d.vversion.v; chat->invalidateParticipants(); + App::api()->requestPeer(chat); if (App::main()) { if (emitPeerUpdated) { App::main()->peerUpdated(chat); @@ -740,7 +744,9 @@ namespace App { UserData *user = App::userLoaded(d.vuser_id.v); if (user) { if (chat->participants.isEmpty()) { - chat->count--; + if (chat->count > 0) { + chat->count--; + } } else { ChatData::Participants::iterator i = chat->participants.find(user); if (i != chat->participants.end()) { @@ -771,7 +777,7 @@ namespace App { } } } else { - chat->invalidateParticipants(false); + chat->invalidateParticipants(); chat->count--; } if (App::main()) { @@ -790,12 +796,13 @@ namespace App { bool badVersion = (chat->version + 1 < d.vversion.v); if (badVersion) { chat->invalidateParticipants(); + App::api()->requestPeer(chat); } chat->version = d.vversion.v; if (mtpIsTrue(d.venabled)) { chat->flags |= MTPDchat::flag_admins_enabled; if (!badVersion) { - chat->invalidateParticipants(false); + chat->invalidateParticipants(); } } else { chat->flags &= ~MTPDchat::flag_admins_enabled; @@ -811,7 +818,9 @@ namespace App { void feedParticipantAdmin(const MTPDupdateChatParticipantAdmin &d, bool emitPeerUpdated) { ChatData *chat = App::chat(d.vchat_id.v); if (chat->version + 1 < d.vversion.v) { + chat->version = d.vversion.v; chat->invalidateParticipants(); + App::api()->requestPeer(chat); if (App::main()) { if (emitPeerUpdated) { App::main()->peerUpdated(chat); @@ -824,12 +833,16 @@ namespace App { UserData *user = App::userLoaded(d.vuser_id.v); if (user) { if (mtpIsTrue(d.vis_admin)) { - chat->admins.insert(user, true); + if (chat->noParticipantInfo()) { + App::api()->requestFullPeer(chat); + } else { + chat->admins.insert(user, true); + } } else { chat->admins.remove(user); } } else { - chat->invalidateParticipants(false); + chat->invalidateParticipants(); } if (App::main()) { if (emitPeerUpdated) { diff --git a/Telegram/SourceFiles/boxes/contactsbox.cpp b/Telegram/SourceFiles/boxes/contactsbox.cpp index 85ee39efd8..0a8d062053 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.cpp +++ b/Telegram/SourceFiles/boxes/contactsbox.cpp @@ -287,7 +287,7 @@ void ContactsInner::peerUpdated(PeerData *peer) { } if (!_chat->amIn()) { App::wnd()->hideLayer(); - } else if (!_chat->participants.isEmpty() || _chat->count <= 0) { + } else if (!_chat->participants.isEmpty()) { for (ContactsData::iterator i = _contactsData.begin(), e = _contactsData.end(); i != e; ++i) { delete i.value(); } @@ -1645,7 +1645,11 @@ void ContactsBox::getAdminsDone(const MTPmessages_ChatFull &result) { void ContactsBox::setAdminDone(UserData *user, const MTPBool &result) { if (mtpIsTrue(result)) { - _inner.chat()->admins.insert(user, true); + if (_inner.chat()->noParticipantInfo()) { + App::api()->requestFullPeer(_inner.chat()); + } else { + _inner.chat()->admins.insert(user, true); + } } --_saveRequestId; if (!_saveRequestId) { @@ -1678,7 +1682,7 @@ bool ContactsBox::saveAdminsFail(const RPCError &error) { bool ContactsBox::editAdminFail(const RPCError &error) { if (mtpIsFlood(error)) return true; --_saveRequestId; - _inner.chat()->invalidateParticipants(false); + _inner.chat()->invalidateParticipants(); if (!_saveRequestId) onClose(); return false; } diff --git a/Telegram/SourceFiles/dropdown.cpp b/Telegram/SourceFiles/dropdown.cpp index a9dec1f4c4..a6c6eb5d11 100644 --- a/Telegram/SourceFiles/dropdown.cpp +++ b/Telegram/SourceFiles/dropdown.cpp @@ -2979,11 +2979,9 @@ void MentionsDropdown::updateFiltered(bool toDown) { if (_filter.at(0) == '@' && _chat) { QMultiMap ordered; rows.reserve(_chat->participants.isEmpty() ? _chat->lastAuthors.size() : _chat->participants.size()); - if (_chat->participants.isEmpty()) { - if (_chat->count > 0 && App::api()) { - App::api()->requestFullPeer(_chat); - } - } else { + if (_chat->noParticipantInfo()) { + if (App::api()) App::api()->requestFullPeer(_chat); + } else if (!_chat->participants.isEmpty()) { for (ChatData::Participants::const_iterator i = _chat->participants.cbegin(), e = _chat->participants.cend(); i != e; ++i) { UserData *user = i.key(); if (user->username.isEmpty()) continue; @@ -3018,11 +3016,9 @@ void MentionsDropdown::updateFiltered(bool toDown) { QMap bots; int32 cnt = 0; if (_chat) { - if (_chat->participants.isEmpty()) { - if (_chat->count > 0 && App::api()) { - App::api()->requestFullPeer(_chat); - } - } else { + if (_chat->noParticipantInfo()) { + if (App::api()) App::api()->requestFullPeer(_chat); + } else if (!_chat->participants.isEmpty()) { int32 index = 0; for (ChatData::Participants::const_iterator i = _chat->participants.cbegin(), e = _chat->participants.cend(); i != e; ++i) { UserData *user = i.key(); diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 4e6e9052f4..936d4d6cf0 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -1706,7 +1706,7 @@ HistoryItem *History::addNewItem(HistoryBlock *to, bool newBlock, HistoryItem *a if (lastKeyboardFrom == adding->from()->id || (!lastKeyboardInited && !peer->isChat() && !adding->out())) { clearLastKeyboard(); } - } else if (peer->isChat() && adding->from()->isUser() && (peer->asChat()->count < 1 || !peer->asChat()->participants.isEmpty()) && !peer->asChat()->participants.contains(adding->from()->asUser())) { + } else if (peer->isChat() && adding->from()->isUser() && (!peer->asChat()->amIn() || !peer->asChat()->participants.isEmpty()) && !peer->asChat()->participants.contains(adding->from()->asUser())) { clearLastKeyboard(); } else { lastKeyboardInited = true; @@ -1914,7 +1914,7 @@ void History::addOlderSlice(const QVector &slice, const QVectorasChat()->count < 1 || !peer->asChat()->participants.isEmpty()) && item->from()->isUser() && !peer->asChat()->participants.contains(item->from()->asUser()))) { + if (wasKeyboardHide || ((!peer->asChat()->amIn() || !peer->asChat()->participants.isEmpty()) && item->from()->isUser() && !peer->asChat()->participants.contains(item->from()->asUser()))) { clearLastKeyboard(); } else { lastKeyboardInited = true; diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 6e862ac33e..dfd38034ae 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -5944,7 +5944,7 @@ void HistoryWidget::peerUpdated(PeerData *data) { updateListSize(); if (_peer->isChannel()) updateReportSpamStatus(); if (App::api()) { - if (data->isChat() && data->asChat()->count > 0 && data->asChat()->participants.isEmpty()) { + if (data->isChat() && data->asChat()->noParticipantInfo()) { App::api()->requestFullPeer(data); } else if (data->isUser() && data->asUser()->blocked == UserBlockUnknown) { App::api()->requestFullPeer(data); diff --git a/Telegram/SourceFiles/profilewidget.cpp b/Telegram/SourceFiles/profilewidget.cpp index 6ddda7e944..8e381b392e 100644 --- a/Telegram/SourceFiles/profilewidget.cpp +++ b/Telegram/SourceFiles/profilewidget.cpp @@ -589,7 +589,7 @@ void ProfileInner::updateOnlineDisplayTimer() { void ProfileInner::reorderParticipants() { int32 was = _participants.size(), t = unixtime(), onlineCount = 0; if (_peerChat && _peerChat->amIn()) { - if (_peerChat->count <= 0 || !_peerChat->participants.isEmpty()) { + if (!_peerChat->participants.isEmpty()) { _participants.clear(); for (ParticipantsData::iterator i = _participantsData.begin(), e = _participantsData.end(); i != e; ++i) { if (*i) { @@ -620,7 +620,7 @@ void ProfileInner::reorderParticipants() { ++onlineCount; } } - if (_peerChat->count > 0 && _participants.isEmpty()) { + if (_peerChat->noParticipantInfo()) { if (App::api()) App::api()->requestFullPeer(_peer); if (_onlineText.isEmpty()) _onlineText = lng_chat_status_members(lt_count, _peerChat->count); } else if (onlineCount && !onlyMe) { @@ -811,7 +811,7 @@ void ProfileInner::paintEvent(QPaintEvent *e) { } // participants - if (_peerChat && (_peerChat->count > 0 || !_participants.isEmpty())) { + if (_peerChat && _peerChat->amIn()) { QString sectionHeader = lang(_participants.isEmpty() ? lng_profile_loading : lng_profile_participants_section); p.setFont(st::profileHeaderFont->f); p.setPen(st::profileHeaderColor->p); @@ -1209,7 +1209,7 @@ void ProfileInner::resizeEvent(QResizeEvent *e) { } // participants - if (_peerChat && (_peerChat->count > 0 || !_participants.isEmpty())) { + if (_peerChat && _peerChat->amIn()) { top += st::profileHeaderSkip; if (!_participants.isEmpty()) { int32 fullCnt = _participants.size(); @@ -1321,7 +1321,7 @@ int32 ProfileInner::countMinHeight() { h = _deleteConversation.y() + _deleteConversation.height() + st::profileHeaderSkip; if (!_participants.isEmpty()) { h += st::profileHeaderSkip + _participants.size() * _pHeight; - } else if (_peerChat->count > 0) { + } else if (_peerChat->amIn()) { h += st::profileHeaderSkip; } } else if (_peerChannel) { diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index daa3167f83..6d857bab78 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -375,12 +375,14 @@ public: ChatData(const PeerId &id) : PeerData(id), inputChat(MTP_int(bareId())), count(0), date(0), version(0), creator(0), inviterForSpamReport(0), flags(0), isForbidden(false), botStatus(0) { } void setPhoto(const MTPChatPhoto &photo, const PhotoId &phId = UnknownPeerPhotoId); - void invalidateParticipants(bool invalidateCount = true) { + void invalidateParticipants() { participants = ChatData::Participants(); admins = ChatData::Admins(); invitedByMe = ChatData::InvitedByMe(); botStatus = 0; - if (invalidateCount) count = 0; + } + bool noParticipantInfo() const { + return (count > 0 || amIn()) && participants.isEmpty(); } MTPint inputChat;