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 b3307a00f..003316997 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -591,6 +591,10 @@ bool InnerWidget::elementIsGifPaused() { return _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any); } +bool InnerWidget::elementHideReply(not_null view) { + return true; +} + 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 f3c90b493..bb35ce57b 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -112,6 +112,8 @@ public: const TextWithEntities &text, Fn hiddenCallback) override; bool elementIsGifPaused() override; + bool elementHideReply( + not_null view) override; ~InnerWidget(); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 95a72f462..2e3503491 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -3368,7 +3368,9 @@ not_null HistoryInner::ElementDelegate() { bool elementIsGifPaused() override { return Instance ? Instance->elementIsGifPaused() : false; } - + bool elementHideReply(not_null view) override { + return false; + } }; static Result result; diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 7963dcfaa..55051f424 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -112,6 +112,10 @@ bool SimpleElementDelegate::elementIsGifPaused() { return _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any); } +bool SimpleElementDelegate::elementHideReply(not_null view) { + return false; +} + TextSelection UnshiftItemSelection( TextSelection selection, uint16 byLength) { @@ -605,6 +609,10 @@ TimeId Element::displayedEditDate() const { return TimeId(0); } +HistoryMessageReply *Element::displayedReply() const { + return nullptr; +} + bool Element::hasVisibleText() const { return false; } diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 99f0f98b5..77d547b3e 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -16,6 +16,7 @@ class HistoryBlock; class HistoryItem; class HistoryMessage; class HistoryService; +struct HistoryMessageReply; namespace Window { class SessionController; @@ -62,6 +63,7 @@ public: const TextWithEntities &text, Fn hiddenCallback) = 0; virtual bool elementIsGifPaused() = 0; + virtual bool elementHideReply(not_null view) = 0; }; @@ -92,6 +94,7 @@ public: const TextWithEntities &text, Fn hiddenCallback) override; bool elementIsGifPaused() override; + bool elementHideReply(not_null view) override; private: const not_null _controller; @@ -267,6 +270,7 @@ public: virtual bool displayEditedBadge() const; virtual TimeId displayedEditDate() const; virtual bool hasVisibleText() const; + virtual HistoryMessageReply *displayedReply() const; struct VerticalRepaintRange { int top = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index d13075d75..d075dde60 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1175,6 +1175,10 @@ bool ListWidget::elementIsGifPaused() { return _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any); } +bool ListWidget::elementHideReply(not_null view) { + return _delegate->listElementHideReply(view); +} + 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 fbb1c5633..d2b1f498f 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -74,6 +74,7 @@ public: const std::vector> &elements) = 0; virtual void listContentRefreshed() = 0; virtual ClickHandlerPtr listDateLink(not_null view) = 0; + virtual bool listElementHideReply(not_null view) = 0; }; @@ -208,6 +209,7 @@ public: const TextWithEntities &text, Fn hiddenCallback) override; bool elementIsGifPaused() override; + bool elementHideReply(not_null view) override; ~ListWidget(); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 3fc502acd..36c7ae36e 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -235,7 +235,7 @@ QSize Message::performCountOptimalSize() { if (drawBubble()) { auto forwarded = item->Get(); - auto reply = item->Get(); + auto reply = displayedReply(); auto via = item->Get(); auto entry = logEntryOriginal(); if (forwarded) { @@ -533,9 +533,10 @@ void Message::draw( p.restore(); } - const auto reply = item->Get(); - if (reply && reply->isNameUpdated()) { - const_cast(this)->setPendingResize(); + if (const auto reply = displayedReply()) { + if (reply->isNameUpdated()) { + const_cast(this)->setPendingResize(); + } } } @@ -692,7 +693,7 @@ void Message::paintForwardedInfo(Painter &p, QRect &trect, bool selected) const void Message::paintReplyInfo(Painter &p, QRect &trect, bool selected) const { const auto item = message(); - if (auto reply = item->Get()) { + if (auto reply = displayedReply()) { int32 h = st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom(); auto flags = HistoryMessageReply::PaintFlag::InBubble | 0; @@ -1108,7 +1109,7 @@ bool Message::getStateReplyInfo( QRect &trect, not_null outResult) const { const auto item = message(); - if (auto reply = item->Get()) { + if (auto reply = displayedReply()) { int32 h = st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom(); if (point.y() >= trect.top() && point.y() < trect.top() + h) { if (reply->replyToMsg && QRect(trect.x(), trect.y() + st::msgReplyPadding.top(), trect.width(), st::msgReplyBarSize.height()).contains(point)) { @@ -1509,6 +1510,13 @@ WebPage *Message::logEntryOriginal() const { return nullptr; } +HistoryMessageReply *Message::displayedReply() const { + if (const auto reply = data()->Get()) { + return delegate()->elementHideReply(this) ? nullptr : reply; + } + return nullptr; +} + bool Message::hasFromName() const { switch (context()) { case Context::AdminLog: @@ -1871,7 +1879,7 @@ int Message::resizeContentGetHeight(int newWidth) { } if (bubble) { - auto reply = item->Get(); + auto reply = displayedReply(); auto via = item->Get(); auto entry = logEntryOriginal(); diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index f8f65a07b..537b8f344 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -94,6 +94,7 @@ public: ClickHandlerPtr rightActionLink() const override; bool displayEditedBadge() const override; TimeId displayedEditDate() const override; + HistoryMessageReply *displayedReply() const override; int infoWidth() const override; VerticalRepaintRange verticalRepaintRange() const override; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index b2bfdb9ee..026a46016 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_schedule_box.h" #include "history/history.h" #include "history/history_drag_area.h" +#include "history/history_item_components.h" #include "history/history_item.h" #include "chat_helpers/send_context_menu.h" // SendMenu::Type. #include "ui/widgets/scroll_area.h" @@ -1165,6 +1166,10 @@ ClickHandlerPtr RepliesWidget::listDateLink(not_null view) { return nullptr; } +bool RepliesWidget::listElementHideReply(not_null view) { + return (view->data()->replyToId() == _rootId); +} + void RepliesWidget::confirmSendNowSelected() { auto items = _inner->getSelectedItems(); if (items.empty()) { diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index ab3fd7a05..a1d1ef7ba 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -115,6 +115,7 @@ public: const std::vector> &elements) override; void listContentRefreshed() override; ClickHandlerPtr listDateLink(not_null view) override; + bool listElementHideReply(not_null view) override; protected: void resizeEvent(QResizeEvent *e) override; diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index d922e7bac..26439e363 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -1146,6 +1146,10 @@ ClickHandlerPtr ScheduledWidget::listDateLink(not_null view) { return nullptr; } +bool ScheduledWidget::listElementHideReply(not_null view) { + return false; +} + void ScheduledWidget::confirmSendNowSelected() { auto items = _inner->getSelectedItems(); if (items.empty()) { diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h index 4ef6b9dbe..926b920ab 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h @@ -110,6 +110,7 @@ public: const std::vector> &elements) override; void listContentRefreshed() override; ClickHandlerPtr listDateLink(not_null view) override; + bool listElementHideReply(not_null view) override; protected: void resizeEvent(QResizeEvent *e) override; diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 5508e503b..f590538bb 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -169,7 +169,7 @@ QSize Gif::countOptimalSize() { } else if (isSeparateRoundVideo()) { const auto item = _parent->data(); auto via = item->Get(); - auto reply = item->Get(); + auto reply = _parent->displayedReply(); auto forwarded = item->Get(); if (forwarded) { forwarded->create(via); @@ -226,7 +226,7 @@ QSize Gif::countCurrentSize(int newWidth) { } else if (isSeparateRoundVideo()) { const auto item = _parent->data(); auto via = item->Get(); - auto reply = item->Get(); + auto reply = _parent->displayedReply(); auto forwarded = item->Get(); if (via || reply || forwarded) { auto additional = additionalWidth(via, reply, forwarded); @@ -348,7 +348,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms auto usex = 0, usew = paintw; auto separateRoundVideo = isSeparateRoundVideo(); auto via = separateRoundVideo ? item->Get() : nullptr; - auto reply = separateRoundVideo ? item->Get() : nullptr; + auto reply = separateRoundVideo ? _parent->displayedReply() : nullptr; auto forwarded = separateRoundVideo ? item->Get() : nullptr; if (via || reply || forwarded) { usew = maxWidth() - additionalWidth(via, reply, forwarded); @@ -752,7 +752,7 @@ TextState Gif::textState(QPoint point, StateRequest request) const { auto separateRoundVideo = isSeparateRoundVideo(); const auto item = _parent->data(); auto via = separateRoundVideo ? item->Get() : nullptr; - auto reply = separateRoundVideo ? item->Get() : nullptr; + auto reply = separateRoundVideo ? _parent->displayedReply() : nullptr; auto forwarded = separateRoundVideo ? item->Get() : nullptr; if (via || reply || forwarded) { usew = maxWidth() - additionalWidth(via, reply, forwarded); diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp index a960d4d32..be4914f0b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -51,7 +51,7 @@ QSize UnwrappedMedia::countOptimalSize() { if (_parent->media() == this) { const auto item = _parent->data(); const auto via = item->Get(); - const auto reply = item->Get(); + const auto reply = _parent->displayedReply(); const auto forwarded = getDisplayedForwardedInfo(); if (forwarded) { forwarded->create(via); @@ -76,7 +76,7 @@ QSize UnwrappedMedia::countCurrentSize(int newWidth) { if (_parent->media() == this) { const auto infoWidth = _parent->infoWidth() + 2 * st::msgDateImgPadding.x(); const auto via = item->Get(); - const auto reply = item->Get(); + const auto reply = _parent->displayedReply(); const auto forwarded = getDisplayedForwardedInfo(); if (via || reply || forwarded) { int usew = maxWidth() - additionalWidth(via, reply, forwarded); @@ -116,7 +116,7 @@ void UnwrappedMedia::draw( const auto inWebPage = (_parent->media() != this); const auto item = _parent->data(); const auto via = inWebPage ? nullptr : item->Get(); - const auto reply = inWebPage ? nullptr : item->Get(); + const auto reply = inWebPage ? nullptr : _parent->displayedReply(); const auto forwarded = inWebPage ? nullptr : getDisplayedForwardedInfo(); auto usex = 0; auto usew = maxWidth(); @@ -243,7 +243,7 @@ PointState UnwrappedMedia::pointState(QPoint point) const { const auto inWebPage = (_parent->media() != this); const auto item = _parent->data(); const auto via = inWebPage ? nullptr : item->Get(); - const auto reply = inWebPage ? nullptr : item->Get(); + const auto reply = inWebPage ? nullptr : _parent->displayedReply(); const auto forwarded = inWebPage ? nullptr : getDisplayedForwardedInfo(); auto usex = 0; auto usew = maxWidth(); @@ -283,7 +283,7 @@ TextState UnwrappedMedia::textState(QPoint point, StateRequest request) const { const auto inWebPage = (_parent->media() != this); const auto item = _parent->data(); const auto via = inWebPage ? nullptr : item->Get(); - const auto reply = inWebPage ? nullptr : item->Get(); + const auto reply = inWebPage ? nullptr : _parent->displayedReply(); const auto forwarded = inWebPage ? nullptr : getDisplayedForwardedInfo(); auto usex = 0; auto usew = maxWidth();