Fix members dropdown and mention autocomplete.

Fixes #7345.
This commit is contained in:
John Preston 2020-03-13 23:14:23 +04:00
parent 084b9ce4de
commit 1492571232
6 changed files with 22 additions and 20 deletions

View file

@ -1503,7 +1503,8 @@ void ApiWrap::applyLastParticipantsList(
channel->mgInfo->lastAdmins.clear();
channel->mgInfo->lastRestricted.clear();
channel->mgInfo->lastParticipants.clear();
channel->mgInfo->lastParticipantsStatus = MegagroupInfo::LastParticipantsUpToDate;
channel->mgInfo->lastParticipantsStatus = MegagroupInfo::LastParticipantsUpToDate
| MegagroupInfo::LastParticipantsOnceReceived;
auto botStatus = channel->mgInfo->botStatus;
const auto emptyAdminRights = MTP_chatAdminRights(MTP_flags(0));

View file

@ -206,8 +206,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
if (_chat) {
maxListSize += (_chat->participants.empty() ? _chat->lastAuthors.size() : _chat->participants.size());
} else if (_channel && _channel->isMegagroup()) {
if (_channel->mgInfo->lastParticipants.empty() || _channel->lastParticipantsCountOutdated()) {
} else {
if (!_channel->lastParticipantsRequestNeeded()) {
maxListSize += _channel->mgInfo->lastParticipants.size();
}
}
@ -274,7 +273,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
}
} else if (_channel && _channel->isMegagroup()) {
QMultiMap<int32, UserData*> ordered;
if (_channel->mgInfo->lastParticipants.empty() || _channel->lastParticipantsCountOutdated()) {
if (_channel->lastParticipantsRequestNeeded()) {
Auth().api().requestLastParticipants(_channel);
} else {
mrows.reserve(mrows.size() + _channel->mgInfo->lastParticipants.size());

View file

@ -340,6 +340,20 @@ bool ChannelData::isGroupAdmin(not_null<UserData*> user) const {
return false;
}
bool ChannelData::lastParticipantsRequestNeeded() const {
if (!mgInfo) {
return false;
} else if (mgInfo->lastParticipantsCount == membersCount()) {
mgInfo->lastParticipantsStatus
&= ~MegagroupInfo::LastParticipantsCountOutdated;
}
return mgInfo->lastParticipants.empty()
|| !(mgInfo->lastParticipantsStatus
& MegagroupInfo::LastParticipantsOnceReceived)
|| (mgInfo->lastParticipantsStatus
& MegagroupInfo::LastParticipantsCountOutdated);
}
auto ChannelData::unavailableReasons() const
-> const std::vector<Data::UnavailableReason> & {
return _unavailableReasons;

View file

@ -73,6 +73,7 @@ public:
enum LastParticipantsStatus {
LastParticipantsUpToDate = 0x00,
LastParticipantsOnceReceived = 0x01,
LastParticipantsCountOutdated = 0x02,
};
mutable int lastParticipantsStatus = LastParticipantsUpToDate;
@ -219,20 +220,7 @@ public:
void markForbidden();
[[nodiscard]] bool isGroupAdmin(not_null<UserData*> user) const;
[[nodiscard]] bool lastParticipantsCountOutdated() const {
if (!mgInfo
|| !(mgInfo->lastParticipantsStatus
& MegagroupInfo::LastParticipantsCountOutdated)) {
return false;
}
if (mgInfo->lastParticipantsCount == membersCount()) {
mgInfo->lastParticipantsStatus
&= ~MegagroupInfo::LastParticipantsCountOutdated;
return false;
}
return true;
}
[[nodiscard]] bool lastParticipantsRequestNeeded() const;
[[nodiscard]] bool isMegagroup() const {
return flags() & MTPDchannel::Flag::f_megagroup;
}

View file

@ -848,7 +848,7 @@ void TopBarWidget::updateOnlineDisplay() {
}
} else if (const auto channel = _activeChat.peer()->asChannel()) {
if (channel->isMegagroup() && channel->membersCount() > 0 && channel->membersCount() <= Global::ChatSizeMax()) {
if (channel->mgInfo->lastParticipants.empty() || channel->lastParticipantsCountOutdated()) {
if (channel->lastParticipantsRequestNeeded()) {
session().api().requestLastParticipants(channel);
}
const auto self = session().user();

View file

@ -192,7 +192,7 @@ void GroupMembersWidget::refreshMembers() {
fillChatMembers(chat);
} else if (const auto megagroup = peer()->asMegagroup()) {
auto &megagroupInfo = megagroup->mgInfo;
if (megagroupInfo->lastParticipants.empty() || megagroup->lastParticipantsCountOutdated()) {
if (megagroup->lastParticipantsRequestNeeded()) {
Auth().api().requestLastParticipants(megagroup);
}
fillMegagroupMembers(megagroup);