Add new phrases for reminders.

This commit is contained in:
John Preston 2019-08-28 19:46:47 +03:00
parent 0a4f91a53d
commit 87addd41b1
15 changed files with 113 additions and 36 deletions

View File

@ -1242,7 +1242,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_send_button" = "Send"; "lng_send_button" = "Send";
"lng_send_silent_message" = "Send without sound"; "lng_send_silent_message" = "Send without sound";
"lng_schedule_message" = "Schedule message"; "lng_schedule_message" = "Schedule message";
"lng_reminder_message" = "Set a reminder";
"lng_schedule_title" = "Send this message on..."; "lng_schedule_title" = "Send this message on...";
"lng_remind_title" = "Remind me on...";
"lng_schedule_at" = "at"; "lng_schedule_at" = "at";
"lng_message_ph" = "Write a message..."; "lng_message_ph" = "Write a message...";
"lng_broadcast_ph" = "Broadcast 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_saved_forward_here" = "Forward messages here for quick access";
"lng_scheduled_messages" = "Scheduled Messages"; "lng_scheduled_messages" = "Scheduled Messages";
"lng_reminder_messages" = "Reminders";
"lng_archived_name" = "Archived chats"; "lng_archived_name" = "Archived chats";
"lng_archived_add" = "Archive"; "lng_archived_add" = "Archive";

View File

