diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index d08b0e515..665938363 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -1623,7 +1623,7 @@ void ApiWrap::requestAdmins(not_null 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); }); diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 8194ee4fe..a256b06ff 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -412,11 +412,21 @@ not_null 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( 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 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); diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 971f75ec3..daa5f3e78 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -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 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(); auto admins = ranges::make_iterator_range( diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h index 8aff904ef..df8adf4e7 100644 --- a/Telegram/SourceFiles/data/data_channel.h +++ b/Telegram/SourceFiles/data/data_channel.h @@ -456,7 +456,7 @@ void ApplyChannelUpdate( not_null channel, const MTPDchannelFull &update); -void ApplyChannelAdmins( +void ApplyMegagroupAdmins( not_null channel, const MTPDchannels_channelParticipants &data);