From d5216a30c7cb77e25c284a203ae0d0226c425ed0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 30 Nov 2020 10:52:53 +0300 Subject: [PATCH] Forbid anonymous admins joining group calls. --- Telegram/Resources/langs/lang.strings | 3 ++ .../SourceFiles/calls/calls_group_call.cpp | 29 +++++++++++++++++-- .../SourceFiles/history/history_widget.cpp | 10 ++++--- .../view/history_view_top_bar_widget.cpp | 7 ++++- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index f66ac56788..0b92d24c4d 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1477,6 +1477,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_game_tag" = "Game"; "lng_context_view_profile" = "View profile"; +"lng_context_send_message" = "Send message"; "lng_context_view_group" = "View group info"; "lng_context_view_channel" = "View channel info"; //"lng_context_view_feed_info" = "View feed info"; @@ -1843,6 +1844,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_group_call_no_members" = "No members"; "lng_group_call_members#one" = "{count} member"; "lng_group_call_members#other" = "{count} members"; +"lng_group_call_no_anonymous" = "Anonymous admins can't join voice chats :("; +"lng_group_call_context_mute" = "Mute"; "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/calls_group_call.cpp b/Telegram/SourceFiles/calls/calls_group_call.cpp index 114b4f5b2c..09ed5804ea 100644 --- a/Telegram/SourceFiles/calls/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/calls_group_call.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "lang/lang_keys.h" #include "boxes/confirm_box.h" +#include "ui/toasts/common_toasts.h" #include "base/unixtime.h" #include "core/application.h" #include "core/core_settings.h" @@ -112,16 +113,22 @@ void GroupCall::setState(State state) { } void GroupCall::start() { - const auto randomId = rand_value(); _createRequestId = _api.request(MTPphone_CreateGroupCall( _channel->inputChannel, - MTP_int(randomId) + MTP_int(rand_value()) )).done([=](const MTPUpdates &result) { _acceptFields = true; _channel->session().api().applyUpdates(result); _acceptFields = false; }).fail([=](const RPCError &error) { - int a = error.code(); + LOG(("Call Error: Could not create, error: %1" + ).arg(error.type())); + hangup(); + if (error.type() == u"GROUP_CALL_ANONYMOUS_FORBIDDEN"_q) { + Ui::ShowMultilineToast({ + .text = tr::lng_group_call_no_anonymous(tr::now), + }); + } }).send(); } @@ -206,6 +213,11 @@ void GroupCall::rejoin() { LOG(("Call Error: Could not join, error: %1" ).arg(error.type())); hangup(); + if (error.type() == u"GROUP_CALL_ANONYMOUS_FORBIDDEN"_q) { + Ui::ShowMultilineToast({ + .text = tr::lng_group_call_no_anonymous(tr::now), + }); + } }).send(); }); }); @@ -401,10 +413,14 @@ void GroupCall::handleUpdate(const MTPDupdateGroupCallParticipants &data) { } if (data.is_left() && data.vsource().v == _mySsrc) { // I was removed from the call, rejoin. + LOG(("Call Info: Rejoin after got 'left' with my source.")); setState(State::Joining); rejoin(); } else if (!data.is_left() && data.vsource().v != _mySsrc) { // I joined from another device, hangup. + LOG(("Call Info: Hangup after '!left' with source %1, my %2." + ).arg(data.vsource().v + ).arg(_mySsrc)); _mySsrc = 0; hangup(); } @@ -550,11 +566,14 @@ void GroupCall::checkJoined() { MTP_int(_mySsrc) )).done([=](const MTPBool &result) { if (!mtpIsTrue(result)) { + LOG(("Call Info: Rejoin after FALSE in checkGroupCall.")); rejoin(); } else if (state() == State::Connecting) { _checkJoinedTimer.callOnce(kCheckJoinedTimeout); } }).fail([=](const RPCError &error) { + LOG(("Call Info: Rejoin after error '%1' in checkGroupCall." + ).arg(error.type())); rejoin(); }).send(); } @@ -585,6 +604,8 @@ void GroupCall::sendMutedUpdate() { }).fail([=](const RPCError &error) { _updateMuteRequestId = 0; if (error.type() == u"GROUP_CALL_FORBIDDEN"_q) { + LOG(("Call Info: Rejoin after error '%1' in editGroupCallMember." + ).arg(error.type())); rejoin(); } }).send(); @@ -615,6 +636,8 @@ void GroupCall::toggleMute(not_null user, bool mute) { _channel->session().api().applyUpdates(result); }).fail([=](const RPCError &error) { if (error.type() == u"GROUP_CALL_FORBIDDEN"_q) { + LOG(("Call Info: Rejoin after error '%1' in editGroupCallMember." + ).arg(error.type())); rejoin(); } }).send(); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index d470a5041a..f5ec69fa70 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -5413,12 +5413,14 @@ void HistoryWidget::setupGroupCallTracker() { const auto channel = _history->peer->asChannel(); if (!channel) { return; - } - const auto call = channel->call(); - if (!call) { + } else if (channel->amAnonymous()) { + Ui::ShowMultilineToast({ + .text = tr::lng_group_call_no_anonymous(tr::now), + }); return; + } else if (const auto call = channel->call()) { + Core::App().calls().joinGroupCall(channel, call->input()); } - Core::App().calls().joinGroupCall(channel, call->input()); }, _groupCallBar->lifetime()); _groupCallBarHeight = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 214950959f..d57c4903b3 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/dropdown_menu.h" #include "ui/effects/radial_animation.h" +#include "ui/toasts/common_toasts.h" #include "ui/special_buttons.h" #include "ui/unread_badge.h" #include "ui/ui_utility.h" @@ -212,7 +213,11 @@ void TopBarWidget::onCall() { if (const auto user = peer->asUser()) { Core::App().calls().startOutgoingCall(user, false); } else if (const auto megagroup = peer->asMegagroup()) { - if (const auto call = megagroup->call()) { + if (megagroup->amAnonymous()) { + Ui::ShowMultilineToast({ + .text = tr::lng_group_call_no_anonymous(tr::now), + }); + } else if (const auto call = megagroup->call()) { Core::App().calls().joinGroupCall(megagroup, call->input()); } else { Core::App().calls().startGroupCall(megagroup);