From 338183e647f1a83a732dc32374a855c6937cd2ee Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 7 Oct 2025 18:27:34 +0300 Subject: [PATCH] Added toast after successfully tagging of recent forwards to self. --- .../Resources/animations/toast/tagged.tgs | Bin 0 -> 1765 bytes Telegram/Resources/langs/lang.strings | 2 + .../Resources/qrc/telegram/animations.qrc | 1 + .../history_view_self_forwards_tagger.cpp | 77 ++++++++++++++++-- .../view/history_view_self_forwards_tagger.h | 7 +- 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 Telegram/Resources/animations/toast/tagged.tgs diff --git a/Telegram/Resources/animations/toast/tagged.tgs b/Telegram/Resources/animations/toast/tagged.tgs new file mode 100644 index 0000000000000000000000000000000000000000..7d2d20cfca90cefdc0eb1f0a9cba76bf184466f6 GIT binary patch literal 1765 zcmV1+-fxE7U0Pn*X_~@-R~nKZ=lRX7J`RVs`{A6_@aJ$o1Rb;; z)Ns8U&ZAMo?c;Ec#{(WAso^g?$g1I{J@4P+%&*_RIs5VZpMN@YICyz^DJQo3{nY`u zn+rAEZ9iP?`18kk`Su=9031FH=YGQ3zCHWy;qn7e_B+w&9S(gQcKmN!1p;!*g1_<6 z=mdB`Z0O<>v|Qw_$qma7a+Vbs$wWxL3?fzx8@?35rb!F;41zur!!?Zj*$B2ALHJ1x zFBp)7W*T9MP_UjKBE1zgincZ= zt8FA@p4c^AxO$m3xwO#uc4Ll;LY~n1PH%Mf1()ia;&LgHd5rK)_%|1}D295OBj{Y> za+Oh|TW&DQJjbTjz}*CHjk31%;N}akfzW~b9z3R3!8tR0cOuPu0x$#7t;JxDv_j!Aelq;R8wl^~v9;Xa|;t5xH0hf+m7i3FVe&!$-Q0RrLE>Fl_LY;25tDnnop83(sG z)`|#AF3wy2bD~f>_J;`$99z@cYY&@zxERqQtAl&u6b2a^N(C7i z#kZtSPQi5J1XJf=`Htk=;u(AejQ}^Y@6ictWUIY)d?-736Ip`bCUJ`?IF3Z32u+^5 zg&Ff{Rg18V=@`TP;@c6bv4%xQsn{mXx+siL`9vTinuwDKq_E`8 z2;;MXd-zd0vGynnP%fx~^*~=>C%cH;li~mwqbE6xFJV6AvFL?77|2E}1fdTOCQqPa1QS>0lWMdinOG#uL?ALEm0`44G-lYwkuwNA z2OhNzzv3Dv_a+b?m@P(NONWGJiK`?d^5LtuGPo)!xYaHW;+7ryy5X`4++g6&KEm9W z(PvB_U1TRh?y0QDw{95w9jibnHLyM69Z#zzs*hFoIgT-FN{#b{3rMCTgd{@ZsSXFk zjV2*AgET1g4epm5>M9@*h36j2y+TaJxI@U0pwLupkQPK9HHeG=4q55-8QnE1q(hL2 zs8}hPfOn6?Cs?_Rw+ZB)M^pRSU0D19^NU~e87HaDN_eBlOn{M$GZhs{T~JYKNN>sD zU^`MqNk-#&G>i7--~!p1j)pO(nq2#RE=xR-1jr^O!vXJ3Q5X;YHF5zf5G~IGHl(AV zS1aeB2QKCy6LAT3;DJ><@FZT5pfA;1ix*@eLsIcfX0=o!kFr1q)#jQ9@LERDQN-E! zni;UpfgEvxq(Sg9#1{lTvYG{l@eT}YytH|KV{|-=B1?Svj2S~LEBt=tN3sJv1DFB zhk&g90QK8@kqZ6~w|95X=QP1T@Z0U../../animations/camera_outline.tgs ../../animations/photo_suggest_icon.tgs ../../animations/toast/saved_messages.tgs + ../../animations/toast/tagged.tgs ../../animations/dice/dice_idle.tgs ../../animations/dice/dart_idle.tgs 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 6c31baa489..15ecec7479 100644 --- a/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.cpp +++ b/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/ui_integration.h" #include "data/data_session.h" #include "data/data_user.h" +#include "data/stickers/data_custom_emoji.h" #include "history/history.h" #include "history/history_item.h" #include "history/view/reactions/history_view_reactions_selector.h" @@ -25,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "ui/toast/toast_widget.h" #include "ui/toast/toast.h" +#include "ui/widgets/buttons.h" #include "ui/widgets/tooltip.h" #include "window/window_session_controller.h" #include "styles/style_chat.h" @@ -141,14 +143,16 @@ void SelfForwardsTagger::showSelectorForMessages( ) | rpl::start_with_next([=](ChosenReaction reaction) { selector->setAttribute(Qt::WA_TransparentForMouseEvents); for (const auto &id : ids) { - if (const auto item = _controller->session().data().message( - id)) { + if (const auto item = _controller->session().data().message(id)) { item->toggleReaction( reaction.id, HistoryReactionSource::Selector); } } hideAndDestroy(); + base::call_delayed(st::defaultToggle.duration, _parent, [=] { + showTaggedToast(reaction.id.custom()); + }); }, selector->lifetime()); const auto eventFilterCallback = [=](not_null event) { @@ -234,7 +238,7 @@ void SelfForwardsTagger::showToast( }); if (const auto strong = _toast.get()) { const auto widget = strong->widget(); - createLottieIcon(widget); + createLottieIcon(widget, u"toast/saved_messages"_q); if (callback) { QObject::connect(widget, &QObject::destroyed, callback); } @@ -244,14 +248,15 @@ void SelfForwardsTagger::showToast( } void SelfForwardsTagger::createLottieIcon( - not_null widget) { + 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 = u"toast/saved_messages"_q, + .name = name, .sizeOverride = st::selfForwardsTaggerIcon, }); const auto icon = state->lottieIcon.get(); @@ -269,6 +274,68 @@ void SelfForwardsTagger::createLottieIcon( }, lottieWidget->lifetime()); } +void SelfForwardsTagger::showTaggedToast(DocumentId reaction) { + auto text = tr::lng_message_tagged_with( + tr::now, + lt_emoji, + Data::SingleCustomEmoji(reaction), + Ui::Text::WithEntities); + hideToast(); + + const auto &st = st::selfForwardsTaggerToast; + const auto viewText = tr::lng_tagged_view_saved(tr::now); + const auto viewFont = st::historyPremiumViewSet.style.font; + const auto rightSkip = viewFont->width(viewText) + + st::toastUndoSpace; + + _toast = Ui::Toast::Show(_scroll, Ui::Toast::Config{ + .text = text, + .textContext = Core::TextContext({ + .session = &_controller->session(), + }), + .padding = rpl::single(QMargins(0, 0, rightSkip, 0)), + .st = &st, + .attach = RectPart::Top, + .acceptinput = true, + .duration = crl::time(3000), + }); + if (const auto strong = _toast.get()) { + const auto widget = strong->widget(); + createLottieIcon(widget, u"toast/tagged"_q); + + const auto button = Ui::CreateChild(widget.get()); + button->setClickedCallback([=] { + _controller->showPeerHistory(_controller->session().user()); + hideToast(); + }); + + button->paintRequest() | rpl::start_with_next([=] { + auto p = QPainter(button); + const auto font = st::historyPremiumViewSet.style.font; + const auto top = (button->height() - font->height) / 2; + p.setPen(st::historyPremiumViewSet.textFg); + p.setFont(font); + p.drawText(0, top + font->ascent, viewText); + }, button->lifetime()); + + button->resize( + viewFont->width(viewText), + st::historyPremiumViewSet.height); + + rpl::combine( + widget->sizeValue(), + button->sizeValue() + ) | rpl::start_with_next([=](const QSize &outer, const QSize &inner) { + button->moveToRight( + st.padding.right(), + (outer.height() - inner.height()) / 2, + outer.width()); + }, widget->lifetime()); + + button->show(); + } +} + void SelfForwardsTagger::hideToast() { if (const auto strong = _toast.get()) { strong->hideAnimated(); 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 a0dfda8928..df340472dc 100644 --- a/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.h +++ b/Telegram/SourceFiles/history/view/history_view_self_forwards_tagger.h @@ -35,6 +35,10 @@ namespace Ui::Toast { class Instance; } // namespace Ui::Toast +namespace Reactions { +struct ChosenReaction; +} // namespace Reactions + namespace HistoryView { class SelfForwardsTagger final : public base::has_weak_ptr { @@ -52,7 +56,8 @@ private: void setup(); void showSelectorForMessages(const MessageIdsList &ids); void showToast(const TextWithEntities &text, Fn callback); - void createLottieIcon(not_null widget); + void showTaggedToast(DocumentId); + void createLottieIcon(not_null widget, const QString &name); void hideToast(); [[nodiscard]] QRect toastGeometry() const;