From ae3925b9cd5c399b9b95422fea67302087756f37 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 27 Feb 2026 23:33:07 +0400 Subject: [PATCH] Nice toast after reminder from formatted date. --- Telegram/CMakeLists.txt | 2 + Telegram/Resources/langs/lang.strings | 1 + .../SourceFiles/core/click_handler_types.cpp | 44 +++++++++++++++++- .../history_view_self_forwards_tagger.cpp | 29 +++--------- .../view/history_view_self_forwards_tagger.h | 4 -- .../ui/toast/toast_lottie_icon.cpp | 45 +++++++++++++++++++ .../SourceFiles/ui/toast/toast_lottie_icon.h | 24 ++++++++++ 7 files changed, 121 insertions(+), 28 deletions(-) create mode 100644 Telegram/SourceFiles/ui/toast/toast_lottie_icon.cpp create mode 100644 Telegram/SourceFiles/ui/toast/toast_lottie_icon.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 389bdb6fcd..5608edf262 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1724,6 +1724,8 @@ PRIVATE ui/image/image_location_factory.h ui/text/format_song_document_name.cpp ui/text/format_song_document_name.h + ui/toast/toast_lottie_icon.cpp + ui/toast/toast_lottie_icon.h ui/widgets/expandable_peer_list.cpp ui/widgets/expandable_peer_list.h ui/widgets/chat_filters_tabs_strip.cpp diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index fd89c036e5..61f7533093 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -5580,6 +5580,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_copy_date" = "Copy Date"; "lng_context_add_to_calendar" = "Add to Calendar"; "lng_context_set_reminder" = "Set a Reminder"; +"lng_reminder_scheduled_in" = "Reminder scheduled in {link}."; "lng_spellchecker_submenu" = "Spelling"; "lng_spellchecker_add" = "Add to Dictionary"; diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index c8f12e3003..bdbcc3f7dd 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "ui/boxes/confirm_box.h" #include "ui/toast/toast.h" +#include "ui/toast/toast_lottie_icon.h" #include "ui/widgets/popup_menu.h" #include "base/qthelp_regex.h" #include "base/qt/qt_key_modifiers.h" @@ -33,9 +34,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller_link_info.h" #include "apiwrap.h" #include "history/view/history_view_schedule_box.h" +#include "history/view/history_view_scheduled_section.h" #include "menu/menu_send.h" #include "data/data_types.h" #include "styles/style_calls.h" // groupCallBoxLabel +#include "styles/style_chat_helpers.h" #include "styles/style_layers.h" #include "styles/style_menu_icons.h" @@ -44,6 +47,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { +constexpr auto kReminderSetToastDuration = 4 * crl::time(1000); + [[nodiscard]] TextWithEntities BoldDomainInUrl(const QString &url) { auto result = TextWithEntities{ .text = url }; @@ -159,6 +164,42 @@ void ExportToCalendar(int32 date, const QString &messageText) { } } +void DoneSetReminder(std::shared_ptr show) { + if (!show->valid()) { + return; + } + const auto text = tr::lng_reminder_scheduled_in( + tr::now, + lt_link, + tr::link(tr::bold(tr::lng_saved_messages(tr::now))), + tr::marked); + const auto session = &show->session(); + const auto filter = [=]( + const ClickHandlerPtr &, + Qt::MouseButton) { + if (const auto controller = show->resolveWindow()) { + controller->showSection( + std::make_shared( + session->data().history(session->user()))); + } + return false; + }; + const auto toast = show->showToast({ + .text = text, + .filter = filter, + .st = &st::selfForwardsTaggerToast, + .attach = RectPart::Top, + .duration = kReminderSetToastDuration, + }); + if (const auto strong = toast.get()) { + Ui::AddLottieToToast( + strong->widget(), + st::selfForwardsTaggerToast, + st::selfForwardsTaggerIcon, + u"toast/saved_messages"_q); + } +}; + } // namespace bool UrlRequiresConfirmation(const QUrl &url) { @@ -577,7 +618,8 @@ void FormattedDateClickHandler::onClick(ClickContext context) const { Data::ResolvedForwardDraft{ .items = { item }, }, - action); + action, + [=] { DoneSetReminder(show); }); })); }, &st::menuIconNotifications); diff --git a/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.cpp b/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.cpp index 80dae68c08..9c1908f71e 100644 --- a/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.cpp +++ b/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.cpp @@ -21,13 +21,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "history/view/reactions/history_view_reactions_selector.h" #include "lang/lang_keys.h" -#include "lottie/lottie_icon.h" #include "main/main_session.h" #include "ui/rect.h" #include "ui/effects/show_animation.h" #include "ui/text/text_utilities.h" #include "ui/toast/toast_widget.h" #include "ui/toast/toast.h" +#include "ui/toast/toast_lottie_icon.h" #include "ui/widgets/buttons.h" #include "ui/widgets/popup_menu.h" #include "ui/widgets/tooltip.h" @@ -245,28 +245,11 @@ void SelfForwardsTagger::showToast( void SelfForwardsTagger::createLottieIcon( not_null widget, const QString &name) { - const auto lottieWidget = Ui::CreateChild(widget); - struct State { - std::unique_ptr lottieIcon; - }; - const auto state = lottieWidget->lifetime().make_state(); - state->lottieIcon = Lottie::MakeIcon({ - .name = name, - .sizeOverride = st::selfForwardsTaggerIcon, - }); - const auto icon = state->lottieIcon.get(); - lottieWidget->resize(st::selfForwardsTaggerIcon); - lottieWidget->move(st::selfForwardsTaggerToast.iconPosition); - lottieWidget->show(); - lottieWidget->raise(); - icon->animate( - [=] { lottieWidget->update(); }, - 0, - icon->framesCount() - 1); - lottieWidget->paintRequest() | rpl::on_next([=] { - auto p = QPainter(lottieWidget); - icon->paint(p, 0, 0); - }, lottieWidget->lifetime()); + Ui::AddLottieToToast( + widget, + st::selfForwardsTaggerToast, + st::selfForwardsTaggerIcon, + name); } void SelfForwardsTagger::showTaggedToast(DocumentId reaction) { diff --git a/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.h b/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.h index 38659ec030..4244de69fa 100644 --- a/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.h +++ b/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.h @@ -11,10 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class History; -namespace Lottie { -class Icon; -} // namespace Lottie - namespace Data { class Session; } // namespace Data diff --git a/Telegram/SourceFiles/ui/toast/toast_lottie_icon.cpp b/Telegram/SourceFiles/ui/toast/toast_lottie_icon.cpp new file mode 100644 index 0000000000..58299b8bb9 --- /dev/null +++ b/Telegram/SourceFiles/ui/toast/toast_lottie_icon.cpp @@ -0,0 +1,45 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "ui/toast/toast_lottie_icon.h" + +#include "lottie/lottie_icon.h" +#include "ui/rp_widget.h" +#include "styles/style_widgets.h" + +namespace Ui { + +void AddLottieToToast( + not_null widget, + const style::Toast &st, + QSize iconSize, + const QString &name) { + const auto lottieWidget = CreateChild(widget); + struct State { + std::unique_ptr lottieIcon; + }; + const auto state = lottieWidget->lifetime().make_state(); + state->lottieIcon = Lottie::MakeIcon({ + .name = name, + .sizeOverride = iconSize, + }); + const auto icon = state->lottieIcon.get(); + lottieWidget->resize(iconSize); + lottieWidget->move(st.iconPosition); + lottieWidget->show(); + lottieWidget->raise(); + icon->animate( + [=] { lottieWidget->update(); }, + 0, + icon->framesCount() - 1); + lottieWidget->paintRequest() | rpl::on_next([=] { + auto p = QPainter(lottieWidget); + icon->paint(p, 0, 0); + }, lottieWidget->lifetime()); +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/toast/toast_lottie_icon.h b/Telegram/SourceFiles/ui/toast/toast_lottie_icon.h new file mode 100644 index 0000000000..adb6cc89fe --- /dev/null +++ b/Telegram/SourceFiles/ui/toast/toast_lottie_icon.h @@ -0,0 +1,24 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +class QWidget; + +namespace style { +struct Toast; +} // namespace style + +namespace Ui { + +void AddLottieToToast( + not_null widget, + const style::Toast &st, + QSize iconSize, + const QString &name); + +} // namespace Ui