diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index c3c21c0d2..ef24c24aa 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -1286,7 +1286,7 @@ void History::addOlderSlice(const QVector &slice) { if (!block) { // If no items were added it means we've loaded everything old. oldLoaded = true; - } else if (loadedAtBottom()) { // add photos to overview and authors to lastAuthors / lastParticipants + } else if (loadedAtBottom()) { // add photos to overview and authors to lastAuthors bool channel = isChannel(); int32 mask = 0; QList *lastAuthors = nullptr; @@ -1295,7 +1295,12 @@ void History::addOlderSlice(const QVector &slice) { lastAuthors = &peer->asChat()->lastAuthors; markupSenders = &peer->asChat()->markupSenders; } else if (peer->isMegagroup()) { - lastAuthors = &peer->asChannel()->mgInfo->lastParticipants; + // We don't add users to mgInfo->lastParticipants here. + // We're scrolling back and we see messages from users that + // could be gone from the megagroup already. It is fine for + // chat->lastAuthors, because they're used only for field + // autocomplete, but this is bad for megagroups, because its + // lastParticipants are displayed in Profile as members list. markupSenders = &peer->asChannel()->mgInfo->markupSenders; } for (int32 i = block->items.size(); i > 0; --i) { @@ -1303,9 +1308,9 @@ void History::addOlderSlice(const QVector &slice) { mask |= item->addToOverview(AddToOverviewFront); if (item->from()->id) { if (lastAuthors) { // chats - if (item->from()->isUser()) { - if (!lastAuthors->contains(item->from()->asUser())) { - lastAuthors->push_back(item->from()->asUser()); + if (auto user = item->from()->asUser()) { + if (!lastAuthors->contains(user)) { + lastAuthors->push_back(user); if (peer->isMegagroup()) { peer->asChannel()->mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsAdminsOutdated; Notify::peerUpdatedDelayed(peer, Notify::PeerUpdate::Flag::MembersChanged); diff --git a/Telegram/SourceFiles/history/field_autocomplete.cpp b/Telegram/SourceFiles/history/field_autocomplete.cpp index eb7164464..b8b3a30a4 100644 --- a/Telegram/SourceFiles/history/field_autocomplete.cpp +++ b/Telegram/SourceFiles/history/field_autocomplete.cpp @@ -274,7 +274,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) { if (App::api()) App::api()->requestFullPeer(_chat); } else if (!_chat->participants.isEmpty()) { for (auto i = _chat->participants.cbegin(), e = _chat->participants.cend(); i != e; ++i) { - UserData *user = i.key(); + auto user = i.key(); if (!user->botInfo) continue; if (!user->botInfo->inited && App::api()) App::api()->requestFullPeer(user); if (user->botInfo->commands.isEmpty()) continue; @@ -304,16 +304,20 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) { int32 botStatus = _chat ? _chat->botStatus : ((_channel && _channel->isMegagroup()) ? _channel->mgInfo->botStatus : -1); if (_chat) { for (auto i = _chat->lastAuthors.cbegin(), e = _chat->lastAuthors.cend(); i != e; ++i) { - UserData *user = *i; + auto user = *i; if (!user->botInfo) continue; if (!bots.contains(user)) continue; if (!user->botInfo->inited && App::api()) App::api()->requestFullPeer(user); if (user->botInfo->commands.isEmpty()) continue; bots.remove(user); - for (int32 j = 0, l = user->botInfo->commands.size(); j < l; ++j) { + for (auto j = 0, l = user->botInfo->commands.size(); j != l; ++j) { if (!listAllSuggestions) { - QString toFilter = (hasUsername || botStatus == 0 || botStatus == 2) ? user->botInfo->commands.at(j).command + '@' + user->username : user->botInfo->commands.at(j).command; - if (!toFilter.startsWith(_filter, Qt::CaseInsensitive)/* || toFilter.size() == _filter.size()*/) continue; + auto toFilter = (hasUsername || botStatus == 0 || botStatus == 2) + ? user->botInfo->commands.at(j).command + '@' + user->username + : user->botInfo->commands.at(j).command; + if (!toFilter.startsWith(_filter, Qt::CaseInsensitive)/* || toFilter.size() == _filter.size()*/) { + continue; + } } brows.push_back(qMakePair(user, &user->botInfo->commands.at(j))); }