From 32e533aba0272ae351b33d32440f6c41252427bc Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 23 Jun 2026 15:44:48 +0400 Subject: [PATCH] Show limit-reached message on community peers limit --- Telegram/Resources/langs/lang.strings | 2 ++ Telegram/SourceFiles/api/api_communities.cpp | 7 +++++++ Telegram/SourceFiles/api/api_communities.h | 4 ++++ .../boxes/peers/add_to_community_box.cpp | 5 +++++ .../peers/community_pending_requests_box.cpp | 21 +++++++++++++++++-- 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 36c06df9cc..60b9d35e61 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2288,6 +2288,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_community_admin_dismiss_title" = "Dismiss yourself as community admin"; "lng_community_admin_dismiss_text" = "You'll lose access to community admin tools, but keep your group admin rights."; "lng_community_removed_list_about" = "Users removed from the community will be shown here."; +"lng_community_peers_limit#one" = "Limit of {count} chat reached."; +"lng_community_peers_limit#other" = "Limit of {count} chats reached."; "lng_manage_monoforum" = "Direct Messages"; "lng_manage_monoforum_off" = "Off"; diff --git a/Telegram/SourceFiles/api/api_communities.cpp b/Telegram/SourceFiles/api/api_communities.cpp index 4293f46918..e5bc0b94a8 100644 --- a/Telegram/SourceFiles/api/api_communities.cpp +++ b/Telegram/SourceFiles/api/api_communities.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_user.h" #include "history/history.h" +#include "main/main_app_config.h" #include "main/main_session.h" namespace Api { @@ -47,6 +48,12 @@ namespace { } // namespace +int CommunityPeersLimit(not_null session) { + return session->appConfig().get( + u"community_peers_limit"_q, + session->isTestMode() ? 10 : 100); +} + Communities::Communities(not_null api) : _session(&api->session()) , _api(&api->instance()) { diff --git a/Telegram/SourceFiles/api/api_communities.h b/Telegram/SourceFiles/api/api_communities.h index b38edee500..e01f12315a 100644 --- a/Telegram/SourceFiles/api/api_communities.h +++ b/Telegram/SourceFiles/api/api_communities.h @@ -22,6 +22,8 @@ namespace Api { inline constexpr auto kCommunityRequestCreated = "COMMUNITY_REQUEST_CREATED"_cs; +inline constexpr auto kCommunityPeersTooMuch + = "COMMUNITY_PEERS_TOO_MUCH"_cs; struct CommunityPeerRequest { not_null peer; @@ -126,4 +128,6 @@ private: }; +[[nodiscard]] int CommunityPeersLimit(not_null session); + } // namespace Api diff --git a/Telegram/SourceFiles/boxes/peers/add_to_community_box.cpp b/Telegram/SourceFiles/boxes/peers/add_to_community_box.cpp index 2885a24247..d8eb1cf657 100644 --- a/Telegram/SourceFiles/boxes/peers/add_to_community_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_to_community_box.cpp @@ -245,6 +245,11 @@ void ShowAddPeerToCommunity( show->hideLayer(); show->showToast( tr::lng_community_request_sent(tr::now)); + } else if (error == Api::kCommunityPeersTooMuch.utf16()) { + show->showToast(tr::lng_community_peers_limit( + tr::now, + lt_count, + Api::CommunityPeersLimit(&community->session()))); } else { show->showToast(error.isEmpty() ? Lang::Hard::ServerError() diff --git a/Telegram/SourceFiles/boxes/peers/community_pending_requests_box.cpp b/Telegram/SourceFiles/boxes/peers/community_pending_requests_box.cpp index f55248f19b..eea01ebad9 100644 --- a/Telegram/SourceFiles/boxes/peers/community_pending_requests_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/community_pending_requests_box.cpp @@ -806,7 +806,15 @@ void Controller::performNow(const std::shared_ptr &action) { } }), crl::guard(this, [=](const QString &error) { - delegate()->peerListUiShow()->showToast(error); + const auto show = delegate()->peerListUiShow(); + if (error == Api::kCommunityPeersTooMuch.utf16()) { + show->showToast(tr::lng_community_peers_limit( + tr::now, + lt_count, + Api::CommunityPeersLimit(&session()))); + } else { + show->showToast(error); + } })); } @@ -953,7 +961,16 @@ void ShowCommunityPendingRequestsBox( count)); }), crl::guard(box, [=](const QString &error) { - box->uiShow()->showToast(error); + const auto show = box->uiShow(); + if (error == Api::kCommunityPeersTooMuch.utf16()) { + show->showToast(tr::lng_community_peers_limit( + tr::now, + lt_count, + Api::CommunityPeersLimit( + &community->session()))); + } else { + show->showToast(error); + } })); }; box->uiShow()->showBox(Ui::MakeConfirmBox({