diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 1d0fa7374..98ac1a7cc 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3585,6 +3585,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_filters_link_noadmin_channel_error" = "You don't have the admin rights to share invite links to this private channel."; "lng_filters_link_already_group" = "you are already a member"; "lng_filters_link_already_channel" = "you are already subscribed"; +"lng_filters_link_inaccessible" = "chat is inaccessible"; "lng_filters_link_chats_about" = "Select groups and channels that you want everyone who adds the folder via invite link to join."; "lng_filters_link_no_about" = "There are no chats in this folder that you can share with others."; "lng_filters_link_chats_no" = "These chats cannot be shared"; diff --git a/Telegram/SourceFiles/api/api_chat_filters.cpp b/Telegram/SourceFiles/api/api_chat_filters.cpp index 2a8e3eaf3..c526bc519 100644 --- a/Telegram/SourceFiles/api/api_chat_filters.cpp +++ b/Telegram/SourceFiles/api/api_chat_filters.cpp @@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/premium_limits_box.h" #include "boxes/filters/edit_filter_links.h" // FilterChatStatusText #include "core/application.h" +#include "data/data_channel.h" +#include "data/data_chat.h" #include "data/data_chat_filters.h" #include "data/data_peer.h" #include "data/data_session.h" @@ -72,6 +74,7 @@ private: ToggleAction _action = ToggleAction::Adding; QString _filterTitle; + base::flat_set> _checkable; std::vector> _chats; std::vector> _additional; rpl::variable>> _selected; @@ -262,20 +265,36 @@ ToggleChatsController::ToggleChatsController( void ToggleChatsController::prepare() { auto selected = base::flat_set>(); + const auto disabled = [](not_null peer) { + return peer->isChat() + ? peer->asChat()->isForbidden() + : peer->isChannel() + ? peer->asChannel()->isForbidden() + : false; + }; const auto add = [&](not_null peer, bool additional = false) { - auto row = std::make_unique(peer); + const auto disable = disabled(peer); + auto row = (additional || !disable) + ? std::make_unique(peer) + : MakeFilterChatRow( + peer, + tr::lng_filters_link_inaccessible(tr::now), + true); if (delegate()->peerListFindRow(peer->id.value)) { return; } const auto raw = row.get(); delegate()->peerListAppendRow(std::move(row)); - if (!additional || _action == ToggleAction::Removing) { + if (!disable + && (!additional || _action == ToggleAction::Removing)) { + _checkable.emplace(peer); if (const auto status = FilterChatStatusText(peer) ; !status.isEmpty()) { raw->setCustomStatus(status); } } - if (!additional) { + if (disable) { + } else if (!additional) { delegate()->peerListSetRowChecked(raw, true); raw->finishCheckedAnimation(); selected.emplace(peer); @@ -287,11 +306,18 @@ void ToggleChatsController::prepare() { } }; for (const auto &peer : _chats) { - add(peer); + if (!disabled(peer)) { + add(peer); + } } for (const auto &peer : _additional) { add(peer, true); } + for (const auto &peer : _chats) { + if (disabled(peer)) { + add(peer); + } + } setupAboveWidget(); setupBelowWidget(); initDesiredHeightValue(); @@ -301,6 +327,9 @@ void ToggleChatsController::prepare() { void ToggleChatsController::rowClicked(not_null row) { const auto peer = row->peer(); + if (!_checkable.contains(peer)) { + return; + } const auto checked = row->checked(); auto selected = _selected.current(); delegate()->peerListSetRowChecked(row, !checked); @@ -341,8 +370,7 @@ void ToggleChatsController::setupAboveWidget() { : _chats.empty() ? _additional.size() : _chats.size(); - const auto selectableCount = delegate()->peerListFullRowsCount() - - (_action == ToggleAction::Adding ? int(_additional.size()) : 0); + const auto selectableCount = int(_checkable.size()); auto selectedCount = _selected.value( ) | rpl::map([](const base::flat_set> &selected) { return int(selected.size()); diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp index 5a788cb45..bd4d5a49f 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp @@ -1292,3 +1292,10 @@ void AddFilterSubtitleWithToggles( link->move(outer - st::boxRowPadding.right() - width, y); }, link->lifetime()); } + +std::unique_ptr MakeFilterChatRow( + not_null peer, + const QString &status, + bool disabled) { + return std::make_unique(peer, status, disabled); +} diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_links.h b/Telegram/SourceFiles/boxes/filters/edit_filter_links.h index 802e15bea..4cc88f95c 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_links.h +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_links.h @@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/object_ptr.h" +class PeerListRow; + namespace Ui { class Show; class BoxContent; @@ -54,3 +56,8 @@ void AddFilterSubtitleWithToggles( int selectableCount, rpl::producer selectedCount, Fn toggle); + +[[nodiscard]] std::unique_ptr MakeFilterChatRow( + not_null peer, + const QString &status, + bool disabled);