From 475b2ac739fb4c495c4e46ef71588768afd1ad55 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 31 Oct 2023 09:01:01 +0400 Subject: [PATCH] Fix external quote-reply to topic message. --- .../history/view/history_view_list_widget.cpp | 1 + .../history/view/history_view_list_widget.h | 1 + .../history/view/history_view_message.cpp | 4 +++- .../view/history_view_replies_section.cpp | 19 +++++++++++++------ .../view/history_view_replies_section.h | 9 +++++++-- .../window/window_session_controller.cpp | 3 ++- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 821cab1519..07f63ce4fc 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -2090,6 +2090,7 @@ void ListWidget::paintEvent(QPaintEvent *e) { }); auto context = preparePaintContext(clip); + context.highlightPathCache = &_highlightPathCache; if (from == end(_items)) { _delegate->listPaintEmpty(p, context); return; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index c12ae113c3..fd56b9313f 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -649,6 +649,7 @@ private: base::flat_map _hiddenSenderUserpics; const std::unique_ptr _pathGradient; + QPainterPath _highlightPathCache; base::unique_qptr _emptyInfo = nullptr; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index c7d532d27e..cf2d82973c 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1123,6 +1123,8 @@ void Message::draw(Painter &p, const PaintContext &context) const { const auto mediaSelection = _invertMedia ? context.selection : skipTextSelection(context.selection); + const auto maybeMediaHighlight = context.highlightPathCache + && context.highlightPathCache->isEmpty(); auto mediaPosition = QPoint(inner.left(), top); p.translate(mediaPosition); media->draw(p, context.translated( @@ -1135,7 +1137,7 @@ void Message::draw(Painter &p, const PaintContext &context) const { context.reactionInfo->effectOffset -= add; } } - if (context.highlightPathCache + if (maybeMediaHighlight && !context.highlightPathCache->isEmpty()) { context.highlightPathCache->translate(mediaPosition); } diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index f67568e1b9..32983df4da 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -128,10 +128,12 @@ rpl::producer RootViewContent( RepliesMemento::RepliesMemento( not_null history, MsgId rootId, - MsgId highlightId) + MsgId highlightId, + const TextWithEntities &highlightPart) : _history(history) , _rootId(rootId) -, _highlightId(highlightId) { +, _highlightId(highlightId) +, _highlightPart(highlightPart) { if (highlightId) { _list.setAroundPosition({ .fullId = FullMsgId(_history->peer->id, highlightId), @@ -1966,7 +1968,7 @@ bool RepliesWidget::showInternal( if (logMemento->getHistory() == history() && logMemento->getRootId() == _rootId) { restoreState(logMemento); - if (!logMemento->getHighlightId()) { + if (!logMemento->highlightId()) { showAtPosition(Data::UnreadMessagePosition); } if (params.reapplyLocalDraft) { @@ -2033,7 +2035,8 @@ bool RepliesWidget::showMessage( if (!originMessage) { return false; } - const auto originItemId = (_cornerButtons.replyReturn() != originMessage) + const auto currentReplyReturn = _cornerButtons.replyReturn(); + const auto originItemId = (currentReplyReturn != originMessage) ? originMessage->fullId() : FullMsgId(); showAtPosition(message->position(), originItemId, params); @@ -2138,11 +2141,15 @@ void RepliesWidget::restoreState(not_null memento) { } _cornerButtons.setReplyReturns(memento->replyReturns()); _inner->restoreState(memento->list()); - if (const auto highlight = memento->getHighlightId()) { + if (const auto highlight = memento->highlightId()) { + auto params = Window::SectionShow( + Window::SectionShow::Way::Forward, + anim::type::instant); + params.highlightPart = memento->highlightPart(); showAtPosition(Data::MessagePosition{ .fullId = FullMsgId(_history->peer->id, highlight), .date = TimeId(0), - }, {}, { Window::SectionShow::Way::Forward, anim::type::instant }); + }, {}, params); } } diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index cea3726145..e8d3e61398 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -380,7 +380,8 @@ public: RepliesMemento( not_null history, MsgId rootId, - MsgId highlightId = 0); + MsgId highlightId = 0, + const TextWithEntities &highlightPart = {}); explicit RepliesMemento( not_null commentsItem, MsgId commentId = 0); @@ -424,9 +425,12 @@ public: [[nodiscard]] not_null list() { return &_list; } - [[nodiscard]] MsgId getHighlightId() const { + [[nodiscard]] MsgId highlightId() const { return _highlightId; } + [[nodiscard]] const TextWithEntities &highlightPart() const { + return _highlightPart; + } private: void setupTopicViewer(); @@ -434,6 +438,7 @@ private: const not_null _history; MsgId _rootId = 0; const MsgId _highlightId = 0; + const TextWithEntities _highlightPart; ListMemento _list; std::shared_ptr _replies; QVector _replyReturns; diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 71de8d7b1b..3fbfd8145b 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -850,7 +850,8 @@ void SessionNavigation::showRepliesForMessage( auto memento = std::make_shared( history, rootId, - commentId); + commentId, + params.highlightPart); memento->setFromTopic(topic); showSection(std::move(memento), params); return;