From 40a79c8367eaa64385b0a9a05d4949edd181bcba Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 10 Jul 2026 22:51:02 +0300 Subject: Add community cache. --- telegram-bot-api/Client.cpp | 24 +++++++++++++++++++++++- telegram-bot-api/Client.h | 8 ++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 173948e..d7ed0d0 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -54,7 +54,7 @@ Client::Client(td::ActorShared<> parent, const td::string &bot_token, bool is_te Client::~Client() { td::Scheduler::instance()->destroy_on_scheduler(SharedData::get_file_gc_scheduler_id(), messages_, users_, groups_, - supergroups_, chats_, sticker_set_names_); + supergroups_, chats_, communities_, sticker_set_names_); } int Client::get_retry_after_time(td::Slice error_message) { @@ -9663,6 +9663,12 @@ void Client::on_update(object_ptr result) { add_supergroup(supergroup_info, std::move(update->supergroup_)); break; } + case td_api::updateCommunity::ID: { + auto update = move_object_as(result); + auto *community_info = add_community_info(update->community_->id_); + add_community(community_info, std::move(update->community_)); + break; + } case td_api::updateSupergroupFullInfo::ID: { auto update = move_object_as(result); auto supergroup_id = update->supergroup_id_; @@ -17553,6 +17559,22 @@ const Client::ChatInfo *Client::get_chat(int64 chat_id) const { return chats_.get_pointer(chat_id); } +void Client::add_community(CommunityInfo *community_info, object_ptr &&community) { + community_info->name = std::move(community->name_); +} + +Client::CommunityInfo *Client::add_community_info(int64 community_id) { + auto &community_info = communities_[community_id]; + if (community_info == nullptr) { + community_info = td::make_unique(); + } + return community_info.get(); +} + +const Client::CommunityInfo *Client::get_community_info(int64 community_id) const { + return communities_.get_pointer(community_id); +} + void Client::set_chat_available_reactions(ChatInfo *chat_info, object_ptr &&available_reactions) { CHECK(chat_info != nullptr); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 6ce5973..e0b00ad 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -1210,6 +1210,13 @@ class Client final : public WebhookActor::Callback { ChatInfo *add_chat(int64 chat_id); const ChatInfo *get_chat(int64 chat_id) const; + struct CommunityInfo { + td::string name; + }; + static void add_community(CommunityInfo *community_info, object_ptr &&community); + CommunityInfo *add_community_info(int64 community_id); + const CommunityInfo *get_community_info(int64 community_id) const; + void set_chat_available_reactions(ChatInfo *chat_info, object_ptr &&available_reactions); @@ -1562,6 +1569,7 @@ class Client final : public WebhookActor::Callback { td::WaitFreeHashMap> groups_; td::WaitFreeHashMap> supergroups_; td::WaitFreeHashMap> chats_; + td::WaitFreeHashMap> communities_; td::WaitFreeHashMap> business_connections_; td::FlatHashMap> file_download_listeners_; -- cgit v1.2.3