Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to filter message searches by channel sender in groups #25104

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions Telegram/SourceFiles/boxes/peers/add_participants_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,13 @@ std::unique_ptr<PeerListRow> AddSpecialBoxController::createSearchRow(
if (_excludeSelf && peer->isSelf()) {
return nullptr;
}
if (const auto user = peer->asUser()) {
return createRow(user);
if (_excludeBroadcasts && peer->isBroadcast())
{
TheWug marked this conversation as resolved.
Show resolved Hide resolved
return nullptr;
}

if (peer->asUser() || peer->asBroadcast()) {
return createRow(peer);
}
return nullptr;
}
Expand Down Expand Up @@ -1118,9 +1123,48 @@ void AddSpecialBoxSearchController::searchGlobalDone(
}
}
};

const auto feedListChannels = [&](const MTPVector<MTPChat>& list) {
// skip this step in groups which are not eligible for masquerading.
if (const auto megagroup = _peer->asMegagroup()) {
if (!megagroup->hasUsername() && !megagroup->linkedChat()) {
return;
}
} else {
return;
}
for (const auto& mtpChat : list.v) {
TheWug marked this conversation as resolved.
Show resolved Hide resolved
const auto peerId = mtpChat.match([](const MTPDchannel& data) {
TheWug marked this conversation as resolved.
Show resolved Hide resolved
return peerFromChannel(data.vid().v);
}, [](const MTPDchat& data) {
TheWug marked this conversation as resolved.
Show resolved Hide resolved
return peerFromChat(data.vid().v);
}, [](auto&&) {
return PeerId();
});
if (const auto peer = _peer->owner().peerLoaded(peerId)) {
bool isBroadcastMasqueradable = false;
TheWug marked this conversation as resolved.
Show resolved Hide resolved
if (const auto broadcast = peer->asBroadcast()) {
// to reduce clutter, only allow exact username matches.
if (broadcast->hasUsername() &&
broadcast->username.compare(_query.startsWith('@') ?
QString(_query).remove('@') :
_query, Qt::CaseInsensitive) == 0) {
isBroadcastMasqueradable = true;
}
}

if (isBroadcastMasqueradable) {
_additional->checkForLoaded(peer);
delegate()->peerListSearchAddRow(peer);
}
}
}
};

if (_requestId == requestId) {
_requestId = 0;
_globalLoaded = true;
feedListChannels(found.vchats());
feedList(found.vmy_results());
feedList(found.vresults());
delegate()->peerListSearchRefreshRows();
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/boxes/peers/add_participants_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class AddSpecialBoxController

protected:
bool _excludeSelf = true;
bool _excludeBroadcasts = true;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ SearchFromController::SearchFromController(
BannedDoneCallback())
, _callback(std::move(callback)) {
_excludeSelf = false;
_excludeBroadcasts = false;
}

void SearchFromController::prepare() {
Expand Down