not invalidating participants when admins not needed

This commit is contained in:
John Preston 2015-11-24 13:40:18 +03:00
parent 3cf4c7f2fc
commit b69f0db975
3 changed files with 16 additions and 8 deletions

View File

@ -437,7 +437,8 @@ void ApiWrap::requestPeers(const QList<PeerData*> &peers) {
void ApiWrap::requestLastParticipants(ChannelData *peer, bool fromStart) {
if (!peer || !peer->isMegagroup()) return;
if ((peer->mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsAdminsOutdated) || peer->lastParticipantsCountOutdated()) {
bool needAdmins = peer->amEditor(), adminsOutdated = (peer->mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsAdminsOutdated);
if ((needAdmins && adminsOutdated) || peer->lastParticipantsCountOutdated()) {
fromStart = true;
}
QMap<PeerData*, mtpRequestId>::iterator i = _participantsRequests.find(peer);

View File

@ -1500,12 +1500,12 @@ HistoryItem *History::createItem(HistoryBlock *block, const MTPMessage &msg, boo
case mtpc_messageActionChatAddUser: {
const MTPDmessageActionChatAddUser &d(action.c_messageActionChatAddUser());
if (peer->isMegagroup()) {
peer->asChannel()->mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsAdminsOutdated;
const QVector<MTPint> &v(d.vusers.c_vector().v);
for (int32 i = 0, l = v.size(); i < l; ++i) {
if (UserData *user = App::userLoaded(peerFromUser(v.at(i)))) {
if (peer->asChannel()->mgInfo->lastParticipants.indexOf(user) < 0) {
peer->asChannel()->mgInfo->lastParticipants.push_front(user);
peer->asChannel()->mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsAdminsOutdated;
}
if (user->botInfo) {
peer->asChannel()->mgInfo->bots.insert(user, true);
@ -1791,7 +1791,6 @@ HistoryItem *History::addNewItem(HistoryBlock *to, bool newBlock, HistoryItem *a
lastAuthors = &peer->asChat()->lastAuthors;
} else if (peer->isMegagroup()) {
lastAuthors = &peer->asChannel()->mgInfo->lastParticipants;
peer->asChannel()->mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsAdminsOutdated;
if (adding->from()->asUser()->botInfo) {
peer->asChannel()->mgInfo->bots.insert(adding->from()->asUser(), true);
if (peer->asChannel()->mgInfo->botStatus != 0 && peer->asChannel()->mgInfo->botStatus < 2) {
@ -1803,6 +1802,8 @@ HistoryItem *History::addNewItem(HistoryBlock *to, bool newBlock, HistoryItem *a
int prev = lastAuthors->indexOf(adding->from()->asUser());
if (prev > 0) {
lastAuthors->removeAt(prev);
} else if (prev < 0 && peer->isMegagroup()) { // nothing is outdated if just reordering
peer->asChannel()->mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsAdminsOutdated;
}
if (prev) {
lastAuthors->push_front(adding->from()->asUser());
@ -2015,7 +2016,6 @@ void History::addOlderSlice(const QVector<MTPMessage> &slice, const QVector<MTPM
} else if (peer->isMegagroup()) {
lastAuthors = &peer->asChannel()->mgInfo->lastParticipants;
markupSenders = &peer->asChannel()->mgInfo->markupSenders;
peer->asChannel()->mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsAdminsOutdated;
}
for (int32 i = block->items.size(); i > 0; --i) {
HistoryItem *item = block->items[i - 1];
@ -2038,8 +2038,13 @@ void History::addOlderSlice(const QVector<MTPMessage> &slice, const QVector<MTPM
}
if (item->from()->id) {
if (lastAuthors) { // chats
if (item->from()->isUser() && !lastAuthors->contains(item->from()->asUser())) {
lastAuthors->push_back(item->from()->asUser());
if (item->from()->isUser()) {
if (!lastAuthors->contains(item->from()->asUser())) {
lastAuthors->push_back(item->from()->asUser());
if (peer->isMegagroup()) {
peer->asChannel()->mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsAdminsOutdated;
}
}
}
}
if (markupSenders) { // chats with bots

View File

@ -130,7 +130,8 @@ ProfileInner::ProfileInner(ProfileWidget *profile, ScrollArea *scroll, PeerData
if (chatPhoto && chatPhoto->date) {
_photoLink = TextLinkPtr(new PhotoLink(chatPhoto, _peer));
}
if (_peerChannel->isMegagroup() && (_peerChannel->mgInfo->lastParticipants.isEmpty() || (_peerChannel->mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsAdminsOutdated) || _peerChannel->lastParticipantsCountOutdated())) {
bool needAdmins = _peerChannel->amEditor(), adminsOutdated = (_peerChannel->mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsAdminsOutdated);
if (_peerChannel->isMegagroup() && (_peerChannel->mgInfo->lastParticipants.isEmpty() || (needAdmins && adminsOutdated) || _peerChannel->lastParticipantsCountOutdated())) {
if (App::api()) App::api()->requestLastParticipants(_peerChannel);
}
_peerChannel->updateFull();
@ -686,7 +687,8 @@ void ProfileInner::reorderParticipants() {
}
loadProfilePhotos(_lastPreload);
} else if (_peerChannel && _peerChannel->isMegagroup() && _peerChannel->amIn() && !_peerChannel->mgInfo->lastParticipants.isEmpty()) {
if (_peerChannel->mgInfo->lastParticipants.isEmpty() || (_peerChannel->mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsAdminsOutdated) || _peerChannel->lastParticipantsCountOutdated()) {
bool needAdmins = _peerChannel->amEditor(), adminsOutdated = (_peerChannel->mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsAdminsOutdated);
if (_peerChannel->mgInfo->lastParticipants.isEmpty() || (needAdmins && adminsOutdated) || _peerChannel->lastParticipantsCountOutdated()) {
if (App::api()) App::api()->requestLastParticipants(_peerChannel);
} else if (!_peerChannel->mgInfo->lastParticipants.isEmpty()) {
const MegagroupInfo::LastParticipants &list(_peerChannel->mgInfo->lastParticipants);