From 46ebbdb547a8cc186295ffa49fbc3bc569df4c51 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 27 Oct 2022 11:52:18 +0400 Subject: [PATCH] Open jump-to-date by date click in topics. --- .../history/view/history_view_list_widget.cpp | 2 +- .../history/view/history_view_list_widget.h | 4 +++- .../history/view/history_view_pinned_section.cpp | 5 +++-- .../history/view/history_view_pinned_section.h | 4 +++- .../history/view/history_view_replies_section.cpp | 15 +++++++++++++-- .../history/view/history_view_replies_section.h | 4 +++- .../view/history_view_scheduled_section.cpp | 5 +++-- .../history/view/history_view_scheduled_section.h | 4 +++- .../window/window_session_controller.cpp | 11 ++++++++--- .../window/window_session_controller.h | 2 ++ 10 files changed, 42 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 4749e9e7c..54f0d5c68 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -3248,7 +3248,7 @@ void ListWidget::mouseActionUpdate() { dateLeft += (widthForDate - dateWidth) / 2; if (point.x() >= dateLeft && point.x() < dateLeft + dateWidth) { - _scrollDateLink = _delegate->listDateLink(view); + _delegate->listUpdateDateLink(_scrollDateLink, view); dragState = TextState( nullptr, _scrollDateLink); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index fbd4ae0b1..2920dae07 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -106,7 +106,9 @@ public: virtual MessagesBarData listMessagesBar( const std::vector> &elements) = 0; virtual void listContentRefreshed() = 0; - virtual ClickHandlerPtr listDateLink(not_null view) = 0; + virtual void listUpdateDateLink( + ClickHandlerPtr &link, + not_null view) = 0; virtual bool listElementHideReply(not_null view) = 0; virtual bool listElementShownUnread(not_null view) = 0; virtual bool listIsGoodForAroundPosition( diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index cff87b6fc..676c20fa6 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -544,8 +544,9 @@ MessagesBarData PinnedWidget::listMessagesBar( void PinnedWidget::listContentRefreshed() { } -ClickHandlerPtr PinnedWidget::listDateLink(not_null view) { - return nullptr; +void PinnedWidget::listUpdateDateLink( + ClickHandlerPtr &link, + not_null view) { } bool PinnedWidget::listElementHideReply(not_null view) { diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.h b/Telegram/SourceFiles/history/view/history_view_pinned_section.h index abf0e1628..4ac17ebdb 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.h +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.h @@ -98,7 +98,9 @@ public: MessagesBarData listMessagesBar( const std::vector> &elements) override; void listContentRefreshed() override; - ClickHandlerPtr listDateLink(not_null view) override; + void listUpdateDateLink( + ClickHandlerPtr &link, + not_null view) override; bool listElementHideReply(not_null view) override; bool listElementShownUnread(not_null view) override; bool listIsGoodForAroundPosition(not_null view) override; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 30264b91e..dd408159f 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -2010,8 +2010,19 @@ MessagesBarData RepliesWidget::listMessagesBar( void RepliesWidget::listContentRefreshed() { } -ClickHandlerPtr RepliesWidget::listDateLink(not_null view) { - return nullptr; +void RepliesWidget::listUpdateDateLink( + ClickHandlerPtr &link, + not_null view) { + if (!_topic) { + link = nullptr; + return; + } + const auto date = view->dateTime().date(); + if (!link) { + link = std::make_shared(_topic, date); + } else { + static_cast(link.get())->setDate(date); + } } bool RepliesWidget::listElementHideReply(not_null view) { diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index e3c37d523..c83e77398 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -138,7 +138,9 @@ public: MessagesBarData listMessagesBar( const std::vector> &elements) override; void listContentRefreshed() override; - ClickHandlerPtr listDateLink(not_null view) override; + void listUpdateDateLink( + ClickHandlerPtr &link, + not_null view) override; bool listElementHideReply(not_null view) override; bool listElementShownUnread(not_null view) override; bool listIsGoodForAroundPosition(not_null view) override; diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 016960024..929899e6d 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -1162,8 +1162,9 @@ MessagesBarData ScheduledWidget::listMessagesBar( void ScheduledWidget::listContentRefreshed() { } -ClickHandlerPtr ScheduledWidget::listDateLink(not_null view) { - return nullptr; +void ScheduledWidget::listUpdateDateLink( + ClickHandlerPtr &link, + not_null view) { } bool ScheduledWidget::listElementHideReply(not_null view) { diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h index f52114e33..9e4edc65b 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h @@ -120,7 +120,9 @@ public: MessagesBarData listMessagesBar( const std::vector> &elements) override; void listContentRefreshed() override; - ClickHandlerPtr listDateLink(not_null view) override; + void listUpdateDateLink( + ClickHandlerPtr &link, + not_null view) override; bool listElementHideReply(not_null view) override; bool listElementShownUnread(not_null view) override; bool listIsGoodForAroundPosition( diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 33dd22ec4..cb3264bb0 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -167,8 +167,9 @@ bool operator!=(const PeerThemeOverride &a, const PeerThemeOverride &b) { } DateClickHandler::DateClickHandler(Dialogs::Key chat, QDate date) - : _chat(chat) - , _date(date) { +: _chat(chat) +, _weak(chat.topic()) +, _date(date) { } void DateClickHandler::setDate(QDate date) { @@ -178,7 +179,11 @@ void DateClickHandler::setDate(QDate date) { void DateClickHandler::onClick(ClickContext context) const { const auto my = context.other.value(); if (const auto window = my.sessionWindow.get()) { - window->showCalendar(_chat, _date); + if (!_chat.topic()) { + window->showCalendar(_chat, _date); + } else if (const auto strong = _weak.get()) { + window->showCalendar(strong, _date); + } } } diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 8647efdf2..18383dfe6 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -70,6 +70,7 @@ namespace Data { struct CloudTheme; enum class CloudThemeType; class Thread; +class ForumTopic; } // namespace Data namespace HistoryView::Reactions { @@ -119,6 +120,7 @@ public: private: Dialogs::Key _chat; + base::weak_ptr _weak; QDate _date; };