diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 2e40febf9c..b7023d2684 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2269,6 +2269,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_community_ban_done" = "{user} was banned from the community."; "lng_community_profile_view" = "View Community"; "lng_community_hidden_chat_about" = "Only invited members and community admins will see this chat."; +"lng_community_admin_title" = "You are a community admin"; +"lng_community_admin_about" = "You can now edit {community} info and use other admin tools."; +"lng_community_admin_continue" = "Continue"; +"lng_community_admin_decline" = "No, thanks"; +"lng_community_admin_dismiss_title" = "Dismiss yourself as community admin"; +"lng_community_admin_dismiss_text" = "You'll lose access to community admin tools, but keep your group admin rights."; "lng_manage_monoforum" = "Direct Messages"; "lng_manage_monoforum_off" = "Off"; diff --git a/Telegram/SourceFiles/boxes/peers/community_box.cpp b/Telegram/SourceFiles/boxes/peers/community_box.cpp index bac6c9f6de..7e34d1c357 100644 --- a/Telegram/SourceFiles/boxes/peers/community_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/community_box.cpp @@ -18,12 +18,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_community.h" #include "data/data_peer_values.h" #include "data/data_session.h" +#include "data/data_user.h" #include "info/profile/info_profile_values.h" #include "lang/lang_hardcoded.h" #include "lang/lang_keys.h" #include "main/main_session.h" #include "main/session/session_show.h" #include "settings/settings_common.h" +#include "ui/boxes/confirm_box.h" #include "ui/layers/generic_box.h" #include "ui/text/text_utilities.h" #include "ui/vertical_list.h" @@ -444,6 +446,49 @@ void BanFromCommunityWithWarning( }); } +void ShowCommunityAdminBox( + not_null navigation, + not_null community) { + navigation->uiShow()->showBox(Box([=](not_null box) { + box->setTitle(tr::lng_community_admin_title()); + box->addRow(object_ptr( + box, + tr::lng_community_admin_about( + lt_community, + rpl::single(tr::bold(community->name())), + tr::marked), + st::boxLabel)); + box->addButton(tr::lng_community_admin_continue(), [=] { + box->closeBox(); + }); + box->addButton(tr::lng_community_admin_decline(), [=] { + const auto sure = crl::guard(box, [=](Fn &&close) { + close(); + const auto session = &community->session(); + const auto show = box->uiShow(); + session->api().request(MTPchannels_EditAdmin( + MTP_flags(MTPchannels_EditAdmin::Flags(0)), + community->inputChannel(), + session->user()->inputUser(), + AdminRightsToMTP(ChatAdminRightsInfo()), + MTPstring() + )).done([=](const MTPUpdates &result) { + session->api().applyUpdates(result); + }).fail([=](const MTP::Error &error) { + show->showToast(error.type()); + }).send(); + box->closeBox(); + }); + box->uiShow()->showBox(Ui::MakeConfirmBox({ + .text = tr::lng_community_admin_dismiss_text(), + .confirmed = sure, + .confirmText = tr::lng_box_ok(), + .title = tr::lng_community_admin_dismiss_title(), + })); + }); + })); +} + void ShowChooseChatToAddBox( not_null navigation, not_null community) { diff --git a/Telegram/SourceFiles/boxes/peers/community_box.h b/Telegram/SourceFiles/boxes/peers/community_box.h index a68d41f700..c1e5bdec1f 100644 --- a/Telegram/SourceFiles/boxes/peers/community_box.h +++ b/Telegram/SourceFiles/boxes/peers/community_box.h @@ -30,3 +30,7 @@ void BanFromCommunityWithWarning( std::shared_ptr show, not_null community, not_null participant); + +void ShowCommunityAdminBox( + not_null navigation, + not_null community); diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 247d26d0bb..2324896cad 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1199,12 +1199,21 @@ not_null Session::processChat(const MTPChat &data) { channel->setDefaultRestrictions(ChatRestrictions()); } if (!minimal) { + const auto wasLoaded = result->isLoaded(); + const auto hadRights = channel->hasAdminRights(); if (const auto rights = data.vadmin_rights()) { channel->setAdminRights(ChatAdminRightsInfo(*rights).flags); } else if (channel->hasAdminRights()) { channel->setAdminRights(ChatAdminRights()); } channel->date = data.vdate().v; + if (wasLoaded + && !hadRights + && channel->hasAdminRights() + && !data.is_creator()) { + _communityAdminPromotions.fire( + not_null(channel)); + } } channel->setName(qs(data.vtitle()), QString()); channel->setPhoto(data.vphoto()); @@ -5218,6 +5227,11 @@ rpl::producer> Session::channelDifferenceTooLong() const return _channelDifferenceTooLong.events(); } +auto Session::communityAdminPromotions() const +-> rpl::producer> { + return _communityAdminPromotions.events(); +} + void Session::registerItemView(not_null view) { _views[view->data()].push_back(view); } diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 57acd38dd5..8210fd81da 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -902,6 +902,9 @@ public: void channelDifferenceTooLong(not_null channel); [[nodiscard]] rpl::producer> channelDifferenceTooLong() const; + [[nodiscard]] auto communityAdminPromotions() const + -> rpl::producer>; + void registerItemView(not_null view); void unregisterItemView(not_null view); @@ -1309,6 +1312,7 @@ private: rpl::event_stream> _webpageUpdates; rpl::event_stream> _pollUpdates; rpl::event_stream> _channelDifferenceTooLong; + rpl::event_stream> _communityAdminPromotions; rpl::event_stream> _photoLoadProgress; rpl::event_stream> _documentLoadProgress; base::flat_set> _suggestToGigagroup; diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 160ba43ee0..7d9e7bcaf8 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1593,6 +1593,15 @@ SessionController::SessionController( } }, _lifetime); + if (_isPrimary) { + session->data().communityAdminPromotions( + ) | rpl::on_next([=](not_null community) { + crl::on_main(this, [=] { + ShowCommunityAdminBox(this, community); + }); + }, _lifetime); + } + _authedName = session->user()->name(); session->changes().peerUpdates( Data::PeerUpdate::Flag::FullInfo