Allow filtering by tag on click in sublists.

This commit is contained in:
John Preston 2024-01-30 19:01:10 +04:00
parent db7c16f82b
commit 0945e04f6b
27 changed files with 140 additions and 28 deletions

View File

@ -33,6 +33,12 @@ namespace {
void SearchByHashtag(ClickContext context, const QString &tag) { void SearchByHashtag(ClickContext context, const QString &tag) {
const auto my = context.other.value<ClickHandlerContext>(); const auto my = context.other.value<ClickHandlerContext>();
if (const auto delegate = my.elementDelegate
? my.elementDelegate()
: nullptr) {
delegate->elementSearchInList(tag, my.itemId);
return;
}
const auto controller = my.sessionWindow.get(); const auto controller = my.sessionWindow.get();
if (!controller) { if (!controller) {
return; return;
@ -287,7 +293,9 @@ void BotCommandClickHandler::onClick(ClickContext context) const {
return; return;
} }
const auto my = context.other.value<ClickHandlerContext>(); const auto my = context.other.value<ClickHandlerContext>();
if (const auto delegate = my.elementDelegate ? my.elementDelegate() : nullptr) { if (const auto delegate = my.elementDelegate
? my.elementDelegate()
: nullptr) {
delegate->elementSendBotCommand(_cmd, my.itemId); delegate->elementSendBotCommand(_cmd, my.itemId);
} else if (const auto controller = my.sessionWindow.get()) { } else if (const auto controller = my.sessionWindow.get()) {
auto &data = controller->session().data(); auto &data = controller->session().data();

View File

@ -985,7 +985,7 @@ void Widget::setupShortcuts() {
if (_openedForum && !controller()->activeChatCurrent()) { if (_openedForum && !controller()->activeChatCurrent()) {
request->check(Command::Search) && request->handle([=] { request->check(Command::Search) && request->handle([=] {
const auto history = _openedForum->history(); const auto history = _openedForum->history();
controller()->content()->searchInChat(history); controller()->searchInChat(history);
return true; return true;
}); });
} }
@ -2654,7 +2654,7 @@ bool Widget::setSearchInChat(
} }
if (searchInPeerUpdated) { if (searchInPeerUpdated) {
_searchInChat = chat; _searchInChat = chat;
controller()->searchInChat = _searchInChat; controller()->setSearchInChat(_searchInChat);
updateJumpToDateVisibility(); updateJumpToDateVisibility();
updateStoriesVisibility(); updateStoriesVisibility();
} }

View File

@ -642,6 +642,12 @@ void InnerWidget::elementSendBotCommand(
const FullMsgId &context) { const FullMsgId &context) {
} }
void InnerWidget::elementSearchInList(
const QString &query,
const FullMsgId &context) {
}
void InnerWidget::elementHandleViaClick(not_null<UserData*> bot) { void InnerWidget::elementHandleViaClick(not_null<UserData*> bot) {
} }

View File

@ -122,6 +122,9 @@ public:
void elementSendBotCommand( void elementSendBotCommand(
const QString &command, const QString &command,
const FullMsgId &context) override; const FullMsgId &context) override;
void elementSearchInList(
const QString &query,
const FullMsgId &context) override;
void elementHandleViaClick(not_null<UserData*> bot) override; void elementHandleViaClick(not_null<UserData*> bot) override;
bool elementIsChatWide() override; bool elementIsChatWide() override;
not_null<Ui::PathShiftGradient*> elementPathShiftGradient() override; not_null<Ui::PathShiftGradient*> elementPathShiftGradient() override;

View File

@ -258,6 +258,13 @@ public:
_widget->elementSendBotCommand(command, context); _widget->elementSendBotCommand(command, context);
} }
} }
void elementSearchInList(
const QString &query,
const FullMsgId &context) override {
if (_widget) {
_widget->elementSearchInList(query, context);
}
}
void elementHandleViaClick(not_null<UserData*> bot) override { void elementHandleViaClick(not_null<UserData*> bot) override {
if (_widget) { if (_widget) {
_widget->elementHandleViaClick(bot); _widget->elementHandleViaClick(bot);
@ -3396,6 +3403,15 @@ void HistoryInner::elementSendBotCommand(
_widget->sendBotCommand({ _history->peer, command, context }); _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<UserData*> bot) { void HistoryInner::elementHandleViaClick(not_null<UserData*> bot) {
_widget->insertBotCommand('@' + bot->username()); _widget->insertBotCommand('@' + bot->username());
} }

View File

@ -158,6 +158,9 @@ public:
void elementSendBotCommand( void elementSendBotCommand(
const QString &command, const QString &command,
const FullMsgId &context); const FullMsgId &context);
void elementSearchInList(
const QString &query,
const FullMsgId &context);
void elementHandleViaClick(not_null<UserData*> bot); void elementHandleViaClick(not_null<UserData*> bot);
bool elementIsChatWide(); bool elementIsChatWide();
not_null<Ui::PathShiftGradient*> elementPathShiftGradient(); not_null<Ui::PathShiftGradient*> elementPathShiftGradient();

View File

@ -848,7 +848,9 @@ HistoryWidget::HistoryWidget(
}, _topBar->lifetime()); }, _topBar->lifetime());
_topBar->searchRequest( _topBar->searchRequest(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
searchInChat(); if (_history) {
controller->searchInChat(_history);
}
}, _topBar->lifetime()); }, _topBar->lifetime());
session().api().sendActions( session().api().sendActions(
@ -1840,7 +1842,7 @@ void HistoryWidget::setupShortcuts() {
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) { }) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
using Command = Shortcuts::Command; using Command = Shortcuts::Command;
request->check(Command::Search, 1) && request->handle([=] { request->check(Command::Search, 1) && request->handle([=] {
searchInChat(); controller()->searchInChat(_history);
return true; return true;
}); });
if (session().supportMode()) { if (session().supportMode()) {
@ -4791,12 +4793,6 @@ bool HistoryWidget::updateCmdStartShown() {
return commandsChanged || buttonChanged || textChanged; return commandsChanged || buttonChanged || textChanged;
} }
void HistoryWidget::searchInChat() {
if (_history) {
controller()->content()->searchInChat(_history);
}
}
bool HistoryWidget::searchInChatEmbedded(Dialogs::Key chat, QString query) { bool HistoryWidget::searchInChatEmbedded(Dialogs::Key chat, QString query) {
const auto peer = chat.peer(); const auto peer = chat.peer();
if (!peer || peer != controller()->singlePeer()) { if (!peer || peer != controller()->singlePeer()) {

View File

@ -641,7 +641,6 @@ private:
bool kbWasHidden() const; bool kbWasHidden() const;
void searchInChat();
void switchToSearch(QString query); void switchToSearch(QString query);
MTP::Sender _api; MTP::Sender _api;

View File

@ -577,7 +577,7 @@ void TopBar::setFrom(PeerData *peer) {
_from = peer; _from = peer;
requestSearchDelayed(); requestSearchDelayed();
}); });
if (!peer) { if (!peer || _history->peer->isSelf()) {
return; return;
} }

View File

@ -166,6 +166,11 @@ void DefaultElementDelegate::elementSendBotCommand(
const FullMsgId &context) { const FullMsgId &context) {
} }
void DefaultElementDelegate::elementSearchInList(
const QString &query,
const FullMsgId &context) {
}
void DefaultElementDelegate::elementHandleViaClick( void DefaultElementDelegate::elementHandleViaClick(
not_null<UserData*> bot) { not_null<UserData*> bot) {
} }

View File

@ -98,6 +98,9 @@ public:
virtual void elementSendBotCommand( virtual void elementSendBotCommand(
const QString &command, const QString &command,
const FullMsgId &context) = 0; const FullMsgId &context) = 0;
virtual void elementSearchInList(
const QString &query,
const FullMsgId &context) = 0;
virtual void elementHandleViaClick(not_null<UserData*> bot) = 0; virtual void elementHandleViaClick(not_null<UserData*> bot) = 0;
virtual bool elementIsChatWide() = 0; virtual bool elementIsChatWide() = 0;
virtual not_null<Ui::PathShiftGradient*> elementPathShiftGradient() = 0; virtual not_null<Ui::PathShiftGradient*> elementPathShiftGradient() = 0;
@ -146,6 +149,9 @@ public:
void elementSendBotCommand( void elementSendBotCommand(
const QString &command, const QString &command,
const FullMsgId &context) override; const FullMsgId &context) override;
void elementSearchInList(
const QString &query,
const FullMsgId &context) override;
void elementHandleViaClick(not_null<UserData*> bot) override; void elementHandleViaClick(not_null<UserData*> bot) override;
bool elementIsChatWide() override; bool elementIsChatWide() override;
void elementReplyTo(const FullReplyTo &to) override; void elementReplyTo(const FullReplyTo &to) override;

View File

@ -1723,6 +1723,12 @@ void ListWidget::elementSendBotCommand(
_delegate->listSendBotCommand(command, context); _delegate->listSendBotCommand(command, context);
} }
void ListWidget::elementSearchInList(
const QString &query,
const FullMsgId &context) {
_delegate->listSearch(query, context);
}
void ListWidget::elementHandleViaClick(not_null<UserData*> bot) { void ListWidget::elementHandleViaClick(not_null<UserData*> bot) {
_delegate->listHandleViaClick(bot); _delegate->listHandleViaClick(bot);
} }

View File

@ -124,6 +124,9 @@ public:
virtual void listSendBotCommand( virtual void listSendBotCommand(
const QString &command, const QString &command,
const FullMsgId &context) = 0; const FullMsgId &context) = 0;
virtual void listSearch(
const QString &query,
const FullMsgId &context) = 0;
virtual void listHandleViaClick(not_null<UserData*> bot) = 0; virtual void listHandleViaClick(not_null<UserData*> bot) = 0;
virtual not_null<Ui::ChatTheme*> listChatTheme() = 0; virtual not_null<Ui::ChatTheme*> listChatTheme() = 0;
virtual CopyRestrictionType listCopyRestrictionType( virtual CopyRestrictionType listCopyRestrictionType(
@ -325,6 +328,9 @@ public:
void elementSendBotCommand( void elementSendBotCommand(
const QString &command, const QString &command,
const FullMsgId &context) override; const FullMsgId &context) override;
void elementSearchInList(
const QString &query,
const FullMsgId &context) override;
void elementHandleViaClick(not_null<UserData*> bot) override; void elementHandleViaClick(not_null<UserData*> bot) override;
bool elementIsChatWide() override; bool elementIsChatWide() override;
not_null<Ui::PathShiftGradient*> elementPathShiftGradient() override; not_null<Ui::PathShiftGradient*> elementPathShiftGradient() override;

View File

@ -618,6 +618,15 @@ void PinnedWidget::listSendBotCommand(
const FullMsgId &context) { 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<UserData*> bot) { void PinnedWidget::listHandleViaClick(not_null<UserData*> bot) {
} }

View File

@ -104,10 +104,14 @@ public:
not_null<Element*> view) override; not_null<Element*> view) override;
bool listElementHideReply(not_null<const Element*> view) override; bool listElementHideReply(not_null<const Element*> view) override;
bool listElementShownUnread(not_null<const Element*> view) override; bool listElementShownUnread(not_null<const Element*> view) override;
bool listIsGoodForAroundPosition(not_null<const Element*> view) override; bool listIsGoodForAroundPosition(
not_null<const Element*> view) override;
void listSendBotCommand( void listSendBotCommand(
const QString &command, const QString &command,
const FullMsgId &context) override; const FullMsgId &context) override;
void listSearch(
const QString &query,
const FullMsgId &context) override;
void listHandleViaClick(not_null<UserData*> bot) override; void listHandleViaClick(not_null<UserData*> bot) override;
not_null<Ui::ChatTheme*> listChatTheme() override; not_null<Ui::ChatTheme*> listChatTheme() override;
CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override; CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override;

View File

@ -68,7 +68,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/mime_type.h" #include "core/mime_type.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_session_settings.h" #include "main/main_session_settings.h"
#include "mainwidget.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_chat.h" #include "data/data_chat.h"
@ -2576,6 +2575,12 @@ void RepliesWidget::listSendBotCommand(
finishSending(); finishSending();
} }
void RepliesWidget::listSearch(
const QString &query,
const FullMsgId &context) {
controller()->searchMessages(query, _history);
}
void RepliesWidget::listHandleViaClick(not_null<UserData*> bot) { void RepliesWidget::listHandleViaClick(not_null<UserData*> bot) {
_composeControls->setText({ '@' + bot->username() + ' ' }); _composeControls->setText({ '@' + bot->username() + ' ' });
} }
@ -2729,7 +2734,7 @@ void RepliesWidget::setupShortcuts() {
void RepliesWidget::searchInTopic() { void RepliesWidget::searchInTopic() {
if (_topic) { if (_topic) {
controller()->content()->searchInChat(_topic); controller()->searchInChat(_topic);
} }
} }

View File

@ -152,6 +152,9 @@ public:
void listSendBotCommand( void listSendBotCommand(
const QString &command, const QString &command,
const FullMsgId &context) override; const FullMsgId &context) override;
void listSearch(
const QString &query,
const FullMsgId &context) override;
void listHandleViaClick(not_null<UserData*> bot) override; void listHandleViaClick(not_null<UserData*> bot) override;
not_null<Ui::ChatTheme*> listChatTheme() override; not_null<Ui::ChatTheme*> listChatTheme() override;
CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override; CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override;

View File

@ -1265,6 +1265,15 @@ void ScheduledWidget::listSendBotCommand(
controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); 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<UserData*> bot) { void ScheduledWidget::listHandleViaClick(not_null<UserData*> bot) {
_composeControls->setText({ '@' + bot->username() + ' ' }); _composeControls->setText({ '@' + bot->username() + ' ' });
} }

