From 33a5856c045d0dfbb944dfcc390c2c1a1fbeac20 Mon Sep 17 00:00:00 2001 From: Wug Date: Wed, 21 Sep 2022 04:29:09 -0700 Subject: [PATCH 1/6] Allow users to filter message searches by channel sender in groups Users can send messages as channels in any supergroup which either has a public username or is linked to a channel. Previously it was not possible to filter by sender for messages sent on behalf of a channel, and now it is. In order to avoid confusion, you must search by the channel's exact username, and the group must permit sending messages as channels. It is worth considering whether chat administrators should always be able to search for messages by any channel, regardless of group or channel settings, to ensure they can handle adversarial situations. --- .../boxes/peers/add_participants_box.cpp | 48 ++++++++++++++++++- .../boxes/peers/add_participants_box.h | 1 + .../dialogs_search_from_controllers.cpp | 1 + 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index 419e9cf2d34e5..ecb6e138e0bd0 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -415,8 +415,13 @@ std::unique_ptr AddSpecialBoxController::createSearchRow( if (_excludeSelf && peer->isSelf()) { return nullptr; } - if (const auto user = peer->asUser()) { - return createRow(user); + if (_excludeBroadcasts && peer->isBroadcast()) + { + return nullptr; + } + + if (peer->asUser() || peer->asBroadcast()) { + return createRow(peer); } return nullptr; } @@ -1118,9 +1123,48 @@ void AddSpecialBoxSearchController::searchGlobalDone( } } }; + + const auto feedListChannels = [&](const MTPVector& 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) { + const auto peerId = mtpChat.match([](const MTPDchannel& data) { + return peerFromChannel(data.vid().v); + }, [](const MTPDchat& data) { + return peerFromChat(data.vid().v); + }, [](auto&&) { + return PeerId(); + }); + if (const auto peer = _peer->owner().peerLoaded(peerId)) { + bool isBroadcastMasqueradable = false; + 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(); diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.h b/Telegram/SourceFiles/boxes/peers/add_participants_box.h index a1c59c6973975..49c50b1713acd 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.h @@ -147,6 +147,7 @@ class AddSpecialBoxController protected: bool _excludeSelf = true; + bool _excludeBroadcasts = true; }; diff --git a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp index b81e79f7b3abe..3d6ce3fdc305a 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp @@ -59,6 +59,7 @@ SearchFromController::SearchFromController( BannedDoneCallback()) , _callback(std::move(callback)) { _excludeSelf = false; + _excludeBroadcasts = false; } void SearchFromController::prepare() { From f33275914b74bca9ed318f22903ce233ca64b9c9 Mon Sep 17 00:00:00 2001 From: Ryan <3932619+TheWug@users.noreply.github.com> Date: Wed, 21 Sep 2022 05:01:48 -0700 Subject: [PATCH 2/6] Update Telegram/SourceFiles/boxes/peers/add_participants_box.cpp Co-authored-by: 23rd <23rd@vivaldi.net> --- Telegram/SourceFiles/boxes/peers/add_participants_box.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index ecb6e138e0bd0..3d1da2d3451cc 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -415,8 +415,7 @@ std::unique_ptr AddSpecialBoxController::createSearchRow( if (_excludeSelf && peer->isSelf()) { return nullptr; } - if (_excludeBroadcasts && peer->isBroadcast()) - { + if (_excludeBroadcasts && peer->isBroadcast()) { return nullptr; } From 92d92187f9d7862634b000a094fbd05bbe82ed48 Mon Sep 17 00:00:00 2001 From: Ryan <3932619+TheWug@users.noreply.github.com> Date: Wed, 21 Sep 2022 05:02:00 -0700 Subject: [PATCH 3/6] Update Telegram/SourceFiles/boxes/peers/add_participants_box.cpp Co-authored-by: 23rd <23rd@vivaldi.net> --- Telegram/SourceFiles/boxes/peers/add_participants_box.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index 3d1da2d3451cc..47567e9fa3a10 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -1132,7 +1132,7 @@ void AddSpecialBoxSearchController::searchGlobalDone( } else { return; } - for (const auto& mtpChat : list.v) { + for (const auto &mtpChat : list.v) { const auto peerId = mtpChat.match([](const MTPDchannel& data) { return peerFromChannel(data.vid().v); }, [](const MTPDchat& data) { From d0b4dbba58f534b4f07ab6b8e09c89da898d17f7 Mon Sep 17 00:00:00 2001 From: Ryan <3932619+TheWug@users.noreply.github.com> Date: Wed, 21 Sep 2022 05:02:06 -0700 Subject: [PATCH 4/6] Update Telegram/SourceFiles/boxes/peers/add_participants_box.cpp Co-authored-by: 23rd <23rd@vivaldi.net> --- Telegram/SourceFiles/boxes/peers/add_participants_box.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index 47567e9fa3a10..1228e63b1359d 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -1141,7 +1141,7 @@ void AddSpecialBoxSearchController::searchGlobalDone( return PeerId(); }); if (const auto peer = _peer->owner().peerLoaded(peerId)) { - bool isBroadcastMasqueradable = false; + auto isBroadcastMasqueradable = false; if (const auto broadcast = peer->asBroadcast()) { // to reduce clutter, only allow exact username matches. if (broadcast->hasUsername() && From f9b07dec8007395cb88ba2e46681d8e2f14818c0 Mon Sep 17 00:00:00 2001 From: Ryan <3932619+TheWug@users.noreply.github.com> Date: Wed, 21 Sep 2022 05:02:41 -0700 Subject: [PATCH 5/6] Update Telegram/SourceFiles/boxes/peers/add_participants_box.cpp Co-authored-by: 23rd <23rd@vivaldi.net> --- Telegram/SourceFiles/boxes/peers/add_participants_box.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index 1228e63b1359d..d24982bc16eaf 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -1133,7 +1133,7 @@ void AddSpecialBoxSearchController::searchGlobalDone( return; } for (const auto &mtpChat : list.v) { - const auto peerId = mtpChat.match([](const MTPDchannel& data) { + const auto peerId = mtpChat.match([](const MTPDchannel &data) { return peerFromChannel(data.vid().v); }, [](const MTPDchat& data) { return peerFromChat(data.vid().v); From 0890001dd69e2dd3b388e4a11ae11423f55c63df Mon Sep 17 00:00:00 2001 From: Ryan <3932619+TheWug@users.noreply.github.com> Date: Wed, 21 Sep 2022 05:02:47 -0700 Subject: [PATCH 6/6] Update Telegram/SourceFiles/boxes/peers/add_participants_box.cpp Co-authored-by: 23rd <23rd@vivaldi.net> --- Telegram/SourceFiles/boxes/peers/add_participants_box.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index d24982bc16eaf..158bc422a9ab7 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -1135,7 +1135,7 @@ void AddSpecialBoxSearchController::searchGlobalDone( for (const auto &mtpChat : list.v) { const auto peerId = mtpChat.match([](const MTPDchannel &data) { return peerFromChannel(data.vid().v); - }, [](const MTPDchat& data) { + }, [](const MTPDchat &data) { return peerFromChat(data.vid().v); }, [](auto&&) { return PeerId();