From c972485555ae6d84a01e41fa0f4811e9d14898a4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 4 Apr 2025 23:53:54 +0500 Subject: [PATCH] Allow revoking confcall link. --- Telegram/Resources/langs/lang.strings | 3 + Telegram/SourceFiles/calls/calls.style | 19 +++++ .../calls/group/calls_group_common.cpp | 75 ++++++++++++++++++- .../calls/group/calls_group_common.h | 4 + Telegram/SourceFiles/ui/menu_icons.style | 1 + 5 files changed, 99 insertions(+), 3 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index bfaa87a884..700c14af2d 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4930,6 +4930,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_confcall_join_button" = "Join Group Call"; "lng_confcall_create_link" = "Create Call Link"; "lng_confcall_create_link_description" = "You can create a link that will allow your friends on Telegram to join the call."; +"lng_confcall_link_revoke" = "Revoke link"; +"lng_confcall_link_revoked_title" = "Link Revoked"; +"lng_confcall_link_revoked_text" = "A new link has been generated."; "lng_confcall_link_title" = "Call Link"; "lng_confcall_link_about" = "Anyone on Telegram can join your call by following the link below."; "lng_confcall_link_or" = "or"; diff --git a/Telegram/SourceFiles/calls/calls.style b/Telegram/SourceFiles/calls/calls.style index 4f4d90b336..09aad20fce 100644 --- a/Telegram/SourceFiles/calls/calls.style +++ b/Telegram/SourceFiles/calls/calls.style @@ -578,6 +578,13 @@ groupCallPopupMenu: PopupMenu(defaultPopupMenu) { menu: groupCallMenu; animation: groupCallPanelAnimation; } +groupCallPopupMenuWithIcons: PopupMenu(popupMenuWithIcons) { + shadow: groupCallMenuShadow; + menu: Menu(groupCallMenu, menuWithIcons) { + arrow: icon {{ "menu/submenu_arrow", groupCallMemberNotJoinedStatus }}; + } + animation: groupCallPanelAnimation; +} groupCallPopupMenuWithVolume: PopupMenu(groupCallPopupMenu) { scrollPadding: margins(0px, 3px, 0px, 8px); menu: Menu(groupCallMenu) { @@ -1617,3 +1624,15 @@ groupCallInviteLink: SettingsButton(defaultSettingsButton) { } groupCallInviteLinkIcon: icon {{ "info/edit/group_manage_links", mediaviewTextLinkFg }}; groupCallInviteLinkIconPosition: point(23px, 2px); + +confcallLinkMenu: IconButton(boxTitleClose) { + icon: icon {{ "title_menu_dots", boxTitleCloseFg }}; + iconOver: icon {{ "title_menu_dots", boxTitleCloseFgOver }}; +} +groupCallLinkMenu: IconButton(confcallLinkMenu) { + icon: icon {{ "title_menu_dots", groupCallMemberInactiveIcon }}; + iconOver: icon {{ "title_menu_dots", groupCallMemberInactiveIcon }}; + ripple: RippleAnimation(defaultRippleAnimation) { + color: groupCallMembersBgOver; + } +} diff --git a/Telegram/SourceFiles/calls/group/calls_group_common.cpp b/Telegram/SourceFiles/calls/group/calls_group_common.cpp index 9eb576b52e..b2e368513d 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_common.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_common.cpp @@ -21,15 +21,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/boost_box.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" +#include "ui/widgets/popup_menu.h" #include "ui/layers/generic_box.h" #include "ui/text/text_utilities.h" +#include "ui/toast/toast.h" #include "ui/painter.h" #include "ui/vertical_list.h" #include "lang/lang_keys.h" #include "main/main_session.h" #include "window/window_session_controller.h" +#include "styles/style_info.h" #include "styles/style_layers.h" #include "styles/style_media_view.h" +#include "styles/style_menu_icons.h" #include "styles/style_calls.h" #include "styles/style_chat.h" @@ -235,9 +239,12 @@ void ConferenceCallJoinConfirm( ConferenceCallLinkStyleOverrides DarkConferenceCallLinkStyle() { return { .box = &st::groupCallLinkBox, + .menuToggle = &st::groupCallLinkMenu, + .menu = &st::groupCallPopupMenuWithIcons, .close = &st::storiesStealthBoxClose, .centerLabel = &st::groupCallLinkCenteredText, .linkPreview = &st::groupCallLinkPreview, + .contextRevoke = &st::mediaMenuIconRemove, .shareBox = std::make_shared( DarkShareBoxStyle()), }; @@ -251,6 +258,12 @@ void ShowConferenceCallLinkBox( const auto st = args.st; const auto initial = args.initial; show->showBox(Box([=](not_null box) { + struct State { + base::unique_qptr menu; + bool resetting = false; + }; + const auto state = box->lifetime().make_state(); + box->setStyle(st.box ? *st.box : initial @@ -258,9 +271,65 @@ void ShowConferenceCallLinkBox( : st::confcallLinkBox); box->setWidth(st::boxWideWidth); box->setNoContentMargin(true); - box->addTopButton(st.close ? *st.close : st::boxTitleClose, [=] { - box->closeBox(); - }); + const auto close = box->addTopButton( + st.close ? *st.close : st::boxTitleClose, + [=] { box->closeBox(); }); + + if (!args.initial && call->canManage()) { + const auto toggle = Ui::CreateChild( + close->parentWidget(), + st.menuToggle ? *st.menuToggle : st::confcallLinkMenu); + const auto handler = [=] { + if (state->resetting) { + return; + } + state->resetting = true; + using Flag = MTPphone_ToggleGroupCallSettings::Flag; + call->session().api().request( + MTPphone_ToggleGroupCallSettings( + MTP_flags(Flag::f_reset_invite_hash), + call->input(), + MTPbool()) // join_muted + ).done([=] { + auto copy = args; + const auto weak = Ui::MakeWeak(box); + copy.finished = [=](QString link) { + if (const auto strong = weak.data()) { + strong->closeBox(); + } + show->showToast({ + .title = tr::lng_confcall_link_revoked_title( + tr::now), + .text = tr::lng_confcall_link_revoked_text( + tr::now), + }); + }; + ExportConferenceCallLink( + show, + call, + std::move(copy)); + }).send(); + }; + toggle->setClickedCallback([=] { + state->menu = base::make_unique_q( + toggle, + st.menu ? *st.menu : st::popupMenuWithIcons); + state->menu->addAction( + tr::lng_confcall_link_revoke(tr::now), + handler, + (st.contextRevoke + ? st.contextRevoke + : &st::menuIconRemove)); + state->menu->popup(QCursor::pos()); + }); + + close->geometryValue( + ) | rpl::start_with_next([=](QRect geometry) { + toggle->moveToLeft( + geometry.x() - toggle->width(), + geometry.y()); + }, close->lifetime()); + } box->addRow( Info::BotStarRef::CreateLinkHeaderIcon(box, &call->session()), diff --git a/Telegram/SourceFiles/calls/group/calls_group_common.h b/Telegram/SourceFiles/calls/group/calls_group_common.h index 267df9b324..e82a12f611 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_common.h +++ b/Telegram/SourceFiles/calls/group/calls_group_common.h @@ -18,6 +18,7 @@ struct Box; struct FlatLabel; struct IconButton; struct InputField; +struct PopupMenu; } // namespace style namespace Data { @@ -164,9 +165,12 @@ void ConferenceCallJoinConfirm( struct ConferenceCallLinkStyleOverrides { const style::Box *box = nullptr; + const style::IconButton *menuToggle = nullptr; + const style::PopupMenu *menu = nullptr; const style::IconButton *close = nullptr; const style::FlatLabel *centerLabel = nullptr; const style::InputField *linkPreview = nullptr; + const style::icon *contextRevoke = nullptr; std::shared_ptr shareBox; }; [[nodiscard]] ConferenceCallLinkStyleOverrides DarkConferenceCallLinkStyle(); diff --git a/Telegram/SourceFiles/ui/menu_icons.style b/Telegram/SourceFiles/ui/menu_icons.style index c7b94f0b06..4c49be52ff 100644 --- a/Telegram/SourceFiles/ui/menu_icons.style +++ b/Telegram/SourceFiles/ui/menu_icons.style @@ -212,6 +212,7 @@ mediaMenuIconArchiveStory: icon {{ "menu/stories_archive", mediaviewMenuFg }}; mediaMenuIconStealthLocked: icon {{ "menu/stealth_locked", mediaviewMenuFg }}; mediaMenuIconStealth: icon {{ "menu/stealth", mediaviewMenuFg }}; mediaMenuIconStats: icon {{ "menu/stats", mediaviewMenuFg }}; +mediaMenuIconRemove: icon {{ "menu/remove", mediaviewMenuFg }}; mediaMenuIconInfo: icon {{ "menu/info", mediaviewMenuFg }}; mediaMenuIconBlock: icon {{ "menu/block", mediaviewMenuFg }};