View File

@ -131,6 +131,9 @@ public:
void listSendBotCommand( void listSendBotCommand(
const QString &command, const QString &command,
const FullMsgId &context) override; const FullMsgId &context) override;
void listSearch(
const QString &query,
const FullMsgId &context) override;
void listHandleViaClick(not_null<UserData*> bot) override; void listHandleViaClick(not_null<UserData*> bot) override;
not_null<Ui::ChatTheme*> listChatTheme() override; not_null<Ui::ChatTheme*> listChatTheme() override;
CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override; CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override;

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h" #include "main/main_session.h"
#include "core/application.h" #include "core/application.h"
#include "core/shortcuts.h" #include "core/shortcuts.h"
#include "data/data_message_reaction_id.h"
#include "data/data_saved_messages.h" #include "data/data_saved_messages.h"
#include "data/data_saved_sublist.h" #include "data/data_saved_sublist.h"
#include "data/data_session.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.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "mainwidget.h"
#include "ui/chat/chat_style.h" #include "ui/chat/chat_style.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/scroll_area.h" #include "ui/widgets/scroll_area.h"
@ -675,6 +675,15 @@ void SublistWidget::listSendBotCommand(
const FullMsgId &context) { 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<UserData*> bot) { void SublistWidget::listHandleViaClick(not_null<UserData*> bot) {
} }
@ -763,7 +772,7 @@ void SublistWidget::setupShortcuts() {
} }
void SublistWidget::searchInSublist() { void SublistWidget::searchInSublist() {
controller()->content()->searchInChat(_sublist); controller()->searchInChat(_sublist);
} }
} // namespace HistoryView } // namespace HistoryView

