Fix owner badges in groups.

This commit is contained in:
John Preston 2019-07-24 08:37:10 +02:00
parent 020e62fb7a
commit db2018c765
4 changed files with 36 additions and 9 deletions

View File

@ -1623,7 +1623,7 @@ void ApiWrap::requestAdmins(not_null<ChannelData*> channel) {
)).done([this, channel](const MTPchannels_ChannelParticipants &result) {
_adminsRequests.remove(channel);
result.match([&](const MTPDchannels_channelParticipants &data) {
Data::ApplyChannelAdmins(channel, data);
Data::ApplyMegagroupAdmins(channel, data);
}, [&](const MTPDchannels_channelParticipantsNotModified &) {
LOG(("API Error: channels.channelParticipantsNotModified received!"));
});
@ -3515,7 +3515,12 @@ void ApiWrap::refreshChannelAdmins(
p.match([&](const MTPDchannelParticipantAdmin &data) {
changes.add(userId, qs(data.vrank().value_or_empty()));
}, [&](const MTPDchannelParticipantCreator &data) {
changes.add(userId, qs(data.vrank().value_or_empty()));
const auto rank = qs(data.vrank().value_or_empty());
if (const auto info = channel->mgInfo.get()) {
info->creator = channel->owner().userLoaded(userId);
info->creatorRank = rank;
}
changes.add(userId, rank);
}, [&](const auto &data) {
changes.remove(userId);
});

View File

@ -412,11 +412,21 @@ not_null<Ui::InputField*> EditAdminBox::addRankInput() {
st::rightsHeaderLabel),
st::rightsHeaderMargin);
const auto isOwner = [&] {
if (user()->isSelf() && amCreator()) {
return true;
} else if (const auto chat = peer()->asChat()) {
return chat->creator == peerToUser(user()->id);
} else if (const auto channel = peer()->asChannel()) {
return channel->mgInfo && channel->mgInfo->creator == user();
}
Unexpected("Peer type in EditAdminBox::addRankInput.");
}();
const auto result = addControl(
object_ptr<Ui::InputField>(
this,
st::customBadgeField,
(amCreator() ? tr::lng_owner_badge : tr::lng_admin_badge)(),
(isOwner ? tr::lng_owner_badge : tr::lng_admin_badge)(),
_oldRank),
st::rightsAboutMargin);
result->setMaxLength(kAdminRoleLimit);
@ -431,7 +441,7 @@ not_null<Ui::InputField*> EditAdminBox::addRankInput() {
this,
tr::lng_rights_edit_admin_rank_about(
lt_title,
(amCreator() ? tr::lng_owner_badge : tr::lng_admin_badge)()),
(isOwner ? tr::lng_owner_badge : tr::lng_admin_badge)()),
st::boxDividerLabel),
st::rightsAboutMargin);

View File

@ -514,9 +514,6 @@ void ChannelData::setAdminRights(const MTPChatAdminRights &rights) {
} else {
mgInfo->lastAdmins.remove(self);
}
auto amAdmin = hasAdminRights() || amCreator();
Data::ChannelAdminChanges(this).add(session().userId(), QString());
}
Notify::peerUpdatedDelayed(this, UpdateFlag::RightsChanged | UpdateFlag::AdminsChanged | UpdateFlag::BannedUsersChanged);
}
@ -741,12 +738,27 @@ void ApplyChannelUpdate(
update.vnotify_settings());
}
void ApplyChannelAdmins(
void ApplyMegagroupAdmins(
not_null<ChannelData*> channel,
const MTPDchannels_channelParticipants &data) {
Expects(channel->isMegagroup());
channel->owner().processUsers(data.vusers());
const auto &list = data.vparticipants().v;
const auto i = ranges::find(
list,
mtpc_channelParticipantCreator,
&MTPChannelParticipant::type);
if (i != list.end()) {
const auto &data = i->c_channelParticipantCreator();
const auto userId = data.vuser_id().v;
channel->mgInfo->creator = channel->owner().userLoaded(userId);
channel->mgInfo->creatorRank = qs(data.vrank().value_or_empty());
} else {
channel->mgInfo->creator = nullptr;
channel->mgInfo->creatorRank = QString();
}
auto adding = base::flat_map<UserId, QString>();
auto admins = ranges::make_iterator_range(

View File

@ -456,7 +456,7 @@ void ApplyChannelUpdate(
not_null<ChannelData*> channel,
const MTPDchannelFull &update);
void ApplyChannelAdmins(
void ApplyMegagroupAdmins(
not_null<ChannelData*> channel,
const MTPDchannels_channelParticipants &data);