diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 36d1871ff7..1c24dc510c 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -33,6 +33,12 @@ namespace { void SearchByHashtag(ClickContext context, const QString &tag) { const auto my = context.other.value(); + if (const auto delegate = my.elementDelegate + ? my.elementDelegate() + : nullptr) { + delegate->elementSearchInList(tag, my.itemId); + return; + } const auto controller = my.sessionWindow.get(); if (!controller) { return; @@ -287,7 +293,9 @@ void BotCommandClickHandler::onClick(ClickContext context) const { return; } const auto my = context.other.value(); - if (const auto delegate = my.elementDelegate ? my.elementDelegate() : nullptr) { + if (const auto delegate = my.elementDelegate + ? my.elementDelegate() + : nullptr) { delegate->elementSendBotCommand(_cmd, my.itemId); } else if (const auto controller = my.sessionWindow.get()) { auto &data = controller->session().data(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 3dd0866d1d..1a701a7b6b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -985,7 +985,7 @@ void Widget::setupShortcuts() { if (_openedForum && !controller()->activeChatCurrent()) { request->check(Command::Search) && request->handle([=] { const auto history = _openedForum->history(); - controller()->content()->searchInChat(history); + controller()->searchInChat(history); return true; }); } @@ -2654,7 +2654,7 @@ bool Widget::setSearchInChat( } if (searchInPeerUpdated) { _searchInChat = chat; - controller()->searchInChat = _searchInChat; + controller()->setSearchInChat(_searchInChat); updateJumpToDateVisibility(); updateStoriesVisibility(); } 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 2598e1f367..d652d0f4c1 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -642,6 +642,12 @@ void InnerWidget::elementSendBotCommand( const FullMsgId &context) { } +void InnerWidget::elementSearchInList( + const QString &query, + const FullMsgId &context) { + +} + void InnerWidget::elementHandleViaClick(not_null bot) { } 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 da7653b1be..f47afddfa7 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -122,6 +122,9 @@ public: void elementSendBotCommand( const QString &command, const FullMsgId &context) override; + void elementSearchInList( + const QString &query, + const FullMsgId &context) override; void elementHandleViaClick(not_null bot) override; bool elementIsChatWide() override; not_null elementPathShiftGradient() override; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 24cbe0ace7..8d008113b4 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -258,6 +258,13 @@ public: _widget->elementSendBotCommand(command, context); } } + void elementSearchInList( + const QString &query, + const FullMsgId &context) override { + if (_widget) { + _widget->elementSearchInList(query, context); + } + } void elementHandleViaClick(not_null bot) override { if (_widget) { _widget->elementHandleViaClick(bot); @@ -3396,6 +3403,15 @@ void HistoryInner::elementSendBotCommand( _widget->sendBotCommand({ _history->peer, command, context }); } +void HistoryInner::elementSearchInList( + const QString &query, + const FullMsgId &context) { + const auto inChat = _history->peer->isUser() + ? Dialogs::Key() + : Dialogs::Key(_history); + _controller->searchMessages(query, inChat); +} + void HistoryInner::elementHandleViaClick(not_null bot) { _widget->insertBotCommand('@' + bot->username()); } diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index ce88f93d7a..11eb81a5a8 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -158,6 +158,9 @@ public: void elementSendBotCommand( const QString &command, const FullMsgId &context); + void elementSearchInList( + const QString &query, + const FullMsgId &context); void elementHandleViaClick(not_null bot); bool elementIsChatWide(); not_null elementPathShiftGradient(); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 6583d98ff0..4921e6307d 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -848,7 +848,9 @@ HistoryWidget::HistoryWidget( }, _topBar->lifetime()); _topBar->searchRequest( ) | rpl::start_with_next([=] { - searchInChat(); + if (_history) { + controller->searchInChat(_history); + } }, _topBar->lifetime()); session().api().sendActions( @@ -1840,7 +1842,7 @@ void HistoryWidget::setupShortcuts() { }) | rpl::start_with_next([=](not_null request) { using Command = Shortcuts::Command; request->check(Command::Search, 1) && request->handle([=] { - searchInChat(); + controller()->searchInChat(_history); return true; }); if (session().supportMode()) { @@ -4791,12 +4793,6 @@ bool HistoryWidget::updateCmdStartShown() { return commandsChanged || buttonChanged || textChanged; } -void HistoryWidget::searchInChat() { - if (_history) { - controller()->content()->searchInChat(_history); - } -} - bool HistoryWidget::searchInChatEmbedded(Dialogs::Key chat, QString query) { const auto peer = chat.peer(); if (!peer || peer != controller()->singlePeer()) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 3dc3489333..3fa34ac2be 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -641,7 +641,6 @@ private: bool kbWasHidden() const; - void searchInChat(); void switchToSearch(QString query); MTP::Sender _api; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_search.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_search.cpp index 14e56a3fb9..c26384f48c 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_search.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_search.cpp @@ -577,7 +577,7 @@ void TopBar::setFrom(PeerData *peer) { _from = peer; requestSearchDelayed(); }); - if (!peer) { + if (!peer || _history->peer->isSelf()) { return; } diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 60f0b0fe3a..bac85515af 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -166,6 +166,11 @@ void DefaultElementDelegate::elementSendBotCommand( const FullMsgId &context) { } +void DefaultElementDelegate::elementSearchInList( + const QString &query, + const FullMsgId &context) { +} + void DefaultElementDelegate::elementHandleViaClick( not_null bot) { } diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 134a7bf70b..0f15a0fef2 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -98,6 +98,9 @@ public: virtual void elementSendBotCommand( const QString &command, const FullMsgId &context) = 0; + virtual void elementSearchInList( + const QString &query, + const FullMsgId &context) = 0; virtual void elementHandleViaClick(not_null bot) = 0; virtual bool elementIsChatWide() = 0; virtual not_null elementPathShiftGradient() = 0; @@ -146,6 +149,9 @@ public: void elementSendBotCommand( const QString &command, const FullMsgId &context) override; + void elementSearchInList( + const QString &query, + const FullMsgId &context) override; void elementHandleViaClick(not_null bot) override; bool elementIsChatWide() override; void elementReplyTo(const FullReplyTo &to) override; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 957b87a480..393284d322 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1723,6 +1723,12 @@ void ListWidget::elementSendBotCommand( _delegate->listSendBotCommand(command, context); } +void ListWidget::elementSearchInList( + const QString &query, + const FullMsgId &context) { + _delegate->listSearch(query, context); +} + void ListWidget::elementHandleViaClick(not_null bot) { _delegate->listHandleViaClick(bot); } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 1321a24ba7..ebba2f5780 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -124,6 +124,9 @@ public: virtual void listSendBotCommand( const QString &command, const FullMsgId &context) = 0; + virtual void listSearch( + const QString &query, + const FullMsgId &context) = 0; virtual void listHandleViaClick(not_null bot) = 0; virtual not_null listChatTheme() = 0; virtual CopyRestrictionType listCopyRestrictionType( @@ -325,6 +328,9 @@ public: void elementSendBotCommand( const QString &command, const FullMsgId &context) override; + void elementSearchInList( + const QString &query, + const FullMsgId &context) override; void elementHandleViaClick(not_null bot) override; bool elementIsChatWide() override; not_null elementPathShiftGradient() override; diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index 017289a0b2..0051aecea8 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -618,6 +618,15 @@ void PinnedWidget::listSendBotCommand( const FullMsgId &context) { } +void PinnedWidget::listSearch( + const QString &query, + const FullMsgId &context) { + const auto inChat = _history->peer->isUser() + ? Dialogs::Key() + : Dialogs::Key(_history); + controller()->searchMessages(query, inChat); +} + void PinnedWidget::listHandleViaClick(not_null bot) { } diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.h b/Telegram/SourceFiles/history/view/history_view_pinned_section.h index 7125a1f187..88a592a1bf 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.h +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.h @@ -104,10 +104,14 @@ public: not_null view) override; bool listElementHideReply(not_null view) override; bool listElementShownUnread(not_null view) override; - bool listIsGoodForAroundPosition(not_null view) override; + bool listIsGoodForAroundPosition( + not_null view) override; void listSendBotCommand( const QString &command, const FullMsgId &context) override; + void listSearch( + const QString &query, + const FullMsgId &context) override; void listHandleViaClick(not_null bot) override; not_null listChatTheme() override; CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index dca9b26331..a244437ffc 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -68,7 +68,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/mime_type.h" #include "main/main_session.h" #include "main/main_session_settings.h" -#include "mainwidget.h" #include "data/data_session.h" #include "data/data_user.h" #include "data/data_chat.h" @@ -2576,6 +2575,12 @@ void RepliesWidget::listSendBotCommand( finishSending(); } +void RepliesWidget::listSearch( + const QString &query, + const FullMsgId &context) { + controller()->searchMessages(query, _history); +} + void RepliesWidget::listHandleViaClick(not_null bot) { _composeControls->setText({ '@' + bot->username() + ' ' }); } @@ -2729,7 +2734,7 @@ void RepliesWidget::setupShortcuts() { void RepliesWidget::searchInTopic() { if (_topic) { - controller()->content()->searchInChat(_topic); + controller()->searchInChat(_topic); } } diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index a4bfdabb65..3da1c44f0a 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -152,6 +152,9 @@ public: void listSendBotCommand( const QString &command, const FullMsgId &context) override; + void listSearch( + const QString &query, + const FullMsgId &context) override; void listHandleViaClick(not_null bot) override; not_null listChatTheme() override; CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override; diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index befbce50d3..ca81ba290c 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -1265,6 +1265,15 @@ void ScheduledWidget::listSendBotCommand( controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); } +void ScheduledWidget::listSearch( + const QString &query, + const FullMsgId &context) { + const auto inChat = _history->peer->isUser() + ? Dialogs::Key() + : Dialogs::Key(_history); + controller()->searchMessages(query, inChat); +} + void ScheduledWidget::listHandleViaClick(not_null bot) { _composeControls->setText({ '@' + bot->username() + ' ' }); } diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h index 1c715e17e5..857410b4f5 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h @@ -131,6 +131,9 @@ public: void listSendBotCommand( const QString &command, const FullMsgId &context) override; + void listSearch( + const QString &query, + const FullMsgId &context) override; void listHandleViaClick(not_null bot) override; not_null listChatTheme() override; CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override; diff --git a/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp b/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp index 5f64ad27f5..f4116fd159 100644 --- a/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_sublist_section.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "core/application.h" #include "core/shortcuts.h" +#include "data/data_message_reaction_id.h" #include "data/data_saved_messages.h" #include "data/data_saved_sublist.h" #include "data/data_session.h" @@ -22,7 +23,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item.h" #include "lang/lang_keys.h" -#include "mainwidget.h" #include "ui/chat/chat_style.h" #include "ui/widgets/buttons.h" #include "ui/widgets/scroll_area.h" @@ -675,6 +675,15 @@ void SublistWidget::listSendBotCommand( const FullMsgId &context) { } +void SublistWidget::listSearch( + const QString &query, + const FullMsgId &context) { + const auto inChat = Data::SearchTagFromQuery(query) + ? Dialogs::Key(_sublist) + : Dialogs::Key(); + controller()->searchMessages(query, inChat); +} + void SublistWidget::listHandleViaClick(not_null bot) { } @@ -763,7 +772,7 @@ void SublistWidget::setupShortcuts() { } void SublistWidget::searchInSublist() { - controller()->content()->searchInChat(_sublist); + controller()->searchInChat(_sublist); } } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_sublist_section.h b/Telegram/SourceFiles/history/view/history_view_sublist_section.h index 3a4bed40b6..7ce8804396 100644 --- a/Telegram/SourceFiles/history/view/history_view_sublist_section.h +++ b/Telegram/SourceFiles/history/view/history_view_sublist_section.h @@ -113,6 +113,9 @@ public: void listSendBotCommand( const QString &command, const FullMsgId &context) override; + void listSearch( + const QString &query, + const FullMsgId &context) override; void listHandleViaClick(not_null bot) override; not_null listChatTheme() override; CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override; diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index c06eddf3f5..31764b970f 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -150,7 +150,7 @@ TopBarWidget::TopBarWidget( rpl::combine( _controller->activeChatValue(), - _controller->searchInChat.value() + _controller->searchInChatValue() ) | rpl::combine_previous( std::make_tuple(Dialogs::Key(), Dialogs::Key()) ) | rpl::map([]( diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 34813a30a6..0f1541ae83 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2696,10 +2696,6 @@ int MainWidget::backgroundFromY() const { return -getMainSectionTop(); } -void MainWidget::searchInChat(Dialogs::Key chat) { - searchMessages(QString(), chat); -} - bool MainWidget::contentOverlapped(const QRect &globalRect) { return _history->contentOverlapped(globalRect) || _playerPlaylist->overlaps(globalRect); diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index d407f8496d..a2c3967815 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -203,8 +203,6 @@ public: bool contentOverlapped(const QRect &globalRect); - void searchInChat(Dialogs::Key chat); - void showChooseReportMessages( not_null peer, Ui::ReportReason reason, diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 0010f6d215..2f4dcc7113 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -1216,7 +1216,7 @@ void Filler::addSearchTopics() { const auto history = forum->history(); const auto controller = _controller; _addAction(tr::lng_dlg_filter(tr::now), [=] { - controller->content()->searchInChat(history); + controller->searchInChat(history); }, &st::menuIconSearch); } diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index cd537957cc..8c936c92ec 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -978,6 +978,16 @@ void SessionNavigation::showPollResults( showSection(std::make_shared(poll, contextId), params); } +void SessionNavigation::searchInChat(Dialogs::Key inChat) { + searchMessages(QString(), inChat); +} + +void SessionNavigation::searchMessages( + const QString &query, + Dialogs::Key inChat) { + parentController()->content()->searchMessages(query, inChat); +} + auto SessionNavigation::showToast(Ui::Toast::Config &&config) -> base::weak_ptr { return uiShow()->showToast(std::move(config)); @@ -1320,7 +1330,7 @@ void SessionController::activateFirstChatsFilter() { bool SessionController::uniqueChatsInSearchResults() const { return session().supportMode() && !session().settings().supportAllSearchResults() - && !searchInChat.current(); + && !_searchInChat.current(); } void SessionController::openFolder(not_null folder) { diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index d3452c8ca5..7aa32404d2 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -240,6 +240,9 @@ public: FullMsgId contextId, const SectionShow ¶ms = SectionShow()); + void searchInChat(Dialogs::Key inChat); + void searchMessages(const QString &query, Dialogs::Key inChat); + base::weak_ptr showToast( Ui::Toast::Config &&config); base::weak_ptr showToast( @@ -340,7 +343,12 @@ public: // This is needed for History TopBar updating when searchInChat // is changed in the Dialogs::Widget of the current window. - rpl::variable searchInChat; + rpl::producer searchInChatValue() const { + return _searchInChat.value(); + } + void setSearchInChat(Dialogs::Key value) { + _searchInChat = value; + } bool uniqueChatsInSearchResults() const; void openFolder(not_null folder); @@ -658,6 +666,7 @@ private: // Depends on _gifPause*. const std::unique_ptr _tabbedSelector; + rpl::variable _searchInChat; rpl::variable _activeChatEntry; rpl::lifetime _activeHistoryLifetime; rpl::variable _dialogsListFocused = false;