From bcd45af2440fd85bb2442f9189824016751f578c Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 9 Jul 2026 16:14:29 +0300 Subject: Add CommunityId. --- CMakeLists.txt | 1 + td/telegram/CommunityId.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 td/telegram/CommunityId.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 411b71b24..985ed0892 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -774,6 +774,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/ChatTheme.h td/telegram/ClientActor.h td/telegram/CommonDialogManager.h + td/telegram/CommunityId.h td/telegram/CommunityManager.h td/telegram/ConfigManager.h td/telegram/ConnectionState.h diff --git a/td/telegram/CommunityId.h b/td/telegram/CommunityId.h new file mode 100644 index 000000000..3cf2df1a2 --- /dev/null +++ b/td/telegram/CommunityId.h @@ -0,0 +1,65 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/utils/common.h" +#include "td/utils/HashTableUtils.h" +#include "td/utils/StringBuilder.h" + +#include + +namespace td { + +class CommunityId { + int64 id = 0; + + public: + CommunityId() = default; + + explicit constexpr CommunityId(int64 community_id) : id(community_id) { + } + template ::value>> + CommunityId(T community_id) = delete; + + bool is_valid() const { + return id > 0; + } + + int64 get() const { + return id; + } + + bool operator==(const CommunityId &other) const { + return id == other.id; + } + + bool operator!=(const CommunityId &other) const { + return id != other.id; + } + + template + void store(StorerT &storer) const { + storer.store_long(id); + } + + template + void parse(ParserT &parser) { + id = parser.fetch_long(); + } +}; + +struct CommunityIdHash { + uint32 operator()(CommunityId community_id) const { + return Hash()(community_id.get()); + } +}; + +inline StringBuilder &operator<<(StringBuilder &string_builder, CommunityId community_id) { + return string_builder << "community " << community_id.get(); +} + +} // namespace td -- cgit v1.2.3