From 61d0d240aa861532211e0a7cfc792d85a7df1493 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 16 Mar 2021 18:13:51 +0400 Subject: [PATCH] Add 'rejoin as' and 'change title' toast notifications. --- Telegram/Resources/langs/lang.strings | 2 + .../SourceFiles/calls/calls_group_call.cpp | 7 +-- Telegram/SourceFiles/calls/calls_group_call.h | 11 ++++- .../SourceFiles/calls/calls_group_panel.cpp | 43 +++++++++++++++++++ .../SourceFiles/calls/calls_group_panel.h | 2 + .../SourceFiles/ui/toasts/common_toasts.cpp | 9 +++- .../SourceFiles/ui/toasts/common_toasts.h | 1 + 7 files changed, 66 insertions(+), 9 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index c4f39a261..dd3177654 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2013,6 +2013,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_group_call_is_recorded" = "Voice chat is being recorded."; "lng_group_call_can_speak_here" = "You can now speak."; "lng_group_call_can_speak" = "You can now speak in {chat}."; +"lng_group_call_title_changed" = "Voice chat title changed to {title}"; +"lng_group_call_join_as_changed" = "Members of this voice chat will now see you as {name}"; "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 92274c78e..eac5f9ee2 100644 --- a/Telegram/SourceFiles/calls/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/calls_group_call.cpp @@ -930,12 +930,12 @@ void GroupCall::changeTitle(const QString &title) { return; } - real->setTitle(title); _api.request(MTPphone_EditGroupCallTitle( inputCall(), MTP_string(title) )).done([=](const MTPUpdates &result) { _peer->session().api().applyUpdates(result); + _titleChanged.fire({}); }).fail([=](const MTP::Error &error) { }).send(); } @@ -1374,11 +1374,6 @@ void GroupCall::sendSelfUpdate(SendUpdateType type) { }).send(); } -auto GroupCall::instanceStateValue() const -> rpl::producer { - using namespace rpl::mappers; - return _instanceState.value(); -} - void GroupCall::setCurrentAudioDevice(bool input, const QString &deviceId) { if (input) { _mediaDevices->switchToAudioInput(deviceId); diff --git a/Telegram/SourceFiles/calls/calls_group_call.h b/Telegram/SourceFiles/calls/calls_group_call.h index fe54a15a9..2f72d4f54 100644 --- a/Telegram/SourceFiles/calls/calls_group_call.h +++ b/Telegram/SourceFiles/calls/calls_group_call.h @@ -158,7 +158,12 @@ public: TransitionToRtc, Connected, }; - [[nodiscard]] rpl::producer instanceStateValue() const; + [[nodiscard]] InstanceState instanceState() const { + return _instanceState.current(); + } + [[nodiscard]] rpl::producer instanceStateValue() const { + return _instanceState.value(); + } [[nodiscard]] rpl::producer levelUpdates() const { return _levelUpdates.events(); @@ -169,6 +174,9 @@ public: [[nodiscard]] rpl::producer<> allowedToSpeakNotifications() const { return _allowedToSpeakNotifications.events(); } + [[nodiscard]] rpl::producer<> titleChanged() const { + return _titleChanged.events(); + } static constexpr auto kSpeakLevelThreshold = 0.2; void setCurrentAudioDevice(bool input, const QString &deviceId); @@ -304,6 +312,7 @@ private: base::flat_map _lastSpoke; rpl::event_stream _rejoinEvents; rpl::event_stream<> _allowedToSpeakNotifications; + rpl::event_stream<> _titleChanged; base::Timer _lastSpokeCheckTimer; base::Timer _checkJoinedTimer; diff --git a/Telegram/SourceFiles/calls/calls_group_panel.cpp b/Telegram/SourceFiles/calls/calls_group_panel.cpp index 6344ba2bd..6eac870e4 100644 --- a/Telegram/SourceFiles/calls/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_group_panel.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/layers/generic_box.h" #include "ui/text/text_utilities.h" #include "ui/toast/toast.h" +#include "ui/toasts/common_toasts.h" #include "ui/special_buttons.h" #include "info/profile/info_profile_values.h" // Info::Profile::Value. #include "core/application.h" @@ -284,6 +285,8 @@ Panel::Panel(not_null call) initControls(); initLayout(); showAndActivate(); + setupJoinAsChangedToasts(); + setupTitleChangedToasts(); call->allowedToSpeakNotifications( ) | rpl::start_with_next([=] { @@ -597,6 +600,46 @@ void Panel::initWithCall(GroupCall *call) { }, _callLifetime); } +void Panel::setupJoinAsChangedToasts() { + _call->rejoinEvents( + ) | rpl::filter([](RejoinEvent event) { + return (event.wasJoinAs != event.nowJoinAs); + }) | rpl::map([=] { + return _call->stateValue() | rpl::filter([](State state) { + return (state == State::Joined); + }) | rpl::take(1); + }) | rpl::flatten_latest() | rpl::start_with_next([=] { + Ui::ShowMultilineToast({ + .parentOverride = widget(), + .text = tr::lng_group_call_join_as_changed( + tr::now, + lt_name, + Ui::Text::Bold(_call->joinAs()->name), + Ui::Text::WithEntities), + }); + }, widget()->lifetime()); +} + +void Panel::setupTitleChangedToasts() { + _call->titleChanged( + ) | rpl::filter([=] { + return _peer->groupCall() && _peer->groupCall()->id() == _call->id(); + }) | rpl::map([=] { + return _peer->groupCall()->title().isEmpty() + ? _peer->name + : _peer->groupCall()->title(); + }) | rpl::start_with_next([=](const QString &title) { + Ui::ShowMultilineToast({ + .parentOverride = widget(), + .text = tr::lng_group_call_title_changed( + tr::now, + lt_title, + Ui::Text::Bold(title), + Ui::Text::WithEntities), + }); + }, widget()->lifetime()); +} + void Panel::subscribeToChanges(not_null real) { _titleText = real->titleValue(); diff --git a/Telegram/SourceFiles/calls/calls_group_panel.h b/Telegram/SourceFiles/calls/calls_group_panel.h index fc848d425..de972d32a 100644 --- a/Telegram/SourceFiles/calls/calls_group_panel.h +++ b/Telegram/SourceFiles/calls/calls_group_panel.h @@ -76,6 +76,8 @@ private: void initWithCall(GroupCall *call); void initLayout(); void initGeometry(); + void setupJoinAsChangedToasts(); + void setupTitleChangedToasts(); bool handleClose(); diff --git a/Telegram/SourceFiles/ui/toasts/common_toasts.cpp b/Telegram/SourceFiles/ui/toasts/common_toasts.cpp index 87de13737..b03d794f5 100644 --- a/Telegram/SourceFiles/ui/toasts/common_toasts.cpp +++ b/Telegram/SourceFiles/ui/toasts/common_toasts.cpp @@ -13,14 +13,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { void ShowMultilineToast(MultilineToastArgs &&args) { - Ui::Toast::Show(Ui::Toast::Config{ + auto config = Ui::Toast::Config{ .text = std::move(args.text), .st = &st::defaultMultilineToast, .durationMs = (args.duration ? args.duration : Ui::Toast::kDefaultDuration), .multiline = true, - }); + }; + if (args.parentOverride) { + Ui::Toast::Show(args.parentOverride, std::move(config)); + } else { + Ui::Toast::Show(std::move(config)); + } } } // namespace Ui diff --git a/Telegram/SourceFiles/ui/toasts/common_toasts.h b/Telegram/SourceFiles/ui/toasts/common_toasts.h index 820e486ff..ebf1efe1d 100644 --- a/Telegram/SourceFiles/ui/toasts/common_toasts.h +++ b/Telegram/SourceFiles/ui/toasts/common_toasts.h @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { struct MultilineToastArgs { + QWidget *parentOverride = nullptr; TextWithEntities text; crl::time duration = 0; };