From e37866d0b9347c3343a492d53ddd15dcc2fef162 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 17 Apr 2022 12:33:29 +0300 Subject: [PATCH] Added animated reactions in manage of groups / channels. --- .../boxes/peers/edit_peer_reactions.cpp | 92 ++++--------------- .../boxes/peers/edit_peer_reactions.h | 6 +- .../boxes/reactions_settings_box.cpp | 5 +- .../boxes/reactions_settings_box.h | 5 - Telegram/SourceFiles/info/info.style | 4 +- .../SourceFiles/settings/settings_chat.cpp | 1 - 6 files changed, 27 insertions(+), 86 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp index c571ebdd5..70f4da475 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp @@ -7,92 +7,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/peers/edit_peer_reactions.h" +#include "boxes/reactions_settings_box.h" // AddReactionLottieIcon #include "data/data_message_reactions.h" -#include "data/data_document.h" -#include "data/data_document_media.h" #include "data/data_peer.h" #include "data/data_chat.h" #include "data/data_channel.h" #include "data/data_session.h" #include "main/main_session.h" #include "apiwrap.h" -#include "lottie/lottie_icon.h" #include "lang/lang_keys.h" +#include "ui/layers/generic_box.h" #include "ui/widgets/buttons.h" #include "info/profile/info_profile_icon.h" #include "settings/settings_common.h" #include "styles/style_settings.h" #include "styles/style_info.h" -namespace { - -using Data::Reaction; - -void AddReactionIcon( - not_null button, - not_null document) { - struct State { - std::shared_ptr media; - std::unique_ptr icon; - QImage image; - }; - - const auto size = st::editPeerReactionsPreview; - const auto state = button->lifetime().make_state(State{ - .media = document->createMediaView(), - }); - const auto icon = Ui::CreateChild(button.get()); - icon->setAttribute(Qt::WA_TransparentForMouseEvents); - icon->resize(size, size); - button->sizeValue( - ) | rpl::start_with_next([=](QSize size) { - icon->moveToLeft( - st::editPeerReactionsIconLeft, - (size.height() - icon->height()) / 2, - size.width()); - }, icon->lifetime()); - - const auto initLottie = [=] { - state->icon = Lottie::MakeIcon({ - .path = state->media->owner()->filepath(true), - .json = state->media->bytes(), - .sizeOverride = QSize(size, size), - .frame = -1, - }); - state->media = nullptr; - }; - state->media->checkStickerLarge(); - if (state->media->loaded()) { - initLottie(); - } else { - document->session().downloaderTaskFinished( - ) | rpl::filter([=] { - return state->media->loaded(); - }) | rpl::take(1) | rpl::start_with_next([=] { - initLottie(); - icon->update(); - }, icon->lifetime()); - } - - icon->paintRequest( - ) | rpl::start_with_next([=] { - QPainter p(icon); - if (state->image.isNull() && state->icon) { - state->image = state->icon->frame(); - crl::async([icon = std::move(state->icon)]{}); - } - if (!state->image.isNull()) { - p.drawImage(QRect(0, 0, size, size), state->image); - } - }, icon->lifetime()); -} - -} // namespace - void EditAllowedReactionsBox( not_null box, bool isGroup, - const std::vector &list, + const std::vector &list, const base::flat_set &selected, Fn &)> callback) { box->setTitle(tr::lng_manage_peer_reactions()); @@ -153,9 +87,23 @@ void EditAllowedReactionsBox( container, rpl::single(entry.title), st::manageGroupButton.button); - AddReactionIcon(button, entry.centerIcon - ? entry.centerIcon - : entry.appearAnimation.get()); + const auto iconHeight = st::editPeerReactionsPreview; + AddReactionLottieIcon( + button, + button->sizeValue( + ) | rpl::map([=](const QSize &size) { + return QPoint( + st::editPeerReactionsIconLeft, + (size.height() - iconHeight) / 2); + }), + iconHeight, + entry, + button->events( + ) | rpl::filter([=](not_null event) { + return event->type() == QEvent::Enter; + }) | rpl::to_empty, + rpl::never<>(), + &button->lifetime()); state->toggles.emplace(entry.emoji, button); button->toggleOn(rpl::single( active(entry) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.h b/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.h index 3feed5cf0..e8dc6f19d 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.h @@ -7,14 +7,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "ui/layers/generic_box.h" - class PeerData; namespace Data { struct Reaction; } // namespace Data +namespace Ui { +class GenericBox; +} // namespace Ui + void EditAllowedReactionsBox( not_null box, bool isGroup, diff --git a/Telegram/SourceFiles/boxes/reactions_settings_box.cpp b/Telegram/SourceFiles/boxes/reactions_settings_box.cpp index 19cbd9064..0c479cb56 100644 --- a/Telegram/SourceFiles/boxes/reactions_settings_box.cpp +++ b/Telegram/SourceFiles/boxes/reactions_settings_box.cpp @@ -234,7 +234,6 @@ void AddMessage( (rightSize.height() - iconSize) / 2); }), iconSize, - &controller->session(), r, rpl::never<>(), rpl::duplicate(emojiValue) | rpl::skip(1) | rpl::to_empty, @@ -251,7 +250,6 @@ void AddReactionLottieIcon( not_null parent, rpl::producer iconPositionValue, int iconSize, - not_null session, const Data::Reaction &reaction, rpl::producer<> &&selects, rpl::producer<> &&destroys, @@ -280,7 +278,7 @@ void AddReactionLottieIcon( state->appear.media->checkStickerLarge(); state->select.media->checkStickerLarge(); rpl::single() | rpl::then( - session->downloaderTaskFinished() + reaction.appearAnimation->session().downloaderTaskFinished() ) | rpl::start_with_next([=] { const auto check = [&](State::Entry &entry) { if (!entry.media) { @@ -448,7 +446,6 @@ void ReactionsSettingsBox( (s.height() - iconSize) / 2); }), iconSize, - &controller->session(), r, button->events( ) | rpl::filter([=](not_null event) { diff --git a/Telegram/SourceFiles/boxes/reactions_settings_box.h b/Telegram/SourceFiles/boxes/reactions_settings_box.h index 33cbe5369..bc2b2d48d 100644 --- a/Telegram/SourceFiles/boxes/reactions_settings_box.h +++ b/Telegram/SourceFiles/boxes/reactions_settings_box.h @@ -16,10 +16,6 @@ namespace Window { class SessionController; } // namespace Window -namespace Main { -class Session; -} // namespace Main - namespace Data { struct Reaction; } // namespace Data @@ -28,7 +24,6 @@ void AddReactionLottieIcon( not_null parent, rpl::producer iconPositionValue, int iconSize, - not_null session, const Data::Reaction &reaction, rpl::producer<> &&selects, rpl::producer<> &&destroys, diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index 7f64c09ea..0dc0f5ee0 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -657,8 +657,8 @@ editPeerInviteLinkBoxBottomSkip: 15px; editPeerReactionsButton: SettingsButton(infoProfileButton) { padding: margins(59px, 13px, 8px, 11px); } -editPeerReactionsPreview: 48px; -editPeerReactionsIconLeft: 12px; +editPeerReactionsPreview: 24px; +editPeerReactionsIconLeft: 21px; historyTopBarBack: IconButton(infoTopBarBack) { width: 52px; diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 839fdc89d..5c4bdaafc 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -903,7 +903,6 @@ void SetupMessages( r.top() + (r.height() - iconSize) / 2); }), iconSize, - &controller->session(), r, buttonRight->events( ) | rpl::filter([=](not_null event) {