diff --git a/Telegram/Resources/animations/toast/tagged.tgs b/Telegram/Resources/animations/toast/tagged.tgs new file mode 100644 index 0000000000..7d2d20cfca Binary files /dev/null and b/Telegram/Resources/animations/toast/tagged.tgs differ diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 73e88c6ba3..fc8f78a47b 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4533,6 +4533,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_unlock_tags" = "Unlock"; "lng_add_tag_selector#one" = "You can add a tag to the message"; "lng_add_tag_selector#other" = "You can add a tag to the messages"; +"lng_message_tagged_with" = "Message tagged with {emoji}"; +"lng_tagged_view_saved" = "View"; "lng_context_animated_emoji" = "This message contains emoji from **{name} pack**."; "lng_context_animated_emoji_many#one" = "This message contains emoji from **{count} pack**."; diff --git a/Telegram/Resources/qrc/telegram/animations.qrc b/Telegram/Resources/qrc/telegram/animations.qrc index 1d38ee7e4a..363c9e924a 100644 --- a/Telegram/Resources/qrc/telegram/animations.qrc +++ b/Telegram/Resources/qrc/telegram/animations.qrc @@ -44,6 +44,7 @@ ../../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;