From d7539349c7eaf11ab931459cec9a2d699c45c626 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 6 Nov 2023 12:35:08 +0400 Subject: [PATCH] Always show manual quote replies, hide redundant. --- .../history/history_inner_widget.cpp | 6 ++++- .../history/view/history_view_element.cpp | 12 ++-------- .../history/view/history_view_element.h | 1 - .../history/view/history_view_message.cpp | 3 +-- .../view/history_view_pinned_section.cpp | 6 ++++- .../view/history_view_replies_section.cpp | 22 +++++++++++++++++-- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index eee1ff08d..bc8b0b09b 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -260,7 +260,11 @@ public: return _widget ? _widget->elementAnimationsPaused() : false; } bool elementHideReply(not_null view) override { - return view->isTopicRootReply(); + if (!view->isTopicRootReply()) { + return false; + } + const auto reply = view->data()->Get(); + return reply && !reply->fields().manualQuote; } bool elementShownUnread(not_null view) override { return view->data()->unread(view->data()->history()); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 329ed41f3..1ba437586 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -498,7 +498,8 @@ Element::Element( | Flag::NeedsResize | (IsItemScheduledUntilOnline(data) ? Flag::ScheduledUntilOnline - : Flag())) + : Flag()) + | (countIsTopicRootReply() ? Flag::TopicRootReply : Flag())) , _context(delegate->elementContext()) { history()->owner().registerItemView(this); refreshMedia(replacing); @@ -1260,15 +1261,6 @@ QSize Element::countCurrentSize(int newWidth) { return performCountCurrentSize(newWidth); } -void Element::refreshIsTopicRootReply() { - const auto topicRootReply = countIsTopicRootReply(); - if (topicRootReply) { - _flags |= Flag::TopicRootReply; - } else { - _flags &= ~Flag::TopicRootReply; - } -} - bool Element::countIsTopicRootReply() const { const auto item = data(); if (!item->history()->isForum()) { diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 4da9f4b9c..a5e7a86a4 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -565,7 +565,6 @@ protected: void clearSpecialOnlyEmoji(); void checkSpecialOnlyEmoji(); - void refreshIsTopicRootReply(); private: // This should be called only from previousInBlocksChanged() diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 115b2e76c..d34e41722 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -601,7 +601,7 @@ QSize Message::performCountOptimalSize() { const auto item = data(); const auto replyData = item->Get(); - if (replyData) { + if (replyData && !_hideReply) { AddComponents(Reply::Bit()); } else { RemoveComponents(Reply::Bit()); @@ -616,7 +616,6 @@ QSize Message::performCountOptimalSize() { : 2; }; const auto oldKey = reactionsKey(); - refreshIsTopicRootReply(); validateText(); validateInlineKeyboard(markup); updateViewButtonExistence(); diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index 0472e4eb1..017289a0b 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -597,7 +597,11 @@ void PinnedWidget::listUpdateDateLink( } bool PinnedWidget::listElementHideReply(not_null view) { - return (view->data()->replyToId() == _thread->topicRootId()); + if (const auto reply = view->data()->Get()) { + return !reply->fields().manualQuote + && (reply->messageId() == _thread->topicRootId()); + } + return false; } bool PinnedWidget::listElementShownUnread(not_null view) { diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index c652ab2e8..1c30b39cd 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -2020,7 +2020,7 @@ bool RepliesWidget::showMessage( } const auto id = FullMsgId(_history->peer->id, messageId); const auto message = _history->owner().message(id); - if (!message || !message->inThread(_rootId)) { + if (!message || (!message->inThread(_rootId) && id.msg != _rootId)) { return false; } const auto originMessage = [&]() -> HistoryItem* { @@ -2516,7 +2516,25 @@ void RepliesWidget::listUpdateDateLink( } bool RepliesWidget::listElementHideReply(not_null view) { - return (view->data()->replyToId() == _rootId); + if (const auto reply = view->data()->Get()) { + const auto replyToPeerId = reply->externalPeerId() + ? reply->externalPeerId() + : _history->peer->id; + if (reply->fields().manualQuote) { + return false; + } else if (replyToPeerId == _history->peer->id) { + return (reply->messageId() == _rootId); + } else if (_root) { + const auto forwarded = _root->Get(); + if (forwarded + && forwarded->savedFromPeer + && forwarded->savedFromPeer->id == replyToPeerId + && forwarded->savedFromMsgId == reply->messageId()) { + return true; + } + } + } + return false; } bool RepliesWidget::listElementShownUnread(not_null view) {