From 7d519990b26c8188da13c54e7e20c7d5c3b3fb06 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 23 Dec 2019 18:14:12 +0300 Subject: [PATCH] Added ability to customize shortcuts for silent or scheduled messages. --- .../SourceFiles/boxes/create_poll_box.cpp | 2 +- Telegram/SourceFiles/boxes/send_files_box.cpp | 2 +- Telegram/SourceFiles/boxes/share_box.cpp | 2 +- .../chat_helpers/message_field.cpp | 29 ++++++++++++++++++- .../SourceFiles/chat_helpers/message_field.h | 2 +- Telegram/SourceFiles/core/shortcuts.cpp | 5 ++++ Telegram/SourceFiles/core/shortcuts.h | 3 ++ .../SourceFiles/history/history_widget.cpp | 2 +- .../view/history_view_schedule_box.cpp | 2 +- 9 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 431a9b329..7f91ed3fe 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -942,7 +942,7 @@ object_ptr CreatePollBox::setupContent() { tr::lng_polls_create_button(), [=] { send({}); }); if (_sendType == Api::SendType::Normal) { - SetupSendMenu( + SetupSendMenuAndShortcuts( submit.data(), [=] { return SendMenuType::Scheduled; }, sendSilent, diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index da9aea32a..9ccd4abd7 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -1847,7 +1847,7 @@ void SendFilesBox::setupShadows( void SendFilesBox::prepare() { _send = addButton(tr::lng_send_button(), [=] { send({}); }); if (_sendType == Api::SendType::Normal) { - SetupSendMenu( + SetupSendMenuAndShortcuts( _send, [=] { return _sendMenuType; }, [=] { sendSilent(); }, diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 2ff338970..1608c8557 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -426,7 +426,7 @@ void ShareBox::createButtons() { const auto send = addButton(tr::lng_share_confirm(), [=] { submit({}); }); - SetupSendMenu( + SetupSendMenuAndShortcuts( send, [=] { return sendMenuType(); }, [=] { submitSilent(); }, diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 87012d32f..98d943b13 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qthelp_url.h" #include "base/event_filter.h" #include "boxes/abstract_box.h" +#include "core/shortcuts.h" #include "ui/wrap/vertical_layout.h" #include "ui/widgets/popup_menu.h" #include "ui/ui_utility.h" @@ -666,7 +667,7 @@ void MessageLinksParser::apply( _list = std::move(parsed); } -void SetupSendMenu( +void SetupSendMenuAndShortcuts( not_null button, Fn type, Fn silent, @@ -702,4 +703,30 @@ void SetupSendMenu( } return base::EventFilterResult::Continue; }); + + Shortcuts::Requests( + ) | rpl::start_with_next([=](not_null request) { + using Command = Shortcuts::Command; + + const auto now = type(); + if (now == SendMenuType::Disabled + || (!silent && now == SendMenuType::SilentOnly)) { + return; + } + silent + && (now != SendMenuType::Reminder) + && request->check(Command::SendSilentMessage) + && request->handle([=] { + silent(); + return true; + }); + + schedule + && (now != SendMenuType::SilentOnly) + && request->check(Command::ScheduleMessage) + && request->handle([=] { + schedule(); + return true; + }); + }, button->lifetime()); } diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index f6bfd80b9..8f95a9323 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -103,7 +103,7 @@ enum class SendMenuType { Reminder, }; -void SetupSendMenu( +void SetupSendMenuAndShortcuts( not_null button, Fn type, Fn silent, diff --git a/Telegram/SourceFiles/core/shortcuts.cpp b/Telegram/SourceFiles/core/shortcuts.cpp index 507efbd4d..fdf5fa46f 100644 --- a/Telegram/SourceFiles/core/shortcuts.cpp +++ b/Telegram/SourceFiles/core/shortcuts.cpp @@ -76,6 +76,11 @@ const auto CommandByName = base::flat_map{ { qsl("self_chat") , Command::ChatSelf }, { qsl("show_archive") , Command::ShowArchive }, + + // Shortcuts that have no default values. + { qsl("message_silently") , Command::SendSilentMessage }, + { qsl("message_scheduled"), Command::ScheduleMessage }, + // }; const auto CommandNames = base::flat_map{ diff --git a/Telegram/SourceFiles/core/shortcuts.h b/Telegram/SourceFiles/core/shortcuts.h index b744a4ab0..569cc2dfd 100644 --- a/Telegram/SourceFiles/core/shortcuts.h +++ b/Telegram/SourceFiles/core/shortcuts.h @@ -37,6 +37,9 @@ enum class Command { ShowArchive, + SendSilentMessage, + ScheduleMessage, + SupportReloadTemplates, SupportToggleMuted, SupportScrollToCurrent, diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 80b599f93..4a8b31b07 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -314,7 +314,7 @@ HistoryWidget::HistoryWidget( _fieldBarCancel->addClickHandler([=] { cancelFieldAreaState(); }); _send->addClickHandler([=] { sendButtonClicked(); }); - SetupSendMenu( + SetupSendMenuAndShortcuts( _send, [=] { return sendButtonMenuType(); }, [=] { sendSilent(); }, diff --git a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp index 405b9f52f..36fb6d0b6 100644 --- a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp +++ b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp @@ -688,7 +688,7 @@ void ScheduleBox( const auto submit = box->addButton(tr::lng_settings_save(), [=] { save(false); }); - SetupSendMenu( + SetupSendMenuAndShortcuts( submit.data(), [=] { return SendMenuType::SilentOnly; }, [=] { save(true); },