From 96bc4858c1099f0f45efc69b1ef91f97fffacc9b Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 7 Apr 2021 11:21:59 +0400 Subject: [PATCH] Add schedule voice chat link in ConfirmBox. --- Telegram/Resources/langs/lang.strings | 10 ++-- .../calls/calls_choose_join_as.cpp | 47 ++++++++++++++----- .../SourceFiles/calls/calls_group_call.cpp | 11 ++--- .../SourceFiles/calls/calls_group_menu.cpp | 19 ++++---- Telegram/SourceFiles/calls/calls_group_menu.h | 23 +++++++-- .../SourceFiles/calls/calls_group_panel.cpp | 23 +++++---- .../calls/calls_group_settings.cpp | 3 +- 7 files changed, 87 insertions(+), 49 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 825d07dac..b02dac3d2 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1995,8 +1995,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_group_call_leave_title" = "Leave voice chat"; "lng_group_call_leave_sure" = "Are you sure you want to leave this voice chat?"; "lng_group_call_close" = "Close"; -"lng_group_call_close_sure" = "Voice chat is scheduled. You can cancel it or just close this panel."; -"lng_group_call_also_cancel" = "Cancel voice chat"; +"lng_group_call_close_sure" = "Voice chat is scheduled. You can abort it or just close this panel."; +"lng_group_call_also_cancel" = "Abort voice chat"; "lng_group_call_leave_to_other_sure" = "Do you want to leave your active voice chat and join a voice chat in this group?"; "lng_group_call_create_sure" = "Do you really want to start a voice chat in this group?"; "lng_group_call_create_sure_channel" = "Are you sure you want to start a voice chat in this channel as your personal account?"; @@ -2027,7 +2027,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_group_call_copy_speaker_link" = "Copy Speaker Link"; "lng_group_call_copy_listener_link" = "Copy Listener Link"; "lng_group_call_end" = "End Voice Chat"; -"lng_group_call_cancel" = "Cancel Voice Chat"; +"lng_group_call_cancel" = "Abort Voice Chat"; "lng_group_call_join" = "Join"; "lng_group_call_join_confirm" = "Do you want to join the voice chat {chat}?"; "lng_group_call_invite_done_user" = "You invited {user} to the voice chat."; @@ -2062,8 +2062,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_group_call_join_as_header" = "Join Voice Chat as..."; "lng_group_call_display_as_header" = "Display me as..."; "lng_group_call_join_as_about" = "Choose whether you want to be displayed as your personal account or as your channel."; -"lng_group_call_or_schedule" = "Or you can {link}."; -"lng_group_call_schedule" = "Schedule Voice Chat"; +"lng_group_call_or_schedule" = "You can also {link}."; +"lng_group_call_schedule" = "schedule a voice chat"; "lng_group_call_schedule_title" = "Schedule Voice Chat"; "lng_group_call_schedule_notified_group" = "The members of the group will be notified that the voice chat will start in {duration}."; "lng_group_call_schedule_notified_channel" = "The subscribers of the channel will be notified that the voice chat will start in {duration}."; diff --git a/Telegram/SourceFiles/calls/calls_choose_join_as.cpp b/Telegram/SourceFiles/calls/calls_choose_join_as.cpp index 9f967d563..40318e692 100644 --- a/Telegram/SourceFiles/calls/calls_choose_join_as.cpp +++ b/Telegram/SourceFiles/calls/calls_choose_join_as.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "calls/calls_choose_join_as.h" #include "calls/calls_group_common.h" +#include "calls/calls_group_menu.h" #include "data/data_peer.h" #include "data/data_user.h" #include "data/data_channel.h" @@ -21,10 +22,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/choose_date_time.h" #include "ui/text/text_utilities.h" #include "boxes/peer_list_box.h" -#include "boxes/confirm_box.h" #include "base/unixtime.h" #include "base/timer_rpl.h" #include "styles/style_boxes.h" +#include "styles/style_layers.h" #include "styles/style_calls.h" namespace Calls::Group { @@ -230,10 +231,8 @@ void ChooseJoinAsBox( label->setClickHandlerFilter([=](const auto&...) { auto withJoinAs = info; withJoinAs.joinAs = controller->selected(); - box->getDelegate()->show(Box( - ScheduleGroupCallBox, - withJoinAs, - done)); + box->getDelegate()->show( + Box(ScheduleGroupCallBox, withJoinAs, done)); return false; }); } @@ -378,7 +377,7 @@ void ChooseJoinAsProcess::start( && (peer->groupCall() != nullptr); if (!changingJoinAsFrom && (onlyByMe || byAlreadyUsed)) { - const auto confirmation = CreateOrJoinConfirmation( + auto confirmation = CreateOrJoinConfirmation( peer, context, byAlreadyUsed); @@ -386,12 +385,36 @@ void ChooseJoinAsProcess::start( finish(info); return; } - auto box = Box<::ConfirmBox>( - confirmation, - (peer->groupCall() - ? tr::lng_group_call_join(tr::now) - : tr::lng_create_group_create(tr::now)), - crl::guard(&_request->guard, [=] { finish(info); })); + const auto creating = !peer->groupCall(); + if (creating) { + confirmation + .append("\n\n") + .append(tr::lng_group_call_or_schedule( + tr::now, + lt_link, + Ui::Text::Link(tr::lng_group_call_schedule(tr::now)), + Ui::Text::WithEntities)); + } + const auto guard = base::make_weak(&_request->guard); + const auto safeFinish = crl::guard(guard, [=] { finish(info); }); + const auto filter = [=](const auto &...) { + if (guard) { + _request->showBox(Box( + ScheduleGroupCallBox, + info, + crl::guard(guard, finish))); + } + return false; + }; + auto box = ConfirmBox({ + .text = confirmation, + .button = (creating + ? tr::lng_create_group_create() + : tr::lng_group_call_join()), + .callback = crl::guard(guard, [=] { finish(info); }), + .st = &st::boxLabel, + .filter = filter, + }); box->boxClosing( ) | rpl::start_with_next([=] { _request = nullptr; diff --git a/Telegram/SourceFiles/calls/calls_group_call.cpp b/Telegram/SourceFiles/calls/calls_group_call.cpp index ef7346514..f31018aba 100644 --- a/Telegram/SourceFiles/calls/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/calls_group_call.cpp @@ -395,12 +395,7 @@ void GroupCall::join(const MTPInputGroupCall &inputCall) { _id = data.vid().v; _accessHash = data.vaccess_hash().v; }); - if (_scheduleDate) { - setState(State::Waiting); - return; - } - - setState(State::Joining); + setState(_scheduleDate ? State::Waiting : State::Joining); if (const auto chat = _peer->asChat()) { chat->setGroupCall(inputCall); } else if (const auto group = _peer->asChannel()) { @@ -408,6 +403,10 @@ void GroupCall::join(const MTPInputGroupCall &inputCall) { } else { Unexpected("Peer type in GroupCall::join."); } + + if (_scheduleDate) { + return; + } rejoin(); using Update = Data::GroupCall::ParticipantUpdate; diff --git a/Telegram/SourceFiles/calls/calls_group_menu.cpp b/Telegram/SourceFiles/calls/calls_group_menu.cpp index 0879bcfc5..3887503bc 100644 --- a/Telegram/SourceFiles/calls/calls_group_menu.cpp +++ b/Telegram/SourceFiles/calls/calls_group_menu.cpp @@ -568,19 +568,20 @@ void LeaveBox( box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); } -void ConfirmBox( +void ConfirmBoxBuilder( not_null box, - const TextWithEntities &text, - rpl::producer button, - Fn callback) { - box->addRow( + ConfirmBoxArgs &&args) { + const auto label = box->addRow( object_ptr( box.get(), - rpl::single(text), - st::groupCallBoxLabel), + rpl::single(args.text), + args.st ? *args.st : st::groupCallBoxLabel), st::boxPadding); - if (callback) { - box->addButton(std::move(button), callback); + if (args.callback) { + box->addButton(std::move(args.button), std::move(args.callback)); + } + if (args.filter) { + label->setClickHandlerFilter(std::move(args.filter)); } box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); } diff --git a/Telegram/SourceFiles/calls/calls_group_menu.h b/Telegram/SourceFiles/calls/calls_group_menu.h index 7eeed21fc..484974493 100644 --- a/Telegram/SourceFiles/calls/calls_group_menu.h +++ b/Telegram/SourceFiles/calls/calls_group_menu.h @@ -9,6 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/object_ptr.h" #include "base/unique_qptr.h" +#include "ui/layers/generic_box.h" + +namespace style { +struct FlatLabel; +} // namespace style namespace Ui { class DropdownMenu; @@ -38,11 +43,19 @@ void LeaveBox( bool discardChecked, BoxContext context); -void ConfirmBox( - not_null box, - const TextWithEntities &text, - rpl::producer button, - Fn callback); +struct ConfirmBoxArgs { + TextWithEntities text; + rpl::producer button; + Fn callback; + const style::FlatLabel *st = nullptr; + Fn filter; +}; + +void ConfirmBoxBuilder(not_null box, ConfirmBoxArgs &&args); + +inline auto ConfirmBox(ConfirmBoxArgs &&args) { + return Box(ConfirmBoxBuilder, std::move(args)); +} void FillMenu( not_null menu, diff --git a/Telegram/SourceFiles/calls/calls_group_panel.cpp b/Telegram/SourceFiles/calls/calls_group_panel.cpp index 8ada11c79..932de26a1 100644 --- a/Telegram/SourceFiles/calls/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_group_panel.cpp @@ -556,11 +556,11 @@ void Panel::startScheduledNow() { } _call->startScheduledNow(); }; - auto owned = Box( - ConfirmBox, - TextWithEntities{ tr::lng_group_call_start_now_sure(tr::now) }, - tr::lng_group_call_start_now(), - done); + auto owned = ConfirmBox({ + .text = { tr::lng_group_call_start_now_sure(tr::now) }, + .button = tr::lng_group_call_start_now(), + .callback = done, + }); *box = owned.data(); _layerBg->showBox(std::move(owned)); } @@ -1153,11 +1153,14 @@ void Panel::addMembers() { } finish(); }; - auto box = Box( - ConfirmBox, - TextWithEntities{ text }, - tr::lng_participant_invite(), - [=] { inviteWithAdd(users, nonMembers, finishWithConfirm); }); + const auto done = [=] { + inviteWithAdd(users, nonMembers, finishWithConfirm); + }; + auto box = ConfirmBox({ + .text = { text }, + .button = tr::lng_participant_invite(), + .callback = done, + }); *shared = box.data(); _layerBg->showBox(std::move(box)); }; diff --git a/Telegram/SourceFiles/calls/calls_group_settings.cpp b/Telegram/SourceFiles/calls/calls_group_settings.cpp index 4a21d3027..79e0bfdc1 100644 --- a/Telegram/SourceFiles/calls/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/calls_group_settings.cpp @@ -149,8 +149,7 @@ object_ptr ShareInviteLinkBox( } text.append(error.first); if (const auto weak = *box) { - weak->getDelegate()->show( - Box(ConfirmBox, text, nullptr, nullptr)); + weak->getDelegate()->show(ConfirmBox({ .text = text })); } return; }