From 3bd6b2268f05416e2c59c0a2fe6a8167e8551dae Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 19 Mar 2021 19:10:44 +0400 Subject: [PATCH] Allow blocking channels in voice chats. --- Telegram/Resources/langs/lang.strings | 2 + Telegram/SourceFiles/apiwrap.cpp | 20 +++---- Telegram/SourceFiles/boxes/confirm_box.cpp | 2 +- .../boxes/peers/add_participants_box.cpp | 24 ++++---- .../boxes/peers/edit_participants_box.cpp | 59 +++++++++---------- .../boxes/peers/edit_participants_box.h | 8 +-- .../SourceFiles/calls/calls_group_members.cpp | 15 ++--- .../SourceFiles/calls/calls_group_panel.cpp | 44 ++++++++------ .../SourceFiles/calls/calls_group_panel.h | 4 +- Telegram/SourceFiles/data/data_channel.cpp | 27 ++++++--- Telegram/SourceFiles/data/data_channel.h | 8 ++- .../admin_log/history_admin_log_inner.cpp | 10 +--- Telegram/SourceFiles/history/history_item.cpp | 8 ++- .../profile/profile_block_group_members.cpp | 2 +- 14 files changed, 124 insertions(+), 109 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 88c448897..372528169 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1982,6 +1982,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_group_call_context_remove_hand" = "Cancel request to speak"; "lng_group_call_context_mute_for_me" = "Mute for me"; "lng_group_call_context_unmute_for_me" = "Unmute for me"; +"lng_group_call_context_remove" = "Remove"; +"lng_group_call_remove_channel" = "Remove {channel} from the voice chat?"; "lng_group_call_duration_days#one" = "{count} day"; "lng_group_call_duration_days#other" = "{count} days"; "lng_group_call_duration_hours#one" = "{count} hour"; diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index de5d1f8e1..7734a5353 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -1522,9 +1522,6 @@ void ApiWrap::applyLastParticipantsList( auto botStatus = channel->mgInfo->botStatus; const auto emptyAdminRights = MTP_chatAdminRights(MTP_flags(0)); - const auto emptyRestrictedRights = MTP_chatBannedRights( - MTP_flags(0), - MTP_int(0)); for (const auto &p : list) { const auto participantId = p.match([]( const MTPDchannelParticipantBanned &data) { @@ -1532,6 +1529,11 @@ void ApiWrap::applyLastParticipantsList( }, [](const auto &data) { return peerFromUser(data.vuser_id()); }); + if (!participantId) { + continue; + } + const auto participant = _session->data().peer(participantId); + const auto user = participant->asUser(); const auto adminCanEdit = (p.type() == mtpc_channelParticipantAdmin) ? p.c_channelParticipantAdmin().is_can_edit() : (p.type() == mtpc_channelParticipantCreator) @@ -1544,13 +1546,7 @@ void ApiWrap::applyLastParticipantsList( : emptyAdminRights; const auto restrictedRights = (p.type() == mtpc_channelParticipantBanned) ? p.c_channelParticipantBanned().vbanned_rights() - : emptyRestrictedRights; - if (!participantId) { - continue; - } - - const auto participant = _session->data().peer(participantId); - const auto user = participant->asUser(); + : ChannelData::EmptyRestrictedRights(participant); if (p.type() == mtpc_channelParticipantCreator) { Assert(user != nullptr); const auto &creator = p.c_channelParticipantCreator(); @@ -1730,7 +1726,7 @@ void ApiWrap::kickParticipant( const auto kick = KickRequest(channel, participant); if (_kickRequests.contains(kick)) return; - const auto rights = ChannelData::KickedRestrictedRights(); + const auto rights = ChannelData::KickedRestrictedRights(participant); const auto requestId = request(MTPchannels_EditBanned( channel->inputChannel, participant->input, @@ -1758,7 +1754,7 @@ void ApiWrap::unblockParticipant( const auto requestId = request(MTPchannels_EditBanned( channel->inputChannel, participant->input, - MTP_chatBannedRights(MTP_flags(0), MTP_int(0)) + ChannelData::EmptyRestrictedRights(participant) )).done([=](const MTPUpdates &result) { applyUpdates(result); diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index a0d08a23c..2c1b0625f 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -900,7 +900,7 @@ void DeleteMessagesBox::deleteAndClear() { _moderateInChannel->session().api().kickParticipant( _moderateInChannel, _moderateFrom, - MTP_chatBannedRights(MTP_flags(0), MTP_int(0))); + ChannelData::EmptyRestrictedRights(_moderateFrom)); } if (_reportSpam->checked()) { _moderateInChannel->session().api().request( diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index e6abb774e..acf78bdf9 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -421,6 +421,7 @@ void AddSpecialBoxController::rebuildChatRows(not_null chat) { auto count = delegate()->peerListFullRowsCount(); for (auto i = 0; i != count;) { auto row = delegate()->peerListRowAt(i); + Assert(row->peer()->isUser()); auto user = row->peer()->asUser(); if (participants.contains(user)) { ++i; @@ -492,11 +493,16 @@ void AddSpecialBoxController::loadMoreRows() { } void AddSpecialBoxController::rowClicked(not_null row) { - auto user = row->peer()->asUser(); + const auto participant = row->peer(); + const auto user = participant->asUser(); switch (_role) { - case Role::Admins: return showAdmin(user); - case Role::Restricted: return showRestricted(user); - case Role::Kicked: return kickUser(user); + case Role::Admins: + Assert(user != nullptr); + return showAdmin(user); + case Role::Restricted: + Assert(user != nullptr); + return showRestricted(user); + case Role::Kicked: return kickUser(participant); } Unexpected("Role in AddSpecialBoxController::rowClicked()"); } @@ -724,9 +730,7 @@ void AddSpecialBoxController::showRestricted( // Finally edit the restricted. const auto currentRights = restrictedRights ? *restrictedRights - : MTPChatBannedRights(MTP_chatBannedRights( - MTP_flags(0), - MTP_int(0))); + : ChannelData::EmptyRestrictedRights(user); auto box = Box( _peer, user, @@ -839,9 +843,7 @@ void AddSpecialBoxController::kickUser( const auto restrictedRights = _additional.restrictedRights(participant); const auto currentRights = restrictedRights ? *restrictedRights - : MTPChatBannedRights(MTP_chatBannedRights( - MTP_flags(0), - MTP_int(0))); + : ChannelData::EmptyRestrictedRights(participant); const auto done = crl::guard(this, [=]( const MTPChatBannedRights &newRights) { @@ -855,7 +857,7 @@ void AddSpecialBoxController::kickUser( participant, done, fail); - callback(currentRights, ChannelData::KickedRestrictedRights()); + callback(currentRights, ChannelData::KickedRestrictedRights(participant)); } bool AddSpecialBoxController::appendRow(not_null participant) { diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index f963b439f..e52864a1e 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -354,7 +354,7 @@ bool ParticipantsAdditionalData::canRestrictParticipant( } else if (const auto channel = _peer->asChannel()) { return channel->canBanMembers(); } - Unexpected("Peer in ParticipantsAdditionalData::canRestrictUser."); + Unexpected("Peer in ParticipantsAdditionalData::canRestrictParticipant."); } bool ParticipantsAdditionalData::canRemoveParticipant( @@ -978,8 +978,10 @@ void ParticipantsBoxController::addNewParticipants() { auto already = std::vector>(); already.reserve(count); for (auto i = 0; i != count; ++i) { - already.emplace_back( - delegate()->peerListRowAt(i)->peer()->asUser()); + const auto participant = delegate()->peerListRowAt(i)->peer(); + if (const auto user = participant->asUser()) { + already.emplace_back(user); + } } AddParticipantsBoxController::Start( _navigation, @@ -1188,6 +1190,7 @@ void ParticipantsBoxController::rebuildChatParticipants( auto count = delegate()->peerListFullRowsCount(); for (auto i = 0; i != count;) { auto row = delegate()->peerListRowAt(i); + Assert(row->peer()->isUser()); auto user = row->peer()->asUser(); if (participants.contains(user)) { ++i; @@ -1439,15 +1442,15 @@ void ParticipantsBoxController::rowClicked(not_null row) { void ParticipantsBoxController::rowActionClicked( not_null row) { - Expects(row->peer()->isUser()); - - const auto user = row->peer()->asUser(); + const auto participant = row->peer(); + const auto user = participant->asUser(); if (_role == Role::Members || _role == Role::Profile) { - kickMember(user); + kickParticipant(participant); } else if (_role == Role::Admins) { + Assert(user != nullptr); removeAdmin(user); } else { - removeKicked(row, user); + removeKicked(row, participant); } } @@ -1473,7 +1476,7 @@ base::unique_qptr ParticipantsBoxController::rowContextMenu( if (user && channel->canAddMembers()) { result->addAction( tr::lng_context_add_to_group(tr::now), - crl::guard(this, [=] { unkickMember(user); })); + crl::guard(this, [=] { unkickParticipant(user); })); } result->addAction( tr::lng_profile_delete_removed(tr::now), @@ -1510,7 +1513,7 @@ base::unique_qptr ParticipantsBoxController::rowContextMenu( (isGroup ? tr::lng_context_remove_from_group : tr::lng_profile_kick)(tr::now), - crl::guard(this, [=] { kickMember(user); })); + crl::guard(this, [=] { kickParticipant(user); })); } } return result; @@ -1596,9 +1599,7 @@ void ParticipantsBoxController::showRestricted(not_null user) { const auto restrictedRights = _additional.restrictedRights(user); const auto currentRights = restrictedRights ? *restrictedRights - : MTPChatBannedRights(MTP_chatBannedRights( - MTP_flags(0), - MTP_int(0))); + : ChannelData::EmptyRestrictedRights(user); const auto hasAdminRights = _additional.adminRights(user).has_value(); auto box = Box( _peer, @@ -1660,32 +1661,32 @@ void ParticipantsBoxController::editRestrictedDone( : MTP_peerChannel(MTP_int(participant->bareId()))), MTP_int(alreadyRestrictedBy ? alreadyRestrictedBy->bareId() - : user->session().userId()), + : participant->session().userId()), MTP_int(date), rights)); if (kicked) { if (_role == Role::Kicked) { - prependRow(user); + prependRow(participant); } else if (_role == Role::Admins || _role == Role::Restricted || _role == Role::Members) { - removeRow(user); + removeRow(participant); } } else { if (_role == Role::Restricted) { - prependRow(user); + prependRow(participant); } else if (_role == Role::Kicked || _role == Role::Admins || _role == Role::Members) { - removeRow(user); + removeRow(participant); } } } - recomputeTypeFor(user); + recomputeTypeFor(participant); delegate()->peerListRefreshRows(); } -void ParticipantsBoxController::kickMember(not_null participant) { +void ParticipantsBoxController::kickParticipant(not_null participant) { const auto user = participant->asUser(); const auto text = ((_peer->isChat() || _peer->isMegagroup()) ? tr::lng_profile_sure_kick @@ -1697,11 +1698,11 @@ void ParticipantsBoxController::kickMember(not_null participant) { Box( text, tr::lng_box_remove(tr::now), - crl::guard(this, [=] { kickMemberSure(participant); })), + crl::guard(this, [=] { kickParticipantSure(participant); })), Ui::LayerOption::KeepOther); } -void ParticipantsBoxController::unkickMember(not_null user) { +void ParticipantsBoxController::unkickParticipant(not_null user) { _editBox = nullptr; if (const auto row = delegate()->peerListFindRow(user->id)) { delegate()->peerListRemoveRow(row); @@ -1710,16 +1711,14 @@ void ParticipantsBoxController::unkickMember(not_null user) { _peer->session().api().addChatParticipants(_peer, { 1, user }); } -void ParticipantsBoxController::kickMemberSure( +void ParticipantsBoxController::kickParticipantSure( not_null participant) { _editBox = nullptr; const auto restrictedRights = _additional.restrictedRights(participant); const auto currentRights = restrictedRights ? *restrictedRights - : MTPChatBannedRights(MTP_chatBannedRights( - MTP_flags(0), - MTP_int(0))); + : ChannelData::EmptyRestrictedRights(participant); if (const auto row = delegate()->peerListFindRow(participant->id)) { delegate()->peerListRemoveRow(row); @@ -1810,16 +1809,16 @@ bool ParticipantsBoxController::appendRow(not_null participant) { return false; } -bool ParticipantsBoxController::prependRow(not_null user) { - if (const auto row = delegate()->peerListFindRow(user->id)) { - recomputeTypeFor(user); +bool ParticipantsBoxController::prependRow(not_null participant) { + if (const auto row = delegate()->peerListFindRow(participant->id)) { + recomputeTypeFor(participant); refreshCustomStatus(row); if (_role == Role::Admins) { // Perhaps we've added a new admin from search. delegate()->peerListPrependRowFromSearchResult(row); } return false; - } else if (auto row = createRow(user)) { + } else if (auto row = createRow(participant)) { delegate()->peerListPrependRow(std::move(row)); if (_role != Role::Kicked) { setDescriptionText(QString()); diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h index 1a1be5122..cb5550f47 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h @@ -232,13 +232,13 @@ private: not_null participant); void removeKickedWithRow(not_null participant); void removeKicked(not_null participant); - void kickMember(not_null participant); - void kickMemberSure(not_null participant); - void unkickMember(not_null user); + void kickParticipant(not_null participant); + void kickParticipantSure(not_null participant); + void unkickParticipant(not_null user); void removeAdmin(not_null user); void removeAdminSure(not_null user); bool appendRow(not_null participant); - bool prependRow(not_null user); + bool prependRow(not_null participant); bool removeRow(not_null participant); void refreshCustomStatus(not_null row) const; bool feedMegagroupLastParticipants(); diff --git a/Telegram/SourceFiles/calls/calls_group_members.cpp b/Telegram/SourceFiles/calls/calls_group_members.cpp index 397e4d792..08846dc0e 100644 --- a/Telegram/SourceFiles/calls/calls_group_members.cpp +++ b/Telegram/SourceFiles/calls/calls_group_members.cpp @@ -1570,7 +1570,7 @@ base::unique_qptr MembersController::createRowContextMenu( Window::SectionShow::Way::Forward); }); }; - const auto removeFromGroup = crl::guard(this, [=] { + const auto removeFromVoiceChat = crl::guard(this, [=] { _kickParticipantRequests.fire_copy(participantPeer); }); @@ -1607,9 +1607,7 @@ base::unique_qptr MembersController::createRowContextMenu( } const auto canKick = [&] { const auto user = participantPeer->asUser(); - if (!user) { - return false; - } else if (static_cast(row.get())->state() + if (static_cast(row.get())->state() == Row::State::Invited) { return false; } else if (const auto chat = _peer->asChat()) { @@ -1617,16 +1615,15 @@ base::unique_qptr MembersController::createRowContextMenu( || (user && chat->canBanMembers() && !chat->admins.contains(user)); - } else if (const auto group = _peer->asMegagroup()) { - return group->amCreator() - || (user && group->canRestrictUser(user)); + } else if (const auto channel = _peer->asChannel()) { + return channel->canRestrictParticipant(participantPeer); } return false; }(); if (canKick) { result->addAction( - tr::lng_context_remove_from_group(tr::now), - removeFromGroup); + tr::lng_group_call_context_remove(tr::now), + removeFromVoiceChat); } } if (result->empty()) { diff --git a/Telegram/SourceFiles/calls/calls_group_panel.cpp b/Telegram/SourceFiles/calls/calls_group_panel.cpp index b0a2ee7cf..06e104b2a 100644 --- a/Telegram/SourceFiles/calls/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_group_panel.cpp @@ -530,9 +530,7 @@ void Panel::initWithCall(GroupCall *call) { _members->kickParticipantRequests( ) | rpl::start_with_next([=](not_null participantPeer) { - if (const auto user = participantPeer->asUser()) { - kickMember(user); - } + kickParticipant(participantPeer); }, _callLifetime); const auto showBox = [=](object_ptr next) { @@ -955,15 +953,22 @@ void Panel::addMembers() { _layerBg->showBox(Box(std::move(controllers), initBox)); } -void Panel::kickMember(not_null user) { +void Panel::kickParticipant(not_null participantPeer) { _layerBg->showBox(Box([=](not_null box) { box->addRow( object_ptr( box.get(), - tr::lng_profile_sure_kick( - tr::now, - lt_user, - user->firstName), + (!participantPeer->isUser() + ? tr::lng_group_call_remove_channel( + tr::now, + lt_channel, + participantPeer->name) + : (_peer->isBroadcast() + ? tr::lng_profile_sure_kick_channel + : tr::lng_profile_sure_kick)( + tr::now, + lt_user, + participantPeer->asUser()->firstName)), st::groupCallBoxLabel), style::margins( st::boxRowPadding.left(), @@ -972,26 +977,29 @@ void Panel::kickMember(not_null user) { st::boxPadding.bottom())); box->addButton(tr::lng_box_remove(), [=] { box->closeBox(); - kickMemberSure(user); + kickParticipantSure(participantPeer); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); })); } -void Panel::kickMemberSure(not_null user) { +void Panel::kickParticipantSure(not_null participantPeer) { if (const auto chat = _peer->asChat()) { - chat->session().api().kickParticipant(chat, user); + chat->session().api().kickParticipant(chat, participantPeer); } else if (const auto channel = _peer->asChannel()) { - const auto currentRestrictedRights = [&]() -> MTPChatBannedRights { - const auto it = channel->mgInfo->lastRestricted.find(user); - return (it != channel->mgInfo->lastRestricted.cend()) - ? it->second.rights - : MTP_chatBannedRights(MTP_flags(0), MTP_int(0)); + const auto currentRestrictedRights = [&] { + const auto user = participantPeer->asUser(); + if (!channel->mgInfo || !user) { + return ChannelData::EmptyRestrictedRights(participantPeer); + } + const auto i = channel->mgInfo->lastRestricted.find(user); + return (i != channel->mgInfo->lastRestricted.cend()) + ? i->second.rights + : ChannelData::EmptyRestrictedRights(participantPeer); }(); - channel->session().api().kickParticipant( channel, - user, + participantPeer, currentRestrictedRights); } } diff --git a/Telegram/SourceFiles/calls/calls_group_panel.h b/Telegram/SourceFiles/calls/calls_group_panel.h index de972d32a..bc966b605 100644 --- a/Telegram/SourceFiles/calls/calls_group_panel.h +++ b/Telegram/SourceFiles/calls/calls_group_panel.h @@ -89,8 +89,8 @@ private: void showMainMenu(); void chooseJoinAs(); void addMembers(); - void kickMember(not_null user); - void kickMemberSure(not_null user); + void kickParticipant(not_null participantPeer); + void kickParticipantSure(not_null participantPeer); [[nodiscard]] QRect computeTitleRect() const; void refreshTitle(); void refreshTitleGeometry(); diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 70f90494f..35b1ba5ab 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -188,7 +188,13 @@ void ChannelData::setKickedCount(int newKickedCount) { } } -MTPChatBannedRights ChannelData::KickedRestrictedRights() { +MTPChatBannedRights ChannelData::EmptyRestrictedRights( + not_null participant) { + return MTP_chatBannedRights(MTP_flags(0), MTP_int(0)); +} + +MTPChatBannedRights ChannelData::KickedRestrictedRights( + not_null participant) { using Flag = MTPDchatBannedRights::Flag; const auto flags = Flag::f_view_messages | Flag::f_send_messages @@ -199,7 +205,7 @@ MTPChatBannedRights ChannelData::KickedRestrictedRights() { | Flag::f_send_games | Flag::f_send_inline; return MTP_chatBannedRights( - MTP_flags(flags), + MTP_flags(participant->isUser() ? flags : Flag::f_view_messages), MTP_int(std::numeric_limits::max())); } @@ -494,7 +500,7 @@ bool ChannelData::canDelete() const { } bool ChannelData::canEditLastAdmin(not_null user) const { - // Duplicated in ParticipantsBoxController::canEditAdmin :( + // Duplicated in ParticipantsAdditionalData::canEditAdmin :( if (mgInfo) { auto i = mgInfo->lastAdmins.find(user); if (i != mgInfo->lastAdmins.cend()) { @@ -506,7 +512,7 @@ bool ChannelData::canEditLastAdmin(not_null user) const { } bool ChannelData::canEditAdmin(not_null user) const { - // Duplicated in ParticipantsBoxController::canEditAdmin :( + // Duplicated in ParticipantsAdditionalData::canEditAdmin :( if (user->isSelf()) { return false; } else if (amCreator()) { @@ -517,14 +523,17 @@ bool ChannelData::canEditAdmin(not_null user) const { return adminRights() & AdminRight::f_add_admins; } -bool ChannelData::canRestrictUser(not_null user) const { - // Duplicated in ParticipantsBoxController::canRestrictUser :( - if (user->isSelf()) { +bool ChannelData::canRestrictParticipant( + not_null participant) const { + // Duplicated in ParticipantsAdditionalData::canRestrictParticipant :( + if (participant->isSelf()) { return false; } else if (amCreator()) { return true; - } else if (!canEditLastAdmin(user)) { - return false; + } else if (const auto user = participant->asUser()) { + if (!canEditLastAdmin(user)) { + return false; + } } return adminRights() & AdminRight::f_ban_users; } diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h index 7b9631120..e00d22a87 100644 --- a/Telegram/SourceFiles/data/data_channel.h +++ b/Telegram/SourceFiles/data/data_channel.h @@ -209,7 +209,10 @@ public: return flags() & MTPDchannel::Flag::f_fake; } - static MTPChatBannedRights KickedRestrictedRights(); + static MTPChatBannedRights EmptyRestrictedRights( + not_null participant); + static MTPChatBannedRights KickedRestrictedRights( + not_null participant); static constexpr auto kRestrictUntilForever = TimeId(INT_MAX); [[nodiscard]] static bool IsRestrictedForever(TimeId until) { return !until || (until == kRestrictUntilForever); @@ -310,7 +313,8 @@ public: [[nodiscard]] bool canEditStickers() const; [[nodiscard]] bool canDelete() const; [[nodiscard]] bool canEditAdmin(not_null user) const; - [[nodiscard]] bool canRestrictUser(not_null user) const; + [[nodiscard]] bool canRestrictParticipant( + not_null participant) const; void setInviteLink(const QString &newInviteLink); [[nodiscard]] QString inviteLink() const { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index baede6839..603452b4e 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -1310,7 +1310,7 @@ void InnerWidget::suggestRestrictUser(not_null user) { Ui::LayerOption::KeepOther); }; if (base::contains(_admins, user)) { - editRestrictions(true, MTP_chatBannedRights(MTP_flags(0), MTP_int(0))); + editRestrictions(true, ChannelData::EmptyRestrictedRights(user)); } else { _api.request(MTPchannels_GetParticipant( _channel->inputChannel, @@ -1327,15 +1327,11 @@ void InnerWidget::suggestRestrictUser(not_null user) { } else { auto hasAdminRights = (type == mtpc_channelParticipantAdmin) || (type == mtpc_channelParticipantCreator); - auto bannedRights = MTP_chatBannedRights( - MTP_flags(0), - MTP_int(0)); + auto bannedRights = ChannelData::EmptyRestrictedRights(user); editRestrictions(hasAdminRights, bannedRights); } }).fail([=](const MTP::Error &error) { - auto bannedRights = MTP_chatBannedRights( - MTP_flags(0), - MTP_int(0)); + auto bannedRights = ChannelData::EmptyRestrictedRights(user); editRestrictions(false, bannedRights); }).send(); } diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 184618cf4..7deeb32d3 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -701,9 +701,11 @@ bool HistoryItem::suggestReport() const { } bool HistoryItem::suggestBanReport() const { - auto channel = history()->peer->asChannel(); - auto fromUser = from()->asUser(); - if (!channel || !fromUser || !channel->canRestrictUser(fromUser)) { + const auto channel = history()->peer->asChannel(); + const auto fromUser = from()->asUser(); + if (!channel + || !fromUser + || !channel->canRestrictParticipant(fromUser)) { return false; } return !isPost() && !out(); diff --git a/Telegram/SourceFiles/profile/profile_block_group_members.cpp b/Telegram/SourceFiles/profile/profile_block_group_members.cpp index f72c5e964..936cfa7ba 100644 --- a/Telegram/SourceFiles/profile/profile_block_group_members.cpp +++ b/Telegram/SourceFiles/profile/profile_block_group_members.cpp @@ -84,7 +84,7 @@ void GroupMembersWidget::removePeer(PeerData *selectedPeer) { return it->second.rights; } } - return MTP_chatBannedRights(MTP_flags(0), MTP_int(0)); + return ChannelData::EmptyRestrictedRights(user); }(); const auto peer = this->peer();