From 82165bec5e52dc0cb12ff93711fe61312db2314b Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 26 Jul 2021 17:37:19 +0300 Subject: [PATCH] Replaced MainWidget::replyToItem with history element delegate. --- .../admin_log/history_admin_log_inner.cpp | 3 +++ .../history/admin_log/history_admin_log_inner.h | 1 + .../SourceFiles/history/history_inner_widget.cpp | 9 +++++++++ .../SourceFiles/history/history_inner_widget.h | 1 + .../history/view/history_view_element.cpp | 3 +++ .../history/view/history_view_element.h | 2 ++ .../history/view/history_view_list_widget.cpp | 4 ++++ .../history/view/history_view_list_widget.h | 1 + .../history/view/history_view_message.cpp | 16 ++-------------- .../view/history_view_replies_section.cpp | 9 +-------- .../history/view/history_view_replies_section.h | 1 - Telegram/SourceFiles/mainwidget.cpp | 8 -------- Telegram/SourceFiles/mainwidget.h | 1 - Telegram/SourceFiles/window/section_widget.h | 4 ---- 14 files changed, 27 insertions(+), 36 deletions(-) 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 22a8448005..67698c4b87 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -656,6 +656,9 @@ not_null InnerWidget::elementPathShiftGradient() { return _pathGradient.get(); } +void InnerWidget::elementReplyTo(const FullMsgId &to) { +} + 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 af0698c250..79cdcc8066 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -132,6 +132,7 @@ public: void elementHandleViaClick(not_null bot) override; bool elementIsChatWide() override; not_null elementPathShiftGradient() override; + void elementReplyTo(const FullMsgId &to) override; ~InnerWidget(); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 2220b279cd..b60d123e86 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2647,6 +2647,10 @@ not_null HistoryInner::elementPathShiftGradient() { return _pathGradient.get(); } +void HistoryInner::elementReplyTo(const FullMsgId &to) { + return _widget->replyToMessage(to); +} + auto HistoryInner::getSelectionState() const -> HistoryView::TopBarWidget::SelectedState { auto result = HistoryView::TopBarWidget::SelectedState {}; @@ -3550,6 +3554,11 @@ not_null HistoryInner::ElementDelegate() { return Instance->elementPathShiftGradient(); } + void elementReplyTo(const FullMsgId &to) override { + if (Instance) { + Instance->elementReplyTo(to); + } + } }; static Result result; diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index e5304749c2..03d4551235 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -109,6 +109,7 @@ public: void elementHandleViaClick(not_null bot); bool elementIsChatWide(); not_null elementPathShiftGradient(); + void elementReplyTo(const FullMsgId &to); void updateBotInfo(bool recount = true); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index f3d2328fd9..34cab21002 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -169,6 +169,9 @@ auto SimpleElementDelegate::elementPathShiftGradient() return _pathGradient.get(); } +void SimpleElementDelegate::elementReplyTo(const FullMsgId &to) { +} + 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 dc6045d803..a5eec66b4f 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -84,6 +84,7 @@ public: virtual void elementHandleViaClick(not_null bot) = 0; virtual bool elementIsChatWide() = 0; virtual not_null elementPathShiftGradient() = 0; + virtual void elementReplyTo(const FullMsgId &to) = 0; virtual ~ElementDelegate() { } @@ -138,6 +139,7 @@ public: void elementHandleViaClick(not_null bot) override; bool elementIsChatWide() override; not_null elementPathShiftGradient() override; + void elementReplyTo(const FullMsgId &to) override; private: const not_null _controller; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 4fbe4b0053..15f1637fe6 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1379,6 +1379,10 @@ not_null ListWidget::elementPathShiftGradient() { return _pathGradient.get(); } +void ListWidget::elementReplyTo(const FullMsgId &to) { + replyToMessageRequestNotify(to); +} + 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 f35dd363ac..a4a5dff626 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -256,6 +256,7 @@ public: void elementHandleViaClick(not_null bot) override; bool elementIsChatWide() override; not_null elementPathShiftGradient() override; + void elementReplyTo(const FullMsgId &to) override; void setEmptyInfoWidget(base::unique_qptr &&w); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 18cca8bed4..66e99e6dde 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -2417,21 +2417,9 @@ ClickHandlerPtr Message::fastReplyLink() const { if (_fastReplyLink) { return _fastReplyLink; } - const auto owner = &data()->history()->owner(); const auto itemId = data()->fullId(); - _fastReplyLink = std::make_shared([=]( - ClickContext context) { - const auto controller = ExtractController(context).value_or(nullptr); - if (!controller) { - return; - } - if (const auto item = owner->message(itemId)) { - if (const auto main = controller->content()) { - if (&main->session() == &owner->session()) { - main->replyToItem(item); - } - } - } + _fastReplyLink = std::make_shared([=] { + delegate()->elementReplyTo(itemId); }); return _fastReplyLink; } diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 377b3df98a..96dfdba2aa 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -1394,15 +1394,8 @@ bool RepliesWidget::showMessage( return true; } -bool RepliesWidget::replyToMessage(not_null item) { - if (item->history() != _history || item->replyToTop() != _rootId) { - return false; - } - replyToMessage(item->fullId()); - return true; -} - void RepliesWidget::replyToMessage(FullMsgId itemId) { + // if (item->history() != _history || item->replyToTop() != _rootId) { _composeControls->replyToMessage(itemId); refreshTopBarActiveChat(); } diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index f3a329b9cd..566422c296 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -92,7 +92,6 @@ public: PeerId peerId, const Window::SectionShow ¶ms, MsgId messageId) override; - bool replyToMessage(not_null item) override; void setInternalState( const QRect &geometry, diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 5f46adcf19..d50f7ec91f 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -571,14 +571,6 @@ bool MainWidget::shareUrl( return true; } -void MainWidget::replyToItem(not_null item) { - if ((!_mainSection || !_mainSection->replyToMessage(item)) - && (_history->peer() == item->history()->peer - || _history->peer() == item->history()->peer->migrateTo())) { - _history->replyToMessage(item); - } -} - bool MainWidget::inlineSwitchChosen(PeerId peerId, const QString &botAndQuery) { Expects(peerId != 0); diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 7d289fa08b..23aa9e8507 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -168,7 +168,6 @@ public: PeerId peerId, const QString &url, const QString &text); - void replyToItem(not_null item); bool inlineSwitchChosen(PeerId peerId, const QString &botAndQuery); bool sendPaths(PeerId peerId); void onFilesOrForwardDrop(const PeerId &peer, const QMimeData *data); diff --git a/Telegram/SourceFiles/window/section_widget.h b/Telegram/SourceFiles/window/section_widget.h index 4ee0db362a..e599bb0285 100644 --- a/Telegram/SourceFiles/window/section_widget.h +++ b/Telegram/SourceFiles/window/section_widget.h @@ -125,10 +125,6 @@ public: return false; } - virtual bool replyToMessage(not_null item) { - return false; - } - virtual bool preventsClose(Fn &&continueCallback) const { return false; }