@ -719,7 +719,10 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
}; };
const auto sendScheduled = [=] { const auto sendScheduled = [=] {
Ui::show( Ui::show(
HistoryView::PrepareScheduleBox(this, send), HistoryView::PrepareScheduleBox(
this,
SendMenuType::Scheduled,
send),
LayerOption::KeepOther); LayerOption::KeepOther);
}; };
const auto updateValid = [=] { const auto updateValid = [=] {
@ -740,7 +743,7 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
if (_sendType == Api::SendType::Normal) { if (_sendType == Api::SendType::Normal) {
SetupSendMenu( SetupSendMenu(
submit.data(), submit.data(),
[=] { return true; }, [=] { return SendMenuType::Scheduled; },
sendSilent, sendSilent,
sendScheduled); sendScheduled);
} }

View File

@ -1369,13 +1369,15 @@ SendFilesBox::SendFilesBox(
const TextWithTags &caption, const TextWithTags &caption,
CompressConfirm compressed, CompressConfirm compressed,
SendLimit limit, SendLimit limit,
Api::SendType sendType) Api::SendType sendType,
SendMenuType sendMenuType)
: _controller(controller) : _controller(controller)
, _sendType(sendType) , _sendType(sendType)
, _list(std::move(list)) , _list(std::move(list))
, _compressConfirmInitial(compressed) , _compressConfirmInitial(compressed)
, _compressConfirm(compressed) , _compressConfirm(compressed)
, _sendLimit(limit) , _sendLimit(limit)
, _sendMenuType(sendMenuType)
, _caption( , _caption(
this, this,
st::confirmCaptionArea, st::confirmCaptionArea,
@ -1476,7 +1478,7 @@ void SendFilesBox::prepare() {
if (_sendType == Api::SendType::Normal) { if (_sendType == Api::SendType::Normal) {
SetupSendMenu( SetupSendMenu(
_send, _send,
[=] { return true; }, [=] { return _sendMenuType; },
[=] { sendSilent(); }, [=] { sendSilent(); },
[=] { sendScheduled(); }); [=] { sendScheduled(); });
} }
@ -1973,7 +1975,7 @@ void SendFilesBox::sendSilent() {
void SendFilesBox::sendScheduled() { void SendFilesBox::sendScheduled() {
const auto callback = [=](Api::SendOptions options) { send(options); }; const auto callback = [=](Api::SendOptions options) { send(options); };
Ui::show( Ui::show(
HistoryView::PrepareScheduleBox(this, callback), HistoryView::PrepareScheduleBox(this, _sendMenuType, callback),
LayerOption::KeepOther); LayerOption::KeepOther);
} }

View File

@ -40,6 +40,8 @@ namespace Window {
class SessionController; class SessionController;
} // namespace Window } // namespace Window
enum class SendMenuType;
enum class SendFilesWay { enum class SendFilesWay {
Album, Album,
Photos, Photos,
@ -59,7 +61,8 @@ public:
const TextWithTags &caption, const TextWithTags &caption,
CompressConfirm compressed, CompressConfirm compressed,
SendLimit limit, SendLimit limit,
Api::SendType sendType); Api::SendType sendType,
SendMenuType sendMenuType);
void setConfirmedCallback( void setConfirmedCallback(
Fn<void( Fn<void(
@ -132,6 +135,7 @@ private:
CompressConfirm _compressConfirmInitial = CompressConfirm::None; CompressConfirm _compressConfirmInitial = CompressConfirm::None;
CompressConfirm _compressConfirm = CompressConfirm::None; CompressConfirm _compressConfirm = CompressConfirm::None;
SendLimit _sendLimit = SendLimit::Many; SendLimit _sendLimit = SendLimit::Many;
SendMenuType _sendMenuType = SendMenuType();
Fn<void( Fn<void(
Storage::PreparedList &&list, Storage::PreparedList &&list,

View File

@ -409,6 +409,13 @@ void ShareBox::keyPressEvent(QKeyEvent *e) {
} }
} }
SendMenuType ShareBox::sendMenuType() const {
const auto selected = _inner->selected();
return (selected.size() == 1 && selected.front()->isSelf())
? SendMenuType::Reminder
: SendMenuType::Scheduled;
}
void ShareBox::createButtons() { void ShareBox::createButtons() {
clearButtons(); clearButtons();
if (_hasSelected) { if (_hasSelected) {
@ -417,7 +424,7 @@ void ShareBox::createButtons() {
}); });
SetupSendMenu( SetupSendMenu(
send, send,
[=] { return true; }, [=] { return sendMenuType(); },
[=] { submitSilent(); }, [=] { submitSilent(); },
[=] { submitScheduled(); }); [=] { submitScheduled(); });
} else if (_copyCallback) { } else if (_copyCallback) {
@ -471,7 +478,7 @@ void ShareBox::submitSilent() {
void ShareBox::submitScheduled() { void ShareBox::submitScheduled() {
const auto callback = [=](Api::SendOptions options) { submit(options); }; const auto callback = [=](Api::SendOptions options) { submit(options); };
Ui::show( Ui::show(
HistoryView::PrepareScheduleBox(this, callback), HistoryView::PrepareScheduleBox(this, sendMenuType(), callback),
LayerOption::KeepOther); LayerOption::KeepOther);
} }

View File

@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/effects/round_checkbox.h" #include "ui/effects/round_checkbox.h"
enum class SendMenuType;
namespace Window { namespace Window {
class SessionNavigation; class SessionNavigation;
} // namespace Window } // namespace Window
@ -83,6 +85,8 @@ private:
void copyLink(); void copyLink();
bool searchByUsername(bool useCache = false); bool searchByUsername(bool useCache = false);
SendMenuType sendMenuType() const;
void scrollTo(Ui::ScrollToRequest request); void scrollTo(Ui::ScrollToRequest request);
void needSearchByUsername(); void needSearchByUsername();
void applyFilterUpdate(const QString &query); void applyFilterUpdate(const QString &query);

View File

@ -786,26 +786,36 @@ void MessageLinksParser::apply(
void SetupSendMenu( void SetupSendMenu(
not_null<Ui::RpWidget*> button, not_null<Ui::RpWidget*> button,
Fn<bool()> enabled, Fn<SendMenuType()> type,
Fn<void()> send, Fn<void()> silent,
Fn<void()> schedule) { Fn<void()> schedule) {
if (!send && !schedule) { if (!silent && !schedule) {
return; return;
} }
const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>(); const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>();
const auto showMenu = [=] { const auto showMenu = [=] {
*menu = base::make_unique_q<Ui::PopupMenu>(button); const auto now = type();
if (send) { if (now == SendMenuType::Disabled
(*menu)->addAction(tr::lng_send_silent_message(tr::now), send); || (!silent && now == SendMenuType::SilentOnly)) {
return false;
} }
if (schedule) {
(*menu)->addAction(tr::lng_schedule_message(tr::now), schedule); *menu = base::make_unique_q<Ui::PopupMenu>(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()); (*menu)->popup(QCursor::pos());
return true;
}; };
Core::InstallEventFilter(button, [=](not_null<QEvent*> e) { Core::InstallEventFilter(button, [=](not_null<QEvent*> e) {
if (e->type() == QEvent::ContextMenu && enabled()) { if (e->type() == QEvent::ContextMenu && showMenu()) {
showMenu();
return true; return true;
} }
return false; return false;

View File

@ -57,7 +57,7 @@ struct AutocompleteQuery {
AutocompleteQuery ParseMentionHashtagBotCommandQuery( AutocompleteQuery ParseMentionHashtagBotCommandQuery(
not_null<const Ui::InputField*> field); not_null<const Ui::InputField*> field);
class QtConnectionOwner { class QtConnectionOwner final {
public: public:
QtConnectionOwner(QMetaObject::Connection connection = {}); QtConnectionOwner(QMetaObject::Connection connection = {});
QtConnectionOwner(QtConnectionOwner &&other); QtConnectionOwner(QtConnectionOwner &&other);
@ -106,8 +106,15 @@ private:
}; };
enum class SendMenuType {
Disabled,
SilentOnly,
Scheduled,
Reminder,
};
void SetupSendMenu( void SetupSendMenu(
not_null<Ui::RpWidget*> button, not_null<Ui::RpWidget*> button,
Fn<bool()> enabled, Fn<SendMenuType()> type,
Fn<void()> send, Fn<void()> silent,
Fn<void()> schedule); Fn<void()> schedule);

View File

@ -300,10 +300,13 @@ HistoryWidget::HistoryWidget(
_unreadMentions->addClickHandler([=] { showNextUnreadMention(); }); _unreadMentions->addClickHandler([=] { showNextUnreadMention(); });
_fieldBarCancel->addClickHandler([=] { cancelFieldAreaState(); }); _fieldBarCancel->addClickHandler([=] { cancelFieldAreaState(); });
_send->addClickHandler([=] { sendButtonClicked(); }); _send->addClickHandler([=] { sendButtonClicked(); });
SetupSendMenu(_send, [=] {
return (_send->type() == Ui::SendButton::Type::Send) SetupSendMenu(
&& !_send->isDisabled(); _send,
}, [=] { sendSilent(); }, [=] { sendScheduled(); }); [=] { return sendMenuType(); },
[=] { sendSilent(); },
[=] { sendScheduled(); });
_unblock->addClickHandler([=] { unblockUser(); }); _unblock->addClickHandler([=] { unblockUser(); });
_botStart->addClickHandler([=] { sendBotStartCommand(); }); _botStart->addClickHandler([=] { sendBotStartCommand(); });
_joinChannel->addClickHandler([=] { joinChannel(); }); _joinChannel->addClickHandler([=] { joinChannel(); });
@ -2972,10 +2975,21 @@ void HistoryWidget::sendScheduled() {
} }
const auto callback = [=](Api::SendOptions options) { send(options); }; const auto callback = [=](Api::SendOptions options) { send(options); };
Ui::show( Ui::show(
HistoryView::PrepareScheduleBox(_list, callback), HistoryView::PrepareScheduleBox(_list, sendMenuType(), callback),
LayerOption::KeepOther); 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() { void HistoryWidget::unblockUser() {
if (const auto user = _peer ? _peer->asUser() : nullptr) { if (const auto user = _peer ? _peer->asUser() : nullptr) {
Window::PeerMenuUnblockUserWithBotRestart(user); Window::PeerMenuUnblockUserWithBotRestart(user);
@ -4188,7 +4202,8 @@ bool HistoryWidget::confirmSendingFiles(
text, text,
boxCompressConfirm, boxCompressConfirm,
_peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many, _peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many,
Api::SendType::Normal); Api::SendType::Normal,
sendMenuType());
_field->setTextWithTags({}); _field->setTextWithTags({});
box->setConfirmedCallback(crl::guard(this, [=]( box->setConfirmedCallback(crl::guard(this, [=](
Storage::PreparedList &&list, Storage::PreparedList &&list,

View File

@ -23,6 +23,7 @@ struct SendingAlbum;
enum class SendMediaType; enum class SendMediaType;
enum class CompressConfirm; enum class CompressConfirm;
class MessageLinksParser; class MessageLinksParser;
enum class SendMenuType;
namespace Api { namespace Api {
struct SendOptions; struct SendOptions;
@ -366,6 +367,7 @@ private:
void sendWithModifiers(Qt::KeyboardModifiers modifiers); void sendWithModifiers(Qt::KeyboardModifiers modifiers);
void sendSilent(); void sendSilent();
void sendScheduled(); void sendScheduled();
[[nodiscard]] SendMenuType sendMenuType() const;
void handlePendingHistoryUpdate(); void handlePendingHistoryUpdate();
void fullPeerUpdated(PeerData *peer); void fullPeerUpdated(PeerData *peer);
void toggleTabbedSelectorMode(); void toggleTabbedSelectorMode();

View File

@ -543,9 +543,12 @@ TimeId DefaultScheduleTime() {
void ScheduleBox( void ScheduleBox(
not_null<GenericBox*> box, not_null<GenericBox*> box,
SendMenuType type,
FnMut<void(Api::SendOptions)> done, FnMut<void(Api::SendOptions)> done,
TimeId time) { 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); box->setWidth(st::boxWideWidth);
const auto date = Ui::CreateChild<rpl::variable<QDate>>( const auto date = Ui::CreateChild<rpl::variable<QDate>>(
@ -657,7 +660,7 @@ void ScheduleBox(
}); });
SetupSendMenu( SetupSendMenu(
submit.data(), submit.data(),
[=] { return true; }, [=] { return SendMenuType::SilentOnly; },
[=] { save(true); }, [=] { save(true); },
nullptr); nullptr);
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });

View File

@ -13,20 +13,25 @@ namespace Api {
struct SendOptions; struct SendOptions;
} // namespace Api } // namespace Api
enum class SendMenuType;
namespace HistoryView { namespace HistoryView {
[[nodiscard]] TimeId DefaultScheduleTime(); [[nodiscard]] TimeId DefaultScheduleTime();
void ScheduleBox( void ScheduleBox(
not_null<GenericBox*> box, not_null<GenericBox*> box,
SendMenuType type,
FnMut<void(Api::SendOptions)> done, FnMut<void(Api::SendOptions)> done,
TimeId time); TimeId time);
template <typename Guard, typename Submit> template <typename Guard, typename Submit>
[[nodiscard]] object_ptr<GenericBox> PrepareScheduleBox( [[nodiscard]] object_ptr<GenericBox> PrepareScheduleBox(
Guard &&guard, Guard &&guard,
SendMenuType type,
Submit &&submit) { Submit &&submit) {
return Box( return Box(
ScheduleBox, ScheduleBox,
type,
crl::guard(std::forward<Guard>(guard), std::forward<Submit>(submit)), crl::guard(std::forward<Guard>(guard), std::forward<Submit>(submit)),
DefaultScheduleTime()); DefaultScheduleTime());
} }

View File

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_schedule_box.h" #include "history/view/history_view_schedule_box.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "chat_helpers/message_field.h" // SendMenuType.
#include "ui/widgets/scroll_area.h" #include "ui/widgets/scroll_area.h"
#include "ui/widgets/shadow.h" #include "ui/widgets/shadow.h"
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
@ -235,7 +236,8 @@ bool ScheduledWidget::confirmSendingFiles(
text, text,
boxCompressConfirm, boxCompressConfirm,
_history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many, _history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many,
Api::SendType::Scheduled); Api::SendType::Scheduled,
SendMenuType::Disabled);
//_field->setTextWithTags({}); //_field->setTextWithTags({});
box->setConfirmedCallback(crl::guard(this, [=]( box->setConfirmedCallback(crl::guard(this, [=](
@ -338,7 +340,7 @@ void ScheduledWidget::uploadFile(
session().api().sendFile(fileContent, type, action); session().api().sendFile(fileContent, type, action);
}; };
Ui::show( Ui::show(
PrepareScheduleBox(this, callback), PrepareScheduleBox(this, sendMenuType(), callback),
LayerOption::KeepOther); LayerOption::KeepOther);
} }
@ -381,7 +383,7 @@ void ScheduledWidget::send() {
} }
const auto callback = [=](Api::SendOptions options) { send(options); }; const auto callback = [=](Api::SendOptions options) { send(options); };
Ui::show( Ui::show(
PrepareScheduleBox(this, callback), PrepareScheduleBox(this, sendMenuType(), callback),
LayerOption::KeepOther); LayerOption::KeepOther);
} }
@ -426,7 +428,7 @@ void ScheduledWidget::sendExistingDocument(
sendExistingDocument(document, options); sendExistingDocument(document, options);
}; };
Ui::show( Ui::show(
PrepareScheduleBox(this, callback), PrepareScheduleBox(this, sendMenuType(), callback),
LayerOption::KeepOther); LayerOption::KeepOther);
} }
@ -464,7 +466,7 @@ void ScheduledWidget::sendExistingPhoto(not_null<PhotoData*> photo) {
sendExistingPhoto(photo, options); sendExistingPhoto(photo, options);
}; };
Ui::show( Ui::show(
PrepareScheduleBox(this, callback), PrepareScheduleBox(this, sendMenuType(), callback),
LayerOption::KeepOther); LayerOption::KeepOther);
} }
@ -501,7 +503,7 @@ void ScheduledWidget::sendInlineResult(
sendInlineResult(result, bot, options); sendInlineResult(result, bot, options);
}; };
Ui::show( Ui::show(
PrepareScheduleBox(this, callback), PrepareScheduleBox(this, sendMenuType(), callback),
LayerOption::KeepOther); LayerOption::KeepOther);
} }
@ -537,6 +539,12 @@ void ScheduledWidget::sendInlineResult(
_composeControls->focus(); _composeControls->focus();
} }
SendMenuType ScheduledWidget::sendMenuType() const {
return _history->peer->isSelf()
? SendMenuType::Reminder
: SendMenuType::Scheduled;
}
void ScheduledWidget::setupScrollDownButton() { void ScheduledWidget::setupScrollDownButton() {
_scrollDown->setClickedCallback([=] { _scrollDown->setClickedCallback([=] {
scrollDownClicked(); scrollDownClicked();

View File

@ -16,6 +16,7 @@ class History;
enum class CompressConfirm; enum class CompressConfirm;
enum class SendMediaType; enum class SendMediaType;
struct SendingAlbum; struct SendingAlbum;
enum class SendMenuType;
namespace Api { namespace Api {
struct SendOptions; struct SendOptions;
@ -145,6 +146,7 @@ private:
void send(Api::SendOptions options); void send(Api::SendOptions options);
void highlightSingleNewMessage(const Data::MessagesSlice &slice); void highlightSingleNewMessage(const Data::MessagesSlice &slice);
void chooseAttach(); void chooseAttach();
[[nodiscard]] SendMenuType sendMenuType() const;
void uploadFile(const QByteArray &fileContent, SendMediaType type); void uploadFile(const QByteArray &fileContent, SendMediaType type);
bool confirmSendingFiles( bool confirmSendingFiles(

View File

@ -323,7 +323,9 @@ void TopBarWidget::paintTopBar(Painter &p) {
|| (_section == Section::Scheduled)) { || (_section == Section::Scheduled)) {
// #TODO feed name emoji. // #TODO feed name emoji.
auto text = (_section == Section::Scheduled) 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
? folder->chatListName() ? folder->chatListName()
: tr::lng_saved_messages(tr::now); : tr::lng_saved_messages(tr::now);