From 87addd41b10480b1b39df5572583c7222b81b047 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 28 Aug 2019 19:46:47 +0300 Subject: [PATCH] Add new phrases for reminders. --- Telegram/Resources/langs/lang.strings | 3 ++ .../SourceFiles/boxes/create_poll_box.cpp | 7 +++-- Telegram/SourceFiles/boxes/send_files_box.cpp | 8 +++-- Telegram/SourceFiles/boxes/send_files_box.h | 6 +++- Telegram/SourceFiles/boxes/share_box.cpp | 11 +++++-- Telegram/SourceFiles/boxes/share_box.h | 4 +++ .../chat_helpers/message_field.cpp | 30 ++++++++++++------- .../SourceFiles/chat_helpers/message_field.h | 13 ++++++-- .../SourceFiles/history/history_widget.cpp | 27 +++++++++++++---- Telegram/SourceFiles/history/history_widget.h | 2 ++ .../view/history_view_schedule_box.cpp | 7 +++-- .../history/view/history_view_schedule_box.h | 5 ++++ .../view/history_view_scheduled_section.cpp | 20 +++++++++---- .../view/history_view_scheduled_section.h | 2 ++ .../view/history_view_top_bar_widget.cpp | 4 ++- 15 files changed, 113 insertions(+), 36 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7a9e1f60d..56decef54 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1242,7 +1242,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_send_button" = "Send"; "lng_send_silent_message" = "Send without sound"; "lng_schedule_message" = "Schedule message"; +"lng_reminder_message" = "Set a reminder"; "lng_schedule_title" = "Send this message on..."; +"lng_remind_title" = "Remind me on..."; "lng_schedule_at" = "at"; "lng_message_ph" = "Write a message..."; "lng_broadcast_ph" = "Broadcast a message..."; @@ -1264,6 +1266,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_saved_forward_here" = "Forward messages here for quick access"; "lng_scheduled_messages" = "Scheduled Messages"; +"lng_reminder_messages" = "Reminders"; "lng_archived_name" = "Archived chats"; "lng_archived_add" = "Archive"; diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 86df6293e..c433314c6 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -719,7 +719,10 @@ object_ptr CreatePollBox::setupContent() { }; const auto sendScheduled = [=] { Ui::show( - HistoryView::PrepareScheduleBox(this, send), + HistoryView::PrepareScheduleBox( + this, + SendMenuType::Scheduled, + send), LayerOption::KeepOther); }; const auto updateValid = [=] { @@ -740,7 +743,7 @@ object_ptr CreatePollBox::setupContent() { if (_sendType == Api::SendType::Normal) { SetupSendMenu( submit.data(), - [=] { return true; }, + [=] { return SendMenuType::Scheduled; }, sendSilent, sendScheduled); } diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 8a5ad1e88..3b410b8e5 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -1369,13 +1369,15 @@ SendFilesBox::SendFilesBox( const TextWithTags &caption, CompressConfirm compressed, SendLimit limit, - Api::SendType sendType) + Api::SendType sendType, + SendMenuType sendMenuType) : _controller(controller) , _sendType(sendType) , _list(std::move(list)) , _compressConfirmInitial(compressed) , _compressConfirm(compressed) , _sendLimit(limit) +, _sendMenuType(sendMenuType) , _caption( this, st::confirmCaptionArea, @@ -1476,7 +1478,7 @@ void SendFilesBox::prepare() { if (_sendType == Api::SendType::Normal) { SetupSendMenu( _send, - [=] { return true; }, + [=] { return _sendMenuType; }, [=] { sendSilent(); }, [=] { sendScheduled(); }); } @@ -1973,7 +1975,7 @@ void SendFilesBox::sendSilent() { void SendFilesBox::sendScheduled() { const auto callback = [=](Api::SendOptions options) { send(options); }; Ui::show( - HistoryView::PrepareScheduleBox(this, callback), + HistoryView::PrepareScheduleBox(this, _sendMenuType, callback), LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/boxes/send_files_box.h b/Telegram/SourceFiles/boxes/send_files_box.h index 322cb6003..401a37306 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.h +++ b/Telegram/SourceFiles/boxes/send_files_box.h @@ -40,6 +40,8 @@ namespace Window { class SessionController; } // namespace Window +enum class SendMenuType; + enum class SendFilesWay { Album, Photos, @@ -59,7 +61,8 @@ public: const TextWithTags &caption, CompressConfirm compressed, SendLimit limit, - Api::SendType sendType); + Api::SendType sendType, + SendMenuType sendMenuType); void setConfirmedCallback( Fnselected(); + return (selected.size() == 1 && selected.front()->isSelf()) + ? SendMenuType::Reminder + : SendMenuType::Scheduled; +} + void ShareBox::createButtons() { clearButtons(); if (_hasSelected) { @@ -417,7 +424,7 @@ void ShareBox::createButtons() { }); SetupSendMenu( send, - [=] { return true; }, + [=] { return sendMenuType(); }, [=] { submitSilent(); }, [=] { submitScheduled(); }); } else if (_copyCallback) { @@ -471,7 +478,7 @@ void ShareBox::submitSilent() { void ShareBox::submitScheduled() { const auto callback = [=](Api::SendOptions options) { submit(options); }; Ui::show( - HistoryView::PrepareScheduleBox(this, callback), + HistoryView::PrepareScheduleBox(this, sendMenuType(), callback), LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/boxes/share_box.h b/Telegram/SourceFiles/boxes/share_box.h index f873ce849..480b5345f 100644 --- a/Telegram/SourceFiles/boxes/share_box.h +++ b/Telegram/SourceFiles/boxes/share_box.h @@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/animations.h" #include "ui/effects/round_checkbox.h" +enum class SendMenuType; + namespace Window { class SessionNavigation; } // namespace Window @@ -83,6 +85,8 @@ private: void copyLink(); bool searchByUsername(bool useCache = false); + SendMenuType sendMenuType() const; + void scrollTo(Ui::ScrollToRequest request); void needSearchByUsername(); void applyFilterUpdate(const QString &query); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 805a96119..847f7a1d6 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -786,26 +786,36 @@ void MessageLinksParser::apply( void SetupSendMenu( not_null button, - Fn enabled, - Fn send, + Fn type, + Fn silent, Fn schedule) { - if (!send && !schedule) { + if (!silent && !schedule) { return; } const auto menu = std::make_shared>(); const auto showMenu = [=] { - *menu = base::make_unique_q(button); - if (send) { - (*menu)->addAction(tr::lng_send_silent_message(tr::now), send); + const auto now = type(); + if (now == SendMenuType::Disabled + || (!silent && now == SendMenuType::SilentOnly)) { + return false; } - if (schedule) { - (*menu)->addAction(tr::lng_schedule_message(tr::now), schedule); + + *menu = base::make_unique_q(button); + if (silent) { + (*menu)->addAction(tr::lng_send_silent_message(tr::now), silent); + } + if (schedule && now != SendMenuType::SilentOnly) { + (*menu)->addAction( + (now == SendMenuType::Scheduled + ? tr::lng_schedule_message(tr::now) + : tr::lng_reminder_message(tr::now)), + schedule); } (*menu)->popup(QCursor::pos()); + return true; }; Core::InstallEventFilter(button, [=](not_null e) { - if (e->type() == QEvent::ContextMenu && enabled()) { - showMenu(); + if (e->type() == QEvent::ContextMenu && showMenu()) { return true; } return false; diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index cbadf01cb..75a1a8b20 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -57,7 +57,7 @@ struct AutocompleteQuery { AutocompleteQuery ParseMentionHashtagBotCommandQuery( not_null field); -class QtConnectionOwner { +class QtConnectionOwner final { public: QtConnectionOwner(QMetaObject::Connection connection = {}); QtConnectionOwner(QtConnectionOwner &&other); @@ -106,8 +106,15 @@ private: }; +enum class SendMenuType { + Disabled, + SilentOnly, + Scheduled, + Reminder, +}; + void SetupSendMenu( not_null button, - Fn enabled, - Fn send, + Fn type, + Fn silent, Fn schedule); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index aea513731..0de17bf5d 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -300,10 +300,13 @@ HistoryWidget::HistoryWidget( _unreadMentions->addClickHandler([=] { showNextUnreadMention(); }); _fieldBarCancel->addClickHandler([=] { cancelFieldAreaState(); }); _send->addClickHandler([=] { sendButtonClicked(); }); - SetupSendMenu(_send, [=] { - return (_send->type() == Ui::SendButton::Type::Send) - && !_send->isDisabled(); - }, [=] { sendSilent(); }, [=] { sendScheduled(); }); + + SetupSendMenu( + _send, + [=] { return sendMenuType(); }, + [=] { sendSilent(); }, + [=] { sendScheduled(); }); + _unblock->addClickHandler([=] { unblockUser(); }); _botStart->addClickHandler([=] { sendBotStartCommand(); }); _joinChannel->addClickHandler([=] { joinChannel(); }); @@ -2972,10 +2975,21 @@ void HistoryWidget::sendScheduled() { } const auto callback = [=](Api::SendOptions options) { send(options); }; Ui::show( - HistoryView::PrepareScheduleBox(_list, callback), + HistoryView::PrepareScheduleBox(_list, sendMenuType(), callback), LayerOption::KeepOther); } +SendMenuType HistoryWidget::sendMenuType() const { + if (_send->type() != Ui::SendButton::Type::Send + || _send->isDisabled() + || !_peer) { + return SendMenuType::Disabled; + } + return _peer->isSelf() + ? SendMenuType::Reminder + : SendMenuType::Scheduled; +} + void HistoryWidget::unblockUser() { if (const auto user = _peer ? _peer->asUser() : nullptr) { Window::PeerMenuUnblockUserWithBotRestart(user); @@ -4188,7 +4202,8 @@ bool HistoryWidget::confirmSendingFiles( text, boxCompressConfirm, _peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many, - Api::SendType::Normal); + Api::SendType::Normal, + sendMenuType()); _field->setTextWithTags({}); box->setConfirmedCallback(crl::guard(this, [=]( Storage::PreparedList &&list, diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 7d281e45e..06ae204cd 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -23,6 +23,7 @@ struct SendingAlbum; enum class SendMediaType; enum class CompressConfirm; class MessageLinksParser; +enum class SendMenuType; namespace Api { struct SendOptions; @@ -366,6 +367,7 @@ private: void sendWithModifiers(Qt::KeyboardModifiers modifiers); void sendSilent(); void sendScheduled(); + [[nodiscard]] SendMenuType sendMenuType() const; void handlePendingHistoryUpdate(); void fullPeerUpdated(PeerData *peer); void toggleTabbedSelectorMode(); diff --git a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp index 4949cbbed..bfe7fc645 100644 --- a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp +++ b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp @@ -543,9 +543,12 @@ TimeId DefaultScheduleTime() { void ScheduleBox( not_null box, + SendMenuType type, FnMut done, TimeId time) { - box->setTitle(tr::lng_schedule_title()); + box->setTitle((type == SendMenuType::Scheduled) + ? tr::lng_schedule_title() + : tr::lng_remind_title()); box->setWidth(st::boxWideWidth); const auto date = Ui::CreateChild>( @@ -657,7 +660,7 @@ void ScheduleBox( }); SetupSendMenu( submit.data(), - [=] { return true; }, + [=] { return SendMenuType::SilentOnly; }, [=] { save(true); }, nullptr); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); diff --git a/Telegram/SourceFiles/history/view/history_view_schedule_box.h b/Telegram/SourceFiles/history/view/history_view_schedule_box.h index 2b73ee5da..a0269a5fc 100644 --- a/Telegram/SourceFiles/history/view/history_view_schedule_box.h +++ b/Telegram/SourceFiles/history/view/history_view_schedule_box.h @@ -13,20 +13,25 @@ namespace Api { struct SendOptions; } // namespace Api +enum class SendMenuType; + namespace HistoryView { [[nodiscard]] TimeId DefaultScheduleTime(); void ScheduleBox( not_null box, + SendMenuType type, FnMut done, TimeId time); template [[nodiscard]] object_ptr PrepareScheduleBox( Guard &&guard, + SendMenuType type, Submit &&submit) { return Box( ScheduleBox, + type, crl::guard(std::forward(guard), std::forward(submit)), DefaultScheduleTime()); } diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index e387d92d3..f4221c471 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_schedule_box.h" #include "history/history.h" #include "history/history_item.h" +#include "chat_helpers/message_field.h" // SendMenuType. #include "ui/widgets/scroll_area.h" #include "ui/widgets/shadow.h" #include "ui/toast/toast.h" @@ -235,7 +236,8 @@ bool ScheduledWidget::confirmSendingFiles( text, boxCompressConfirm, _history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many, - Api::SendType::Scheduled); + Api::SendType::Scheduled, + SendMenuType::Disabled); //_field->setTextWithTags({}); box->setConfirmedCallback(crl::guard(this, [=]( @@ -338,7 +340,7 @@ void ScheduledWidget::uploadFile( session().api().sendFile(fileContent, type, action); }; Ui::show( - PrepareScheduleBox(this, callback), + PrepareScheduleBox(this, sendMenuType(), callback), LayerOption::KeepOther); } @@ -381,7 +383,7 @@ void ScheduledWidget::send() { } const auto callback = [=](Api::SendOptions options) { send(options); }; Ui::show( - PrepareScheduleBox(this, callback), + PrepareScheduleBox(this, sendMenuType(), callback), LayerOption::KeepOther); } @@ -426,7 +428,7 @@ void ScheduledWidget::sendExistingDocument( sendExistingDocument(document, options); }; Ui::show( - PrepareScheduleBox(this, callback), + PrepareScheduleBox(this, sendMenuType(), callback), LayerOption::KeepOther); } @@ -464,7 +466,7 @@ void ScheduledWidget::sendExistingPhoto(not_null photo) { sendExistingPhoto(photo, options); }; Ui::show( - PrepareScheduleBox(this, callback), + PrepareScheduleBox(this, sendMenuType(), callback), LayerOption::KeepOther); } @@ -501,7 +503,7 @@ void ScheduledWidget::sendInlineResult( sendInlineResult(result, bot, options); }; Ui::show( - PrepareScheduleBox(this, callback), + PrepareScheduleBox(this, sendMenuType(), callback), LayerOption::KeepOther); } @@ -537,6 +539,12 @@ void ScheduledWidget::sendInlineResult( _composeControls->focus(); } +SendMenuType ScheduledWidget::sendMenuType() const { + return _history->peer->isSelf() + ? SendMenuType::Reminder + : SendMenuType::Scheduled; +} + void ScheduledWidget::setupScrollDownButton() { _scrollDown->setClickedCallback([=] { scrollDownClicked(); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h index 8a15d0828..95bd85942 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h @@ -16,6 +16,7 @@ class History; enum class CompressConfirm; enum class SendMediaType; struct SendingAlbum; +enum class SendMenuType; namespace Api { struct SendOptions; @@ -145,6 +146,7 @@ private: void send(Api::SendOptions options); void highlightSingleNewMessage(const Data::MessagesSlice &slice); void chooseAttach(); + [[nodiscard]] SendMenuType sendMenuType() const; void uploadFile(const QByteArray &fileContent, SendMediaType type); bool confirmSendingFiles( 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 57fb4d6ef..9ff68df08 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -323,7 +323,9 @@ void TopBarWidget::paintTopBar(Painter &p) { || (_section == Section::Scheduled)) { // #TODO feed name emoji. auto text = (_section == Section::Scheduled) - ? tr::lng_scheduled_messages(tr::now) + ? ((history && history->peer->isSelf()) + ? tr::lng_reminder_messages(tr::now) + : tr::lng_scheduled_messages(tr::now)) : folder ? folder->chatListName() : tr::lng_saved_messages(tr::now);