From 069a2814fc11055d428358c206f59efd434a4511 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 28 Feb 2022 19:53:49 +0300 Subject: [PATCH] Added ability to revoke stream key from settings of group call. --- Telegram/Resources/langs/lang.strings | 1 + .../calls/group/calls_group_settings.cpp | 77 ++++++++++++++++++- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 60eaa4c13..b6d37467c 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2401,6 +2401,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_group_call_rtmp_key_warning" = "**Never share your Stream Key with anyone or show it on stream!**"; "lng_group_call_rtmp_info" = "To stream video with another app, enter these Server URL and Stream Key in your streaming app.\n\nOnce you start broadcasting in your streaming app, tap Start Streaming below"; "lng_group_call_rtmp_start" = "Start Streaming"; +"lng_group_call_rtmp_revoke" = "Revoke Stream Key"; "lng_group_call_rtmp_revoke_sure" = "Are you sure you want to revoke your Server URL and Stream Key?"; "lng_no_mic_permission" = "Telegram needs access to your microphone so that you can make calls and record voice messages."; diff --git a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp index 6d9adb393..2931371fd 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/input_fields.h" +#include "ui/widgets/dropdown_menu.h" #include "ui/wrap/slide_wrap.h" #include "ui/text/text_utilities.h" #include "ui/toasts/common_toasts.h" @@ -628,6 +629,76 @@ void SettingsBox( )->addClickHandler(std::move(shareLink)); } if (rtmp) { + struct State { + base::unique_qptr menu; + mtpRequestId requestId; + rpl::event_stream data; + }; + const auto top = box->addTopButton(st::groupCallMenuToggle); + const auto state = top->lifetime().make_state(); + const auto revoke = [=] { + if (state->requestId) { + return; + } + const auto session = &peer->session(); + state->requestId = session->api().request( + MTPphone_GetGroupCallStreamRtmpUrl( + peer->input, + MTP_bool(true) + )).done([=](const MTPphone_GroupCallStreamRtmpUrl &result) { + auto data = result.match([&]( + const MTPDphone_groupCallStreamRtmpUrl &data) { + return StartRtmpProcess::Data{ + .url = qs(data.vurl()), + .key = qs(data.vkey()), + }; + }); + state->data.fire(std::move(data)); + }).fail([=] { + state->requestId = 0; + }).send(); + }; + top->setClickedCallback([=] { + state->menu = base::make_unique_q( + box, + st::groupCallDropdownMenu); + state->menu->addAction( + tr::lng_group_call_rtmp_revoke(tr::now), + revoke); + state->menu->moveToRight( + st::groupCallRtmpTopBarMenuPosition.x(), + st::groupCallRtmpTopBarMenuPosition.y()); + state->menu->showAnimated( + Ui::PanelAnimation::Origin::TopRight); + const auto raw = state->menu.get(); + raw->setHiddenCallback([=] { + raw->deleteLater(); + if (state->menu == raw) { + state->menu = nullptr; + if (top) { + top->setForceRippled(false); + } + } + }); + raw->setShowStartCallback([=] { + if (state->menu == raw) { + if (top) { + top->setForceRippled(true); + } + } + }); + raw->setHideStartCallback([=] { + if (state->menu == raw) { + if (top) { + top->setForceRippled(false); + } + } + }); + top->installEventFilter(state->menu); + return true; + }); + + StartRtmpProcess::FillRtmpRows( box->verticalLayout(), false, @@ -639,14 +710,12 @@ void SettingsBox( box->getDelegate()->outerContainer(), text); }, - rpl::single({ - call->rtmpUrl(), - call->rtmpKey() - }), + state->data.events(), &st::groupCallBoxLabel, &st::groupCallSettingsRtmpShowButton, &st::groupCallSubsectionTitle, &st::groupCallAttentionBoxButton); + state->data.fire({ call->rtmpUrl(), call->rtmpKey() }); } if (peer->canManageGroupCall()) {