From 42d53e5543d38371c705eca0c0618520007d1457 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 20 May 2024 17:38:18 +0400 Subject: [PATCH] Fix saved messages tags search. --- .../dialogs/dialogs_inner_widget.cpp | 59 +++++++++++-------- .../dialogs/dialogs_inner_widget.h | 4 ++ Telegram/SourceFiles/dialogs/dialogs_key.cpp | 2 +- .../SourceFiles/dialogs/dialogs_widget.cpp | 3 +- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index ee71e46e7..274d889a9 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -488,7 +488,7 @@ int InnerWidget::peerSearchOffset() const { + st::searchedBarHeight; } -int InnerWidget::searchInChatOffset() const { +int InnerWidget::searchTagsOffset() const { auto result = peerSearchOffset() - st::searchedBarHeight; if (!_peerSearchResults.empty()) { result += (_peerSearchResults.size() * st::dialogsRowHeight) @@ -497,6 +497,14 @@ int InnerWidget::searchInChatOffset() const { return result; } +int InnerWidget::searchInChatOffset() const { + auto result = searchTagsOffset(); + if (_searchTags) { + result += _searchTags->height(); + } + return result; +} + int InnerWidget::searchedOffset() const { return searchInChatOffset() + searchInChatSkip() @@ -505,9 +513,6 @@ int InnerWidget::searchedOffset() const { int InnerWidget::searchInChatSkip() const { auto result = 0; - if (_searchTags) { - result += _searchTags->height(); - } if (_searchFromShown) { result += st::dialogsSearchInHeight; } @@ -857,6 +862,17 @@ void InnerWidget::paintEvent(QPaintEvent *e) { } } + if (_searchTags) { + paintSearchTags(p, { + .st = &st::forumTopicRow, + .currentBg = currentBg(), + .now = ms, + .width = fullWidth, + .paused = videoPaused, + }); + p.translate(0, _searchTags->height()); + top += _searchTags->height(); + } if (_searchFromShown) { paintSearchInChat(p, { .st = &st::forumTopicRow, @@ -1117,20 +1133,24 @@ QBrush InnerWidget::currentBg() const { _childListShown.current().shown); } +void InnerWidget::paintSearchTags( + Painter &p, + const Ui::PaintContext &context) const { + Expects(_searchTags != nullptr); + + const auto height = _searchTags->height(); + p.fillRect(0, 0, width(), height, currentBg()); + const auto top = st::dialogsSearchTagBottom / 2; + const auto position = QPoint(_searchTagsLeft, top); + _searchTags->paint(p, position, context.now, context.paused); +} + void InnerWidget::paintSearchInChat( Painter &p, const Ui::PaintContext &context) const { auto height = searchInChatSkip(); auto top = 0; - if (_searchTags) { - const auto height = _searchTags->height(); - top += st::dialogsSearchTagBottom; - p.fillRect(0, top, width(), height, currentBg()); - const auto position = QPoint(_searchTagsLeft, top); - _searchTags->paint(p, position, context.now, context.paused); - top += height - st::dialogsSearchTagBottom; - } p.setFont(st::searchedBarFont); auto fullRect = QRect(0, top, width(), height - top); p.fillRect(fullRect, currentBg()); @@ -1280,7 +1300,7 @@ void InnerWidget::selectByMouse(QPoint globalPosition) { const auto tagBase = QPoint( _searchTagsLeft, - searchInChatOffset() + st::dialogsSearchTagBottom); + searchTagsOffset() + st::dialogsSearchTagBottom / 2); const auto tagPoint = local - tagBase; const auto inTags = _searchTags && QRect( @@ -2464,11 +2484,7 @@ void InnerWidget::applySearchState(SearchState state) { const auto ignoreInChat = (state.tab == ChatSearchTab::MyMessages) || (state.tab == ChatSearchTab::PublicPosts); const auto sublist = ignoreInChat ? nullptr : state.inChat.sublist(); - const auto peer = ignoreInChat - ? nullptr - : sublist - ? session().user().get() - : state.inChat.peer(); + const auto peer = ignoreInChat ? nullptr : state.inChat.peer(); if (const auto migrateFrom = peer ? peer->migrateFrom() : nullptr) { _searchInMigrated = peer->owner().history(migrateFrom); } else { @@ -2481,14 +2497,9 @@ void InnerWidget::applySearchState(SearchState state) { reactions->myTagsValue(sublist), state.tags); - _searchTags->selectedChanges( - ) | rpl::start_with_next([=](std::vector &&list) { - _searchState.tags = std::move(list); - }, _searchTags->lifetime()); - _searchTags->repaintRequests() | rpl::start_with_next([=] { const auto height = _searchTags->height(); - update(0, searchInChatOffset(), width(), height); + update(0, searchTagsOffset(), width(), height); }, _searchTags->lifetime()); _searchTags->menuRequests( diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index 57f649c3c..8cde8de92 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -334,6 +334,7 @@ private: [[nodiscard]] int filteredIndex(int y) const; [[nodiscard]] int filteredHeight(int till = -1) const; [[nodiscard]] int peerSearchOffset() const; + [[nodiscard]] int searchTagsOffset() const; [[nodiscard]] int searchInChatOffset() const; [[nodiscard]] int searchedOffset() const; [[nodiscard]] int searchInChatSkip() const; @@ -349,6 +350,9 @@ private: Painter &p, not_null result, const Ui::PaintContext &context); + void paintSearchTags( + Painter &p, + const Ui::PaintContext &context) const; void paintSearchInChat( Painter &p, const Ui::PaintContext &context) const; diff --git a/Telegram/SourceFiles/dialogs/dialogs_key.cpp b/Telegram/SourceFiles/dialogs/dialogs_key.cpp index 263a605cc..8a8cf398c 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_key.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_key.cpp @@ -93,7 +93,7 @@ PeerData *Key::peer() const { ChatSearchTab SearchState::defaultTabForMe() const { return inChat.topic() ? ChatSearchTab::ThisTopic - : inChat.history() + : (inChat.history() || inChat.sublist()) ? ChatSearchTab::ThisPeer : ChatSearchTab::MyMessages; } diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 6024e7b04..5d8cdc063 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -1282,7 +1282,8 @@ void Widget::updateSearchTabs() { && !_searchingHashtag)) { _searchState.tab = _searchState.inChat.topic() ? ChatSearchTab::ThisTopic - : _searchState.inChat.owningHistory() + : (_searchState.inChat.owningHistory() + || _searchState.inChat.sublist()) ? ChatSearchTab::ThisPeer : ChatSearchTab::MyMessages; }