From 5e6beb57c2777190688cd5b369c3337af4951327 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 10 Jul 2026 20:54:01 +0300 Subject: Accept messageActionChangeCommunity only with accessible communities. --- td/telegram/CommunityManager.cpp | 5 +++++ td/telegram/CommunityManager.h | 2 ++ td/telegram/UpdatesManager.cpp | 14 +++++++++++++- td/telegram/UpdatesManager.h | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/td/telegram/CommunityManager.cpp b/td/telegram/CommunityManager.cpp index 734ce999d..deda69dc5 100644 --- a/td/telegram/CommunityManager.cpp +++ b/td/telegram/CommunityManager.cpp @@ -346,6 +346,11 @@ bool CommunityManager::have_community(CommunityId community_id) const { return communities_.count(community_id) > 0; } +bool CommunityManager::have_accessible_community(CommunityId community_id) const { + const auto *c = get_community(community_id); + return c != nullptr && c->access_hash != 0; +} + const CommunityManager::Community *CommunityManager::get_community(CommunityId community_id) const { return communities_.get_pointer(community_id); } diff --git a/td/telegram/CommunityManager.h b/td/telegram/CommunityManager.h index c2d3a621b..92ae2718a 100644 --- a/td/telegram/CommunityManager.h +++ b/td/telegram/CommunityManager.h @@ -37,6 +37,8 @@ class CommunityManager final : public Actor { bool have_community_force(CommunityId community_id, const char *source); + bool have_accessible_community(CommunityId community_id) const; + void reload_community(CommunityId community_id, Promise &&promise, const char *source); void on_get_community(telegram_api::community &community, const char *source); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 09562db8c..fe7769342 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -20,6 +20,7 @@ #include "td/telegram/ChannelType.h" #include "td/telegram/ChatId.h" #include "td/telegram/ChatManager.h" +#include "td/telegram/CommunityManager.h" #include "td/telegram/ConfigManager.h" #include "td/telegram/DialogAction.h" #include "td/telegram/DialogActionManager.h" @@ -722,6 +723,11 @@ bool UpdatesManager::is_acceptable_channel(ChannelId channel_id) const { return td_->chat_manager_->have_channel_force(channel_id, "is_acceptable_channel"); } +bool UpdatesManager::is_acceptable_community(CommunityId community_id) const { + return td_->community_manager_->have_community_force(community_id, "is_acceptable_community") && + td_->community_manager_->have_accessible_community(community_id); +} + bool UpdatesManager::is_acceptable_peer(const tl_object_ptr &peer) const { if (peer == nullptr) { return true; @@ -992,7 +998,6 @@ bool UpdatesManager::is_acceptable_message(const telegram_api::Message *message_ case telegram_api::messageActionPollAppendAnswer::ID: case telegram_api::messageActionPollDeleteAnswer::ID: case telegram_api::messageActionManagedBotCreated::ID: - case telegram_api::messageActionChangeCommunity::ID: break; case telegram_api::messageActionChatCreate::ID: { auto action = static_cast(action_ptr); @@ -1110,6 +1115,13 @@ bool UpdatesManager::is_acceptable_message(const telegram_api::Message *message_ } break; } + case telegram_api::messageActionChangeCommunity::ID: { + auto action = static_cast(action_ptr); + if (action->community_id_ != 0 && !is_acceptable_community(CommunityId(action->community_id_))) { + return false; + } + break; + } default: UNREACHABLE(); return false; diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index 6bb30d48d..9a47a007c 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -8,6 +8,7 @@ #include "td/telegram/ChannelId.h" #include "td/telegram/ChatId.h" +#include "td/telegram/CommunityId.h" #include "td/telegram/DialogId.h" #include "td/telegram/InputGroupCallId.h" #include "td/telegram/MessageFullId.h" @@ -491,6 +492,8 @@ class UpdatesManager final : public Actor { bool is_acceptable_channel(ChannelId channel_id) const; + bool is_acceptable_community(CommunityId community_id) const; + bool is_acceptable_peer(const tl_object_ptr &peer) const; bool is_acceptable_message_entities(const vector> &message_entities) const; -- cgit v1.2.3