Allow searching for messages by a user who has left a chat (#6417)

Fixes #5667
This commit is contained in:
Sameer Hoosen 2019-09-09 09:05:29 +02:00 committed by John Preston
parent eebcdb842d
commit f979df3dfe
5 changed files with 19 additions and 17 deletions

View File

@ -299,7 +299,7 @@ void AddSpecialBoxController::migrate(not_null<ChannelData*> channel) {
std::unique_ptr<PeerListRow> AddSpecialBoxController::createSearchRow(
not_null<PeerData*> 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<UserData*> user) {
if (delegate()->peerListFindRow(user->id) || user->isSelf()) {
if (delegate()->peerListFindRow(user->id)
|| (_excludeSelf && user->isSelf())) {
return false;
}
delegate()->peerListAppendRow(createRow(user));

View File

@ -131,6 +131,9 @@ private:
AdminDoneCallback _adminDoneCallback;
BannedDoneCallback _bannedDoneCallback;
protected:
bool _excludeSelf = true;
};
// Finds chat/channel members, then contacts, then global search results.

View File

@ -19,18 +19,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Dialogs {
void ShowSearchFromBox(
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Fn<void(not_null<UserData*>)> callback,
Fn<void()> closedCallback) {
auto createController = [
navigation,
peer,
callback = std::move(callback)
]() -> std::unique_ptr<PeerListController> {
if (peer && (peer->isChat() || peer->isMegagroup())) {
return std::make_unique<Dialogs::SearchFromController>(
navigation,
peer,
std::move(callback));
}
@ -50,18 +47,20 @@ void ShowSearchFromBox(
}
SearchFromController::SearchFromController(
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Fn<void(not_null<UserData*>)> 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());
}

View File

@ -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<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Fn<void(not_null<UserData*>)> callback,
Fn<void()> closedCallback);
class SearchFromController : public ParticipantsBoxController {
class SearchFromController : public AddSpecialBoxController {
public:
SearchFromController(
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer,
Fn<void(not_null<UserData*>)> callback);
@ -29,7 +27,7 @@ public:
void rowClicked(not_null<PeerListRow*> row) override;
protected:
std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user) const override;
std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user) const;
private:
Fn<void(not_null<UserData*>)> _callback;

View File

@ -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<UserData*> user) {
Ui::hideLayer();