From 35378e717a40fe0b1679dc33dbb35dee52cdde4d Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 16 Dec 2021 16:35:07 +0400 Subject: [PATCH] Handle click on the reaction once again. --- .../SourceFiles/history/history_inner_widget.cpp | 12 +++++++++--- .../history/view/history_view_reactions.cpp | 14 ++++++++++++-- .../history/view/history_view_reactions.h | 6 +++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 2b0d89e56..28ffda103 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2987,8 +2987,8 @@ void HistoryInner::mouseActionUpdate() { QPoint m; adjustCurrent(point.y()); - const auto reactionItemId = _reactionsManager->lookupButtonId(point); - const auto reactionItem = session().data().message(reactionItemId); + const auto reactionState = _reactionsManager->buttonTextState(point); + const auto reactionItem = session().data().message(reactionState.itemId); const auto reactionView = reactionItem ? reactionItem->mainView() : nullptr; @@ -3034,7 +3034,13 @@ void HistoryInner::mouseActionUpdate() { && (view == App::hoveredItem()) && !_selected.empty() && (_selected.cbegin()->second != FullSelection); - if (point.y() < _historyPaddingTop) { + if (reactionView && reactionState.link) { + dragState = reactionState; + lnkhost = reactionView; + _reactionsManager->showSelector([=](QPoint local) { + return mapToGlobal(local); + }); + } else if (point.y() < _historyPaddingTop) { if (_botAbout && !_botAbout->info->text.isEmpty() && _botAbout->height > 0) { dragState = TextState(nullptr, _botAbout->info->text.getState( point - _botAbout->rect.topLeft() - QPoint(st::msgPadding.left(), st::msgPadding.top() + st::botDescSkip + st::msgNameFont->height), diff --git a/Telegram/SourceFiles/history/view/history_view_reactions.cpp b/Telegram/SourceFiles/history/view/history_view_reactions.cpp index 4727d9c7a..6f1116f2c 100644 --- a/Telegram/SourceFiles/history/view/history_view_reactions.cpp +++ b/Telegram/SourceFiles/history/view/history_view_reactions.cpp @@ -376,6 +376,14 @@ Manager::Manager(QWidget *selectorParent, Fn buttonUpdate) st::reactionCornerSize.width(), st::reactionCornerSize.height())) , _buttonUpdate(std::move(buttonUpdate)) +, _buttonLink(std::make_shared(crl::guard(this, [=] { + if (_buttonContext && !_list.empty()) { + _chosen.fire({ + .context = _buttonContext, + .emoji = _list.front().emoji, + }); + } +}))) , _selectorParent(selectorParent) { const auto ratio = style::DevicePixelRatio(); _cacheInOut = QImage( @@ -468,14 +476,16 @@ void Manager::paintButtons(Painter &p, const PaintContext &context) { } } -FullMsgId Manager::lookupButtonId(QPoint position) const { +TextState Manager::buttonTextState(QPoint position) const { if (const auto current = _button.get()) { const auto geometry = current->geometry(); if (geometry.contains(position)) { const auto maxInner = QRect({}, CountMaxSizeWithMargins({})); const auto shift = geometry.center() - maxInner.center(); if (maxInner.translated(shift).contains(position)) { - return _buttonContext; + auto result = TextState(nullptr, _buttonLink); + result.itemId = _buttonContext; + return result; } } } diff --git a/Telegram/SourceFiles/history/view/history_view_reactions.h b/Telegram/SourceFiles/history/view/history_view_reactions.h index 1659cba99..acaa56a33 100644 --- a/Telegram/SourceFiles/history/view/history_view_reactions.h +++ b/Telegram/SourceFiles/history/view/history_view_reactions.h @@ -28,7 +28,6 @@ namespace HistoryView { using PaintContext = Ui::ChatPaintContext; enum class PointState : char; struct TextState; -struct StateRequest; class Message; } // namespace HistoryView @@ -149,7 +148,7 @@ private: }; -class Manager final { +class Manager final : public base::has_weak_ptr { public: Manager(QWidget *selectorParent, Fn buttonUpdate); ~Manager(); @@ -158,7 +157,7 @@ public: void showButton(ButtonParameters parameters); void paintButtons(Painter &p, const PaintContext &context); - [[nodiscard]] FullMsgId lookupButtonId(QPoint position) const; + [[nodiscard]] TextState buttonTextState(QPoint position) const; void showSelector(Fn mapToGlobal); void showSelector(FullMsgId context, QRect globalButtonArea); @@ -227,6 +226,7 @@ private: std::unique_ptr