diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 248ed8d45f..a24bdeac4b 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -5528,9 +5528,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_menu_formatting_blockquote" = "Quote"; "lng_menu_formatting_monospace" = "Monospace"; "lng_menu_formatting_spoiler" = "Spoiler"; +"lng_menu_formatting_date" = "Date"; "lng_menu_formatting_link_create" = "Create link"; "lng_menu_formatting_link_edit" = "Edit link"; "lng_menu_formatting_clear" = "Clear formatting"; +"lng_formatting_date_title" = "Choose date and time"; "lng_formatting_link_create_title" = "Create link"; "lng_formatting_link_edit_title" = "Edit link"; "lng_formatting_link_text" = "Text"; diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index dec17c47b3..e3c97e1305 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -17,6 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/event_filter.h" #include "ui/chat/chat_style.h" #include "ui/layers/generic_box.h" +#include "ui/boxes/calendar_box.h" +#include "ui/boxes/choose_date_time.h" #include "ui/basic_click_handlers.h" #include "ui/rect.h" #include "core/shortcuts.h" @@ -408,8 +410,68 @@ FncommitMarkdownLinkEdit(selection, t, l); + } + }; + const auto savedCallback = std::make_shared< + Fn>( + std::move(callback)); + const auto savedText = std::make_shared(text); + const auto showDateTimeBox = [=](TimeId time) { + const auto dateBox = std::make_shared< + base::weak_qptr>(); + *dateBox = show->show(Box( + Ui::ChooseDateTimeBox, + Ui::ChooseDateTimeBoxArgs{ + .title = tr::lng_formatting_date_title(), + .submit = tr::lng_settings_save(), + .done = [=](TimeId result) { + const auto dateLink + = Ui::InputField::kCustomDateTagStart + + QString::number(result); + (*savedCallback)( + *savedText, + dateLink); + if (const auto box = dateBox->get()) { + box->closeBox(); + } + }, + .min = [] { return TimeId(1); }, + .time = time, + .max = [] { return TimeId(2114380800); }, + })); + }; + if (existingDate > 0) { + showDateTimeBox(existingDate); + } else { + show->show(Box(Ui::CalendarBoxArgs{ + .month = QDate::currentDate(), + .highlighted = QDate::currentDate(), + .callback = [=](QDate chosen, Fn close) { + close(); + const auto midday = QDateTime( + chosen, + QTime(12, 0)); + showDateTimeBox( + base::unixtime::serialize(midday)); + }, + .minDate = QDate(1970, 1, 1), + .maxDate = QDate(2036, 12, 31), + })); + } + return true; } auto callback = [=](const TextWithTags &text, const QString &link) { if (const auto strong = weak.get()) { diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 835a484151..61e038cc28 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -578,7 +578,7 @@ void FormattedDateClickHandler::onClick(ClickContext context) const { action); })); }, - &st::menuIconSchedule); + &st::menuIconNotifications); } menu->popup(QCursor::pos()); diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index 352089e02a..3b003e6191 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -528,6 +528,10 @@ QString UiIntegration::phraseFormattingSpoiler() { return tr::lng_menu_formatting_spoiler(tr::now); } +QString UiIntegration::phraseFormattingDate() { + return tr::lng_menu_formatting_date(tr::now); +} + QString UiIntegration::phraseButtonOk() { return tr::lng_box_ok(tr::now); } diff --git a/Telegram/SourceFiles/core/ui_integration.h b/Telegram/SourceFiles/core/ui_integration.h index eae9cca342..dfc923292f 100644 --- a/Telegram/SourceFiles/core/ui_integration.h +++ b/Telegram/SourceFiles/core/ui_integration.h @@ -79,6 +79,7 @@ public: QString phraseFormattingBlockquote() override; QString phraseFormattingMonospace() override; QString phraseFormattingSpoiler() override; + QString phraseFormattingDate() override; QString phraseButtonOk() override; QString phraseButtonClose() override; QString phraseButtonCancel() override; diff --git a/Telegram/SourceFiles/ui/boxes/choose_date_time.cpp b/Telegram/SourceFiles/ui/boxes/choose_date_time.cpp index b646da1018..b8db8ec83b 100644 --- a/Telegram/SourceFiles/ui/boxes/choose_date_time.cpp +++ b/Telegram/SourceFiles/ui/boxes/choose_date_time.cpp @@ -28,12 +28,19 @@ namespace { constexpr auto kMinimalSchedule = TimeId(10); QString DayString(const QDate &date) { - return tr::lng_month_day( - tr::now, - lt_month, - Lang::MonthDay(date.month())(tr::now), - lt_day, - QString::number(date.day())); + const auto month = Lang::MonthDay(date.month())(tr::now); + const auto day = QString::number(date.day()); + if (date.year() != QDate::currentDate().year()) { + return tr::lng_month_day_year( + tr::now, + lt_month, + month, + lt_day, + day, + lt_year, + QString::number(date.year())); + } + return tr::lng_month_day(tr::now, lt_month, month, lt_day, day); } QString TimeString(QTime time) { diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 1bb25b4a5a..4bb2ec6716 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 1bb25b4a5a00fa15be5f112796f89758de12a84b +Subproject commit 4bb2ec67161df0a15eb25e0e9ae52422e3c399e9