From f979df3dfe2ac46e47fe60d2fa9acb0d77e4dfb6 Mon Sep 17 00:00:00 2001 From: Sameer Hoosen Date: Mon, 9 Sep 2019 09:05:29 +0200 Subject: [PATCH] Allow searching for messages by a user who has left a chat (#6417) Fixes #5667 --- .../boxes/peers/add_participants_box.cpp | 7 +++++-- .../boxes/peers/add_participants_box.h | 3 +++ .../dialogs/dialogs_search_from_controllers.cpp | 17 ++++++++--------- .../dialogs/dialogs_search_from_controllers.h | 8 +++----- Telegram/SourceFiles/dialogs/dialogs_widget.cpp | 1 - 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index dfea07f629..e2e3325779 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -299,7 +299,7 @@ void AddSpecialBoxController::migrate(not_null channel) { std::unique_ptr AddSpecialBoxController::createSearchRow( not_null peer) { - if (peer->isSelf()) { + if (_excludeSelf && peer->isSelf()) { return nullptr; } if (const auto user = peer->asUser()) { @@ -312,6 +312,8 @@ void AddSpecialBoxController::prepare() { delegate()->peerListSetSearchMode(PeerListSearchMode::Enabled); auto title = [&] { switch (_role) { + case Role::Members: + return tr::lng_profile_participants_section(); case Role::Admins: return tr::lng_channel_add_admin(); case Role::Restricted: @@ -799,7 +801,8 @@ void AddSpecialBoxController::kickUser( } bool AddSpecialBoxController::appendRow(not_null user) { - if (delegate()->peerListFindRow(user->id) || user->isSelf()) { + if (delegate()->peerListFindRow(user->id) + || (_excludeSelf && user->isSelf())) { return false; } delegate()->peerListAppendRow(createRow(user)); diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.h b/Telegram/SourceFiles/boxes/peers/add_participants_box.h index deef59d010..b1fab5a43c 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.h @@ -131,6 +131,9 @@ private: AdminDoneCallback _adminDoneCallback; BannedDoneCallback _bannedDoneCallback; +protected: + bool _excludeSelf = true; + }; // Finds chat/channel members, then contacts, then global search results. diff --git a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp index b5823b308f..9e11fa53e1 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp @@ -19,18 +19,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Dialogs { void ShowSearchFromBox( - not_null navigation, not_null peer, Fn)> callback, Fn closedCallback) { auto createController = [ - navigation, peer, callback = std::move(callback) ]() -> std::unique_ptr { if (peer && (peer->isChat() || peer->isMegagroup())) { return std::make_unique( - navigation, peer, std::move(callback)); } @@ -50,18 +47,20 @@ void ShowSearchFromBox( } SearchFromController::SearchFromController( - not_null navigation, not_null peer, Fn)> callback) -: ParticipantsBoxController( - navigation, +: AddSpecialBoxController( peer, - ParticipantsBoxController::Role::Members) -, _callback(std::move(callback)) { + ParticipantsBoxController::Role::Members, + AdminDoneCallback(), + BannedDoneCallback()) +, _callback(std::move(callback)) +{ + _excludeSelf = false; } void SearchFromController::prepare() { - ParticipantsBoxController::prepare(); + AddSpecialBoxController::prepare(); delegate()->peerListSetTitle(tr::lng_search_messages_from()); } diff --git a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h index 3a45b7b5cb..709353bb5f 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h +++ b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h @@ -8,20 +8,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "boxes/peer_list_box.h" -#include "boxes/peers/edit_participants_box.h" +#include "boxes/peers/add_participants_box.h" namespace Dialogs { void ShowSearchFromBox( - not_null navigation, not_null peer, Fn)> callback, Fn closedCallback); -class SearchFromController : public ParticipantsBoxController { +class SearchFromController : public AddSpecialBoxController { public: SearchFromController( - not_null navigation, not_null peer, Fn)> callback); @@ -29,7 +27,7 @@ public: void rowClicked(not_null row) override; protected: - std::unique_ptr createRow(not_null user) const override; + std::unique_ptr createRow(not_null user) const; private: Fn)> _callback; diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index ef158c034b..794934b54b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -1328,7 +1328,6 @@ void Widget::showSearchFrom() { if (const auto peer = _searchInChat.peer()) { const auto chat = _searchInChat; ShowSearchFromBox( - controller(), peer, crl::guard(this, [=](not_null user) { Ui::hideLayer();