diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 9c6db61bac..d48addd0d4 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -686,6 +686,33 @@ void MessageLinksParser::apply( _list = std::move(parsed); } +bool FillSendMenu( + not_null menu, + Fn type, + Fn silent, + Fn schedule) { + if (!silent && !schedule) { + return false; + } + const auto now = type(); + if (now == SendMenuType::Disabled + || (!silent && now == SendMenuType::SilentOnly)) { + return false; + } + + if (silent && now != SendMenuType::Reminder) { + menu->addAction(tr::lng_send_silent_message(tr::now), silent); + } + if (schedule && now != SendMenuType::SilentOnly) { + menu->addAction( + (now == SendMenuType::Reminder + ? tr::lng_reminder_message(tr::now) + : tr::lng_schedule_message(tr::now)), + schedule); + } + return true; +} + void SetupSendMenuAndShortcuts( not_null button, Fn type, @@ -696,25 +723,12 @@ void SetupSendMenuAndShortcuts( } const auto menu = std::make_shared>(); const auto showMenu = [=] { - const auto now = type(); - if (now == SendMenuType::Disabled - || (!silent && now == SendMenuType::SilentOnly)) { - return false; - } - *menu = base::make_unique_q(button); - if (silent && now != SendMenuType::Reminder) { - (*menu)->addAction(tr::lng_send_silent_message(tr::now), silent); + const auto success = FillSendMenu(*menu, type, silent, schedule); + if (success) { + (*menu)->popup(QCursor::pos()); } - if (schedule && now != SendMenuType::SilentOnly) { - (*menu)->addAction( - (now == SendMenuType::Reminder - ? tr::lng_reminder_message(tr::now) - : tr::lng_schedule_message(tr::now)), - schedule); - } - (*menu)->popup(QCursor::pos()); - return true; + return success; }; base::install_event_filter(button, [=](not_null e) { if (e->type() == QEvent::ContextMenu && showMenu()) { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index b67bff6684..035d3709ea 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -26,6 +26,10 @@ namespace Window { class SessionController; } // namespace Window +namespace Ui { +class PopupMenu; +} // namespace Ui + QString PrepareMentionTag(not_null user); TextWithTags PrepareEditText(not_null item); @@ -106,6 +110,12 @@ enum class SendMenuType { Reminder, }; +bool FillSendMenu( + not_null menu, + Fn type, + Fn silent, + Fn schedule); + void SetupSendMenuAndShortcuts( not_null button, Fn type,