diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 23f8dac4eb..7e56c73c22 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -671,6 +671,8 @@ PRIVATE history/view/history_view_send_action.h history/view/history_view_service_message.cpp history/view/history_view_service_message.h + history/view/history_view_spoiler_click_handler.cpp + history/view/history_view_spoiler_click_handler.h history/view/history_view_top_bar_widget.cpp history/view/history_view_top_bar_widget.h history/view/history_view_view_button.cpp diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index c2504a29fa..7d79a55ebf 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -673,6 +673,11 @@ void InnerWidget::elementStartInteraction(not_null view) { void InnerWidget::elementShowReactions(not_null view) { } +void InnerWidget::elementShowSpoilerAnimation() { + _spoilerOpacity.stop(); + _spoilerOpacity.start([=] { update(); }, 0., 1., st::fadeWrapDuration); +} + void InnerWidget::saveState(not_null memento) { memento->setFilter(std::move(_filter)); memento->setAdmins(std::move(_admins)); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index 4c4e73efad..9d6b12eeb6 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -141,6 +141,7 @@ public: not_null view) override; void elementShowReactions( not_null view) override; + void elementShowSpoilerAnimation() override; ~InnerWidget(); @@ -324,6 +325,8 @@ private: QPoint _trippleClickPoint; base::Timer _trippleClickTimer; + Ui::Animations::Simple _spoilerOpacity; + FilterValue _filter; QString _searchQuery; std::vector> _admins; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 304eaa28d7..8904c45afa 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2903,6 +2903,11 @@ void HistoryInner::elementShowReactions(not_null view) { view->data())); } +void HistoryInner::elementShowSpoilerAnimation() { + _spoilerOpacity.stop(); + _spoilerOpacity.start([=] { update(); }, 0., 1., st::fadeWrapDuration); +} + auto HistoryInner::getSelectionState() const -> HistoryView::TopBarWidget::SelectedState { auto result = HistoryView::TopBarWidget::SelectedState {}; @@ -3862,6 +3867,11 @@ not_null HistoryInner::ElementDelegate() { Instance->elementShowReactions(view); } } + void elementShowSpoilerAnimation() override { + if (Instance) { + Instance->elementShowSpoilerAnimation(); + } + } }; diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 988e932495..3dd0c34993 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -126,6 +126,7 @@ public: void elementReplyTo(const FullMsgId &to); void elementStartInteraction(not_null view); void elementShowReactions(not_null view); + void elementShowSpoilerAnimation(); void updateBotInfo(bool recount = true); @@ -446,6 +447,8 @@ private: crl::time _touchTime = 0; base::Timer _touchScrollTimer; + Ui::Animations::Simple _spoilerOpacity; + base::unique_qptr _menu; bool _scrollDateShown = false; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 3b380d248c..95265945ec 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_service.h" #include "history/view/history_view_service_message.h" #include "history/view/history_view_context_menu.h" // CopyPostLink. +#include "history/view/history_view_spoiler_click_handler.h" #include "history/view/media/history_view_media.h" // AddTimestampLinks. #include "chat_helpers/stickers_emoji_pack.h" #include "main/main_session.h" @@ -1618,6 +1619,7 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) { withLocalEntities(textWithEntities), Ui::ItemTextOptions(this), context); + HistoryView::FillTextWithAnimatedSpoilers(_text, textWithEntities); if (!textWithEntities.text.isEmpty() && _text.isEmpty()) { // If server has allowed some text that we've trim-ed entirely, // just replace it with something so that UI won't look buggy. diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 875ff1806e..6192b8f63c 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -191,6 +191,9 @@ void SimpleElementDelegate::elementShowReactions( not_null view) { } +void SimpleElementDelegate::elementShowSpoilerAnimation() { +} + TextSelection UnshiftItemSelection( TextSelection selection, uint16 byLength) { diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index a985df3029..f1eff74e33 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -100,6 +100,7 @@ public: virtual void elementReplyTo(const FullMsgId &to) = 0; virtual void elementStartInteraction(not_null view) = 0; virtual void elementShowReactions(not_null view) = 0; + virtual void elementShowSpoilerAnimation() = 0; virtual ~ElementDelegate() { } @@ -158,6 +159,7 @@ public: void elementReplyTo(const FullMsgId &to) override; void elementStartInteraction(not_null view) override; void elementShowReactions(not_null view) override; + void elementShowSpoilerAnimation() override; protected: [[nodiscard]] not_null controller() const { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index a3d17e04b0..d93bcc1681 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1461,6 +1461,11 @@ void ListWidget::elementStartInteraction(not_null view) { void ListWidget::elementShowReactions(not_null view) { } +void ListWidget::elementShowSpoilerAnimation() { + _spoilerOpacity.stop(); + _spoilerOpacity.start([=] { update(); }, 0., 1., st::fadeWrapDuration); +} + void ListWidget::saveState(not_null memento) { memento->setAroundPosition(_aroundPosition); auto state = countScrollState(); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 33a781691b..8fe56d6b9f 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -279,6 +279,7 @@ public: void elementReplyTo(const FullMsgId &to) override; void elementStartInteraction(not_null view) override; void elementShowReactions(not_null view) override; + void elementShowSpoilerAnimation() override; void setEmptyInfoWidget(base::unique_qptr &&w); @@ -608,6 +609,8 @@ private: FullMsgId _highlightedMessageId; base::Timer _highlightTimer; + Ui::Animations::Simple _spoilerOpacity; + Ui::SelectScrollManager _selectScroll; rpl::event_stream _requestedToEditMessage; diff --git a/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp b/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp new file mode 100644 index 0000000000..f7243a5e00 --- /dev/null +++ b/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp @@ -0,0 +1,53 @@ +/* +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 "history/view/history_view_spoiler_click_handler.h" + +#include "core/click_handler_types.h" // ClickHandlerContext +#include "history/view/history_view_element.h" +#include "ui/spoiler_click_handler.h" + +namespace HistoryView { +namespace { + +class AnimatedSpoilerClickHandler final : public SpoilerClickHandler { +public: + AnimatedSpoilerClickHandler() = default; + + void onClick(ClickContext context) const override; + +}; + +void AnimatedSpoilerClickHandler::onClick(ClickContext context) const { + const auto button = context.button; + if (button != Qt::LeftButton) { + return; + } + const auto my = context.other.value(); + if (const auto d = my.elementDelegate ? my.elementDelegate() : nullptr) { + d->elementShowSpoilerAnimation(); + const auto nonconst = const_cast(this); + nonconst->setStartMs(crl::now()); + SpoilerClickHandler::onClick({}); + } +} + +} // namespace + +void FillTextWithAnimatedSpoilers( + Ui::Text::String &text, + const TextWithEntities &textWithEntities) { + for (auto i = 0; i < textWithEntities.entities.size(); i++) { + if (textWithEntities.entities[i].type() == EntityType::Spoiler) { + text.setSpoiler( + i + 1, + std::make_shared()); + } + } +} + +} // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.h b/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.h new file mode 100644 index 0000000000..37ebf09c30 --- /dev/null +++ b/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.h @@ -0,0 +1,16 @@ +/* +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 + +namespace HistoryView { + +void FillTextWithAnimatedSpoilers( + Ui::Text::String &text, + const TextWithEntities &textWithEntities); + +} // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/media/history_view_media.cpp b/Telegram/SourceFiles/history/view/media/history_view_media.cpp index 4a2e317c05..eecc636023 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item.h" #include "history/view/history_view_element.h" #include "history/view/history_view_cursor_state.h" +#include "history/view/history_view_spoiler_click_handler.h" #include "lottie/lottie_single_player.h" #include "storage/storage_shared_media.h" #include "data/data_document.h" @@ -196,11 +197,13 @@ Ui::Text::String Media::createCaption(not_null item) const { const auto context = Core::MarkedTextContext{ .session = &history()->session() }; + const auto textWithEntities = item->originalTextWithLocalEntities(); result.setMarkedText( st::messageTextStyle, - item->originalTextWithLocalEntities(), + textWithEntities, Ui::ItemTextOptions(item), context); + FillTextWithAnimatedSpoilers(result, textWithEntities); if (const auto width = _parent->skipBlockWidth()) { result.updateSkipBlock(width, _parent->skipBlockHeight()); }