From 2c1153bac9ae994a45f6cfad68781a54767daef9 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Wed, 22 Apr 2020 08:03:34 +0300 Subject: [PATCH] Search user messages from context menu --- Telegram/Resources/langs/lang.strings | 2 ++ Telegram/Resources/langs/rewrites/ru.json | 3 ++- .../SourceFiles/boxes/peers/edit_participants_box.cpp | 3 +++ Telegram/SourceFiles/dialogs/dialogs_widget.cpp | 11 +++++++++-- Telegram/SourceFiles/dialogs/dialogs_widget.h | 2 +- Telegram/SourceFiles/facades.cpp | 5 +++-- Telegram/SourceFiles/facades.h | 2 +- Telegram/SourceFiles/history/history_inner_widget.cpp | 6 ++++++ Telegram/SourceFiles/mainwidget.cpp | 4 ++-- Telegram/SourceFiles/mainwidget.h | 2 +- 10 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index b1521ac6d..f924c4191 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2486,4 +2486,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_stickers_copy_title" = "Copy name"; "ktg_stickers_title_copied" = "Sticker pack name copied to clipboard."; +"ktg_context_show_messages_from" = "User messages"; + // Keys finished diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index a69e1c75a..a6d8a2f0f 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -111,5 +111,6 @@ "ktg_settings_filters_hide_all": "Скрыть папку «Все чаты»", "ktg_hide_pinned_message": "Скрыть", "ktg_stickers_copy_title": "Копировать название", - "ktg_stickers_title_copied": "Название набора стикеров скопировано в буфер обмена." + "ktg_stickers_title_copied": "Название набора стикеров скопировано в буфер обмена.", + "ktg_context_show_messages_from": "Сообщения пользователя" } diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 77665b540..398b80c79 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -1408,6 +1408,9 @@ base::unique_qptr ParticipantsBoxController::rowContextMenu( result->addAction( tr::lng_context_view_profile(tr::now), crl::guard(this, [=] { _navigation->showPeerInfo(user); })); + result->addAction( + tr::ktg_context_show_messages_from(tr::now), + crl::guard(this, [=] { App::searchByHashtag(QString(), _peer, user); })); if (_role == Role::Kicked) { if (_peer->isMegagroup() && _additional.canRestrictUser(user)) { diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 89f08591e..8fd0689a9 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -913,7 +913,8 @@ void Widget::showMainMenu() { void Widget::searchMessages( const QString &query, - Key inChat) { + Key inChat, + UserData *from) { auto inChatChanged = [&] { if (inChat == _searchInChat) { return false; @@ -929,7 +930,9 @@ void Widget::searchMessages( onCancelSearch(); setSearchInChat(inChat); } - _filter->setText(query); + if (!query.trimmed().isEmpty()) { + _filter->setText(query); + } _filter->updatePlaceholder(); applyFilterUpdate(true); _searchTimer.stop(); @@ -937,6 +940,10 @@ void Widget::searchMessages( Local::saveRecentSearchHashtags(query); } + if (inChat && from) { + setSearchInChat(inChat, from); + applyFilterUpdate(true); + } } void Widget::onSearchMore() { diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index fc81317e8..e75e0d59a 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -78,7 +78,7 @@ public: void scrollToEntry(const RowDescriptor &entry); - void searchMessages(const QString &query, Key inChat = {}); + void searchMessages(const QString &query, Key inChat = {}, UserData *from = nullptr); void onSearchMore(); // Float player interface. diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 4267df373..639d388d4 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -158,7 +158,7 @@ void activateBotCommand( } } -void searchByHashtag(const QString &tag, PeerData *inPeer) { +void searchByHashtag(const QString &tag, PeerData *inPeer, UserData *from) { if (const auto window = App::wnd()) { if (const auto controller = window->sessionController()) { if (controller->openedFolder().current()) { @@ -172,7 +172,8 @@ void searchByHashtag(const QString &tag, PeerData *inPeer) { tag + ' ', (inPeer && !inPeer->isUser()) ? inPeer->owner().history(inPeer).get() - : Dialogs::Key()); + : Dialogs::Key(), + from); } } } diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index b45e225a8..03bc47f79 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -47,7 +47,7 @@ void activateBotCommand( not_null msg, int row, int column); -void searchByHashtag(const QString &tag, PeerData *inPeer); +void searchByHashtag(const QString &tag, PeerData *inPeer, UserData *from = nullptr); void showSettings(); } // namespace App diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 3bdad6c22..0bba2b8c4 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1561,6 +1561,12 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } }); } + const auto peer = item->history()->peer; + if (peer->isChat() || peer->isMegagroup()) { + _menu->addAction(tr::ktg_context_show_messages_from(tr::now), [=] { + App::searchByHashtag(QString(), peer, item->from()->asUser()); + }); + } }; const auto addPhotoActions = [&](not_null photo) { _menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index ba4f0576c..e1fadd120 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1026,8 +1026,8 @@ bool MainWidget::insertBotCommand(const QString &cmd) { return _history->insertBotCommand(cmd); } -void MainWidget::searchMessages(const QString &query, Dialogs::Key inChat) { - _dialogs->searchMessages(query, inChat); +void MainWidget::searchMessages(const QString &query, Dialogs::Key inChat, UserData *from) { + _dialogs->searchMessages(query, inChat, from); if (Adaptive::OneColumn()) { Ui::showChatsList(); } else { diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index c96711f35..15ddab2b8 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -211,7 +211,7 @@ public: void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo); bool insertBotCommand(const QString &cmd); - void searchMessages(const QString &query, Dialogs::Key inChat); + void searchMessages(const QString &query, Dialogs::Key inChat, UserData *from = nullptr); void itemEdited(not_null item); void checkLastUpdate(bool afterSleep);