Fix members list in supergroups when scrolling up.

When we load previous messages in chat history we add all authors
of the messages to lastAuthors in regular groups (so that we can
suggest them in mention autocomplete). The same logic was (blindly)
applied to supergroups lastParticipants list which is used not only
for the mention autocomplete but also in Profile members list. That
way we were showing there users who could've already left the group.
This commit is contained in:
John Preston 2017-02-26 20:49:13 +03:00
parent dcd6028e91
commit e8b03248e1
2 changed files with 19 additions and 10 deletions

View File

@ -1286,7 +1286,7 @@ void History::addOlderSlice(const QVector<MTPMessage> &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<UserData*> *lastAuthors = nullptr;
@ -1295,7 +1295,12 @@ void History::addOlderSlice(const QVector<MTPMessage> &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<MTPMessage> &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);

View File

@ -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)));
}