From bc96bdf7a9ac07e528fdb5b80e4012f8f30ef0fc Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 28 Oct 2022 17:21:11 +0400 Subject: [PATCH] Add video chat management menu items to forum. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/dialogs/dialogs.style | 2 +- Telegram/SourceFiles/dialogs/dialogs_row.cpp | 7 ++- .../view/history_view_top_bar_widget.cpp | 30 +--------- .../SourceFiles/window/window_peer_menu.cpp | 57 +++++++++++++++++++ .../SourceFiles/window/window_peer_menu.h | 4 ++ 6 files changed, 71 insertions(+), 30 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index d972b1b73..77130446c 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2811,6 +2811,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_menu_start_group_call" = "Start video chat"; "lng_menu_start_group_call_scheduled" = "Schedule video chat"; "lng_menu_start_group_call_with" = "Stream with..."; +"lng_menu_start_group_call_join" = "Join video chat"; "lng_menu_start_group_call_channel" = "Start live stream"; "lng_menu_start_group_call_scheduled_channel" = "Schedule live stream"; "lng_menu_start_group_call_with_channel" = "Stream with..."; diff --git a/Telegram/SourceFiles/dialogs/dialogs.style b/Telegram/SourceFiles/dialogs/dialogs.style index b5f503ef4..5a2c8d47c 100644 --- a/Telegram/SourceFiles/dialogs/dialogs.style +++ b/Telegram/SourceFiles/dialogs/dialogs.style @@ -78,7 +78,7 @@ dialogsOnlineBadgeSkip: point(0px, 2px); dialogsOnlineBadgeDuration: 150; dialogsCallBadgeSize: 16px; -dialogsCallBadgeSkip: point(-1px, 1px); +dialogsCallBadgeSkip: point(-3px, -3px); dialogsSpeakingStrokeNumerator: 16px; dialogsSpeakingDenominator: 8.; diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.cpp b/Telegram/SourceFiles/dialogs/dialogs_row.cpp index b09221466..c61ac650b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_row.cpp @@ -293,7 +293,12 @@ void Row::paintUserpic( } ensureCornerBadgeUserpic(); const auto ratio = style::DevicePixelRatio(); - const auto frameSide = context.st->photoSize * style::DevicePixelRatio(); + const auto added = std::max({ + -st::dialogsCallBadgeSkip.x(), + -st::dialogsCallBadgeSkip.y(), + 0 }); + const auto frameSide = (context.st->photoSize + added) + * style::DevicePixelRatio(); const auto frameSize = QSize(frameSide, frameSide); if (_cornerBadgeUserpic->frame.size() != frameSize) { _cornerBadgeUserpic->frame = QImage( 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 a2bf10117..c8bd3ee3c 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -340,34 +340,8 @@ void TopBarWidget::showGroupCallMenu(not_null peer) { if (!created) { return; } - const auto controller = _controller; - const auto callback = [=](Calls::StartGroupCallArgs &&args) { - controller->startOrJoinGroupCall(peer, std::move(args)); - }; - const auto rtmpCallback = [=] { - Core::App().calls().showStartWithRtmp( - std::make_shared(controller), - peer); - }; - const auto livestream = !peer->isMegagroup() && peer->isChannel(); - _menu->addAction( - (livestream - ? tr::lng_menu_start_group_call_channel - : tr::lng_menu_start_group_call)(tr::now), - [=] { callback({}); }, - &st::menuIconStartStream); - _menu->addAction( - (livestream - ? tr::lng_menu_start_group_call_scheduled_channel - : tr::lng_menu_start_group_call_scheduled)(tr::now), - [=] { callback({ .scheduleNeeded = true }); }, - &st::menuIconReschedule); - _menu->addAction( - (livestream - ? tr::lng_menu_start_group_call_with_channel - : tr::lng_menu_start_group_call_with)(tr::now), - rtmpCallback, - &st::menuIconStartStreamWith); + const auto addAction = Ui::Menu::CreateAddActionCallback(_menu); + Window::FillVideoChatMenu(_controller, _activeChat, addAction); _menu->setForcedOrigin(Ui::PanelAnimation::Origin::TopRight); _menu->popup(mapToGlobal(QPoint( _groupCall->x() + _groupCall->width() + st::topBarMenuGroupCallSkip, diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 3515d7d44..6e6597ad4 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peers/add_participants_box.h" #include "boxes/peers/edit_forum_topic_box.h" #include "boxes/peers/edit_contact_box.h" +#include "calls/calls_instance.h" #include "ui/boxes/report_box.h" #include "ui/toast/toast.h" #include "ui/text/format_values.h" @@ -1021,6 +1022,9 @@ void Filler::fillChatsListActions() { return; } addViewAsMessages(); + if (FillVideoChatMenu(_controller, _request, _addAction)) { + _addAction(PeerMenuCallback::Args{ .isSeparator = true }); + } addInfo(); addNewMembers(); const auto &all = _peer->forum()->topicsList()->indexed()->all(); @@ -1829,4 +1833,57 @@ void FillDialogsEntryMenu( Filler(controller, request, callback).fill(); } +bool FillVideoChatMenu( + not_null controller, + Dialogs::EntryState request, + const PeerMenuCallback &addAction) { + const auto peer = request.key.peer(); + if (!peer || peer->isUser()) { + return false; + } + + const auto callback = [=](Calls::StartGroupCallArgs &&args) { + controller->startOrJoinGroupCall(peer, std::move(args)); + }; + const auto rtmpCallback = [=] { + Core::App().calls().showStartWithRtmp( + std::make_shared(controller), + peer); + }; + const auto livestream = !peer->isMegagroup() && peer->isChannel(); + const auto has = (peer->groupCall() != nullptr); + const auto manager = peer->canManageGroupCall(); + const auto creator = peer->isChat() + ? peer->asChat()->amCreator() + : peer->asChannel()->amCreator(); + if (has) { + addAction( + tr::lng_menu_start_group_call_join(tr::now), + [=] { callback({}); }, + &st::menuIconStartStream); + } else if (manager) { + addAction( + (livestream + ? tr::lng_menu_start_group_call_channel + : tr::lng_menu_start_group_call)(tr::now), + [=] { callback({}); }, + &st::menuIconStartStream); + } + if (!has && creator) { + addAction( + (livestream + ? tr::lng_menu_start_group_call_scheduled_channel + : tr::lng_menu_start_group_call_scheduled)(tr::now), + [=] { callback({ .scheduleNeeded = true }); }, + &st::menuIconReschedule); + addAction( + (livestream + ? tr::lng_menu_start_group_call_with_channel + : tr::lng_menu_start_group_call_with)(tr::now), + rtmpCallback, + &st::menuIconStartStreamWith); + } + return has || manager; +} + } // namespace Window diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index b3257d62b..e423665e9 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -47,6 +47,10 @@ void FillDialogsEntryMenu( not_null controller, Dialogs::EntryState request, const PeerMenuCallback &addAction); +bool FillVideoChatMenu( + not_null controller, + Dialogs::EntryState request, + const PeerMenuCallback &addAction); void MenuAddMarkAsReadAllChatsAction( not_null controller,