View File

@ -113,6 +113,9 @@ public:
void listSendBotCommand( void listSendBotCommand(
const QString &command, const QString &command,
const FullMsgId &context) override; const FullMsgId &context) override;
void listSearch(
const QString &query,
const FullMsgId &context) override;
void listHandleViaClick(not_null<UserData*> bot) override; void listHandleViaClick(not_null<UserData*> bot) override;
not_null<Ui::ChatTheme*> listChatTheme() override; not_null<Ui::ChatTheme*> listChatTheme() override;
CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override; CopyRestrictionType listCopyRestrictionType(HistoryItem *item) override;

View File

@ -150,7 +150,7 @@ TopBarWidget::TopBarWidget(
rpl::combine( rpl::combine(
_controller->activeChatValue(), _controller->activeChatValue(),
_controller->searchInChat.value() _controller->searchInChatValue()
) | rpl::combine_previous( ) | rpl::combine_previous(
std::make_tuple(Dialogs::Key(), Dialogs::Key()) std::make_tuple(Dialogs::Key(), Dialogs::Key())
) | rpl::map([]( ) | rpl::map([](

View File

@ -2696,10 +2696,6 @@ int MainWidget::backgroundFromY() const {
return -getMainSectionTop(); return -getMainSectionTop();
} }
void MainWidget::searchInChat(Dialogs::Key chat) {
searchMessages(QString(), chat);
}
bool MainWidget::contentOverlapped(const QRect &globalRect) { bool MainWidget::contentOverlapped(const QRect &globalRect) {
return _history->contentOverlapped(globalRect) return _history->contentOverlapped(globalRect)
|| _playerPlaylist->overlaps(globalRect); || _playerPlaylist->overlaps(globalRect);

View File

@ -203,8 +203,6 @@ public:
bool contentOverlapped(const QRect &globalRect); bool contentOverlapped(const QRect &globalRect);
void searchInChat(Dialogs::Key chat);
void showChooseReportMessages( void showChooseReportMessages(
not_null<PeerData*> peer, not_null<PeerData*> peer,
Ui::ReportReason reason, Ui::ReportReason reason,

View File

@ -1216,7 +1216,7 @@ void Filler::addSearchTopics() {
const auto history = forum->history(); const auto history = forum->history();
const auto controller = _controller; const auto controller = _controller;
_addAction(tr::lng_dlg_filter(tr::now), [=] { _addAction(tr::lng_dlg_filter(tr::now), [=] {
controller->content()->searchInChat(history); controller->searchInChat(history);
}, &st::menuIconSearch); }, &st::menuIconSearch);
} }

View File

@ -978,6 +978,16 @@ void SessionNavigation::showPollResults(
showSection(std::make_shared<Info::Memento>(poll, contextId), params); showSection(std::make_shared<Info::Memento>(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) auto SessionNavigation::showToast(Ui::Toast::Config &&config)
-> base::weak_ptr<Ui::Toast::Instance> { -> base::weak_ptr<Ui::Toast::Instance> {
return uiShow()->showToast(std::move(config)); return uiShow()->showToast(std::move(config));
@ -1320,7 +1330,7 @@ void SessionController::activateFirstChatsFilter() {
bool SessionController::uniqueChatsInSearchResults() const { bool SessionController::uniqueChatsInSearchResults() const {
return session().supportMode() return session().supportMode()
&& !session().settings().supportAllSearchResults() && !session().settings().supportAllSearchResults()
&& !searchInChat.current(); && !_searchInChat.current();
} }
void SessionController::openFolder(not_null<Data::Folder*> folder) { void SessionController::openFolder(not_null<Data::Folder*> folder) {

View File

@ -240,6 +240,9 @@ public:
FullMsgId contextId, FullMsgId contextId,
const SectionShow &params = SectionShow()); const SectionShow &params = SectionShow());
void searchInChat(Dialogs::Key inChat);
void searchMessages(const QString &query, Dialogs::Key inChat);
base::weak_ptr<Ui::Toast::Instance> showToast( base::weak_ptr<Ui::Toast::Instance> showToast(
Ui::Toast::Config &&config); Ui::Toast::Config &&config);
base::weak_ptr<Ui::Toast::Instance> showToast( base::weak_ptr<Ui::Toast::Instance> showToast(
@ -340,7 +343,12 @@ public:
// This is needed for History TopBar updating when searchInChat // This is needed for History TopBar updating when searchInChat
// is changed in the Dialogs::Widget of the current window. // is changed in the Dialogs::Widget of the current window.
rpl::variable<Dialogs::Key> searchInChat; rpl::producer<Dialogs::Key> searchInChatValue() const {
return _searchInChat.value();
}
void setSearchInChat(Dialogs::Key value) {
_searchInChat = value;
}
bool uniqueChatsInSearchResults() const; bool uniqueChatsInSearchResults() const;
void openFolder(not_null<Data::Folder*> folder); void openFolder(not_null<Data::Folder*> folder);
@ -658,6 +666,7 @@ private:
// Depends on _gifPause*. // Depends on _gifPause*.
const std::unique_ptr<ChatHelpers::TabbedSelector> _tabbedSelector; const std::unique_ptr<ChatHelpers::TabbedSelector> _tabbedSelector;
rpl::variable<Dialogs::Key> _searchInChat;
rpl::variable<Dialogs::RowDescriptor> _activeChatEntry; rpl::variable<Dialogs::RowDescriptor> _activeChatEntry;
rpl::lifetime _activeHistoryLifetime; rpl::lifetime _activeHistoryLifetime;
rpl::variable<bool> _dialogsListFocused = false; rpl::variable<bool> _dialogsListFocused = false;