diff options
| author | levlam <levlam@telegram.org> | 2026-04-14 14:00:58 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2026-04-14 14:00:58 +0300 |
| commit | d72be76092313dd434e4a399e524cf982a4ac9d6 (patch) | |
| tree | 16895b282c36f2c37f2a5caaa9bb33b2d0794b83 | |
| parent | f65f56761a2679adce07ec5ed9e8ee38e0192042 (diff) | |
Support custom styles in textCompositionStyle.
| -rw-r--r-- | CMakeLists.txt | 3 | ||||
| -rw-r--r-- | SplitSource.php | 1 | ||||
| -rw-r--r-- | td/generate/scheme/td_api.tl | 9 | ||||
| -rw-r--r-- | td/telegram/AiComposeTone.cpp | 72 | ||||
| -rw-r--r-- | td/telegram/AiComposeTone.h | 59 | ||||
| -rw-r--r-- | td/telegram/AiComposeTone.hpp | 96 | ||||
| -rw-r--r-- | td/telegram/TranslationManager.cpp | 3 |
7 files changed, 240 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 92b52f7d1..288b7efd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -344,6 +344,7 @@ set(TDLIB_SOURCE_PART1 td/telegram/ActiveStoryState.cpp td/telegram/AffiliateType.cpp td/telegram/AgeVerificationParameters.cpp + td/telegram/AiComposeTone.cpp td/telegram/AlarmManager.cpp td/telegram/AnimationsManager.cpp td/telegram/Application.cpp @@ -701,6 +702,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/AffectedHistory.h td/telegram/AffiliateType.h td/telegram/AgeVerificationParameters.h + td/telegram/AiComposeTone.h td/telegram/AlarmManager.h td/telegram/AnimationsManager.h td/telegram/Application.h @@ -1125,6 +1127,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/WebPagesManager.h td/telegram/AgeVerificationParameters.hpp + td/telegram/AiComposeTone.hpp td/telegram/AnimationsManager.hpp td/telegram/AudiosManager.hpp td/telegram/AuthManager.hpp diff --git a/SplitSource.php b/SplitSource.php index f5ec6550d..03d861e1c 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -287,6 +287,7 @@ function split_file($file, $chunks, $undo) { 'ActiveStoryState' => 'ActiveStoryState', 'AffiliateType' => 'AffiliateType', 'AgeVerificationParameters' => 'AgeVerificationParameters', + 'AiComposeTone' => 'AiComposeTone', 'alarm_manager[_(-](?![.]get[(][)])|AlarmManager' => 'AlarmManager', 'animations_manager[_(-](?![.]get[(][)])|AnimationsManager[^;>]' => 'AnimationsManager', 'attach_menu_manager[_(-](?![.]get[(][)])|AttachMenuManager[^;>]' => 'AttachMenuManager', diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 7b5f3d26f..668d02b20 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -128,9 +128,14 @@ fixedText text:formattedText diff_text:diffText = FixedText; //@description Describes a style that can be used to compose a text //@name Name of the style -//@custom_emoji_id Identifier of the custom emoji corresponding to the style +//@custom_emoji_id Identifier of the custom emoji corresponding to the style; 0 if none //@title Title of the style in the user application's language -textCompositionStyle name:string custom_emoji_id:int64 title:string = TextCompositionStyle; +//@is_custom True, if the style is created by a user +//@is_creator True, if the user is creator of the style +//@install_count Number of users that installed the style; for created custom styles only; 0 if unknown +//@prompt Prompt of the style; for created custom styles only +//@creator_user_id User identifier of the creator of the style; 0 if none of unknown +textCompositionStyle name:string custom_emoji_id:int64 title:string is_custom:Bool is_creator:Bool install_count:int32 prompt:string creator_user_id:int53 = TextCompositionStyle; //@description Contains Telegram terms of service @text Text of the terms of service @min_user_age The minimum age of a user to be able to accept the terms; 0 if age isn't restricted @show_popup True, if a blocking popup with terms of service must be shown to the user diff --git a/td/telegram/AiComposeTone.cpp b/td/telegram/AiComposeTone.cpp new file mode 100644 index 000000000..5d8565cfd --- /dev/null +++ b/td/telegram/AiComposeTone.cpp @@ -0,0 +1,72 @@ +// +// 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) +// +#include "td/telegram/AiComposeTone.h" + +#include "td/telegram/Dependencies.h" +#include "td/telegram/Td.h" +#include "td/telegram/UserManager.h" + +#include "td/utils/logging.h" + +namespace td { + +AiComposeTone::AiComposeTone(telegram_api::object_ptr<telegram_api::AiComposeTone> &&tone_ptr) { + CHECK(tone_ptr != nullptr); + switch (tone_ptr->get_id()) { + case telegram_api::aiComposeTone::ID: { + auto tone = telegram_api::move_object_as<telegram_api::aiComposeTone>(tone_ptr); + type_ = Type::Custom; + slug_ = std::move(tone->slug_); + custom_emoji_id_ = CustomEmojiId(tone->emoji_id_); + title_ = std::move(tone->title_); + is_creator_ = tone->creator_; + id_ = tone->id_; + access_hash_ = tone->access_hash_; + install_count_ = tone->installs_count_; + prompt_ = std::move(tone->prompt_); + author_user_id_ = UserId(tone->author_id_); + break; + } + case telegram_api::aiComposeToneDefault::ID: { + auto tone = telegram_api::move_object_as<telegram_api::aiComposeToneDefault>(tone_ptr); + type_ = Type::Default; + slug_ = std::move(tone->tone_); + custom_emoji_id_ = CustomEmojiId(tone->emoji_id_); + title_ = std::move(tone->title_); + break; + } + default: + UNREACHABLE(); + } + if (author_user_id_ != UserId() && !author_user_id_.is_valid()) { + LOG(ERROR) << "Receive " << author_user_id_; + author_user_id_ = {}; + } + if (custom_emoji_id_ != CustomEmojiId() && !custom_emoji_id_.is_valid()) { + LOG(ERROR) << "Receive " << custom_emoji_id_; + custom_emoji_id_ = {}; + } +} + +td_api::object_ptr<td_api::textCompositionStyle> AiComposeTone::get_text_composition_style_object(Td *td) const { + return td_api::make_object<td_api::textCompositionStyle>( + slug_, custom_emoji_id_.get(), title_, type_ == Type::Custom, is_creator_, install_count_, prompt_, + td->user_manager_->get_user_id_object(author_user_id_, "textCompositionStyle")); +} + +void AiComposeTone::add_dependencies(Dependencies &dependencies) const { + dependencies.add(author_user_id_); +} + +bool operator==(const AiComposeTone &lhs, const AiComposeTone &rhs) { + return lhs.type_ == rhs.type_ && lhs.slug_ == rhs.slug_ && lhs.custom_emoji_id_ == rhs.custom_emoji_id_ && + lhs.title_ == rhs.title_ && lhs.is_creator_ == rhs.is_creator_ && lhs.id_ == rhs.id_ && + lhs.access_hash_ == rhs.access_hash_ && lhs.install_count_ == rhs.install_count_ && + lhs.prompt_ == rhs.prompt_ && lhs.author_user_id_ == rhs.author_user_id_; +} + +} // namespace td diff --git a/td/telegram/AiComposeTone.h b/td/telegram/AiComposeTone.h new file mode 100644 index 000000000..3e8c4c9c3 --- /dev/null +++ b/td/telegram/AiComposeTone.h @@ -0,0 +1,59 @@ +// +// 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/telegram/CustomEmojiId.h" +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" +#include "td/telegram/UserId.h" + +#include "td/utils/common.h" + +namespace td { + +class Dependencies; +class Td; + +class AiComposeTone { + enum class Type : int32 { Default, Custom }; + Type type_ = Type::Default; + string slug_; + CustomEmojiId custom_emoji_id_; + string title_; + + bool is_creator_ = false; + int64 id_ = 0; + int64 access_hash_ = 0; + int32 install_count_ = 0; + string prompt_; + UserId author_user_id_; + + friend bool operator==(const AiComposeTone &lhs, const AiComposeTone &rhs); + + public: + AiComposeTone() = default; + + explicit AiComposeTone(telegram_api::object_ptr<telegram_api::AiComposeTone> &&tone_ptr); + + td_api::object_ptr<td_api::textCompositionStyle> get_text_composition_style_object(Td *td) const; + + void add_dependencies(Dependencies &dependencies) const; + + template <class StorerT> + void store(StorerT &storer) const; + + template <class ParserT> + void parse(ParserT &parser); +}; + +bool operator==(const AiComposeTone &lhs, const AiComposeTone &rhs); + +inline bool operator!=(const AiComposeTone &lhs, const AiComposeTone &rhs) { + return !(lhs == rhs); +} + +} // namespace td diff --git a/td/telegram/AiComposeTone.hpp b/td/telegram/AiComposeTone.hpp new file mode 100644 index 000000000..8ddcda035 --- /dev/null +++ b/td/telegram/AiComposeTone.hpp @@ -0,0 +1,96 @@ +// +// 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/telegram/AiComposeTone.h" + +#include "td/utils/common.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +template <class StorerT> +void AiComposeTone::store(StorerT &storer) const { + bool has_custom_emoji_id = custom_emoji_id_.is_valid(); + bool has_id = id_ != 0; + bool has_access_hash = access_hash_ != 0; + bool has_install_count = install_count_ != 0; + bool has_author_user_id = author_user_id_ != UserId(); + bool has_prompt = !prompt_.empty(); + BEGIN_STORE_FLAGS(); + STORE_FLAG(is_creator_); + STORE_FLAG(has_custom_emoji_id); + STORE_FLAG(has_id); + STORE_FLAG(has_access_hash); + STORE_FLAG(has_install_count); + STORE_FLAG(has_author_user_id); + STORE_FLAG(has_prompt); + END_STORE_FLAGS(); + td::store(type_, storer); + td::store(slug_, storer); + if (has_custom_emoji_id) { + td::store(custom_emoji_id_, storer); + } + td::store(title_, storer); + if (has_id) { + td::store(id_, storer); + } + if (has_access_hash) { + td::store(access_hash_, storer); + } + if (has_install_count) { + td::store(install_count_, storer); + } + if (has_author_user_id) { + td::store(author_user_id_, storer); + } + if (has_prompt) { + td::store(prompt_, storer); + } +} + +template <class ParserT> +void AiComposeTone::parse(ParserT &parser) { + bool has_custom_emoji_id; + bool has_id; + bool has_access_hash; + bool has_install_count; + bool has_author_user_id; + bool has_prompt; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(is_creator_); + PARSE_FLAG(has_custom_emoji_id); + PARSE_FLAG(has_id); + PARSE_FLAG(has_access_hash); + PARSE_FLAG(has_install_count); + PARSE_FLAG(has_author_user_id); + PARSE_FLAG(has_prompt); + END_PARSE_FLAGS(); + td::parse(type_, parser); + td::parse(slug_, parser); + if (has_custom_emoji_id) { + td::parse(custom_emoji_id_, parser); + } + td::parse(title_, parser); + if (has_id) { + td::parse(id_, parser); + } + if (has_access_hash) { + td::parse(access_hash_, parser); + } + if (has_install_count) { + td::parse(install_count_, parser); + } + if (has_author_user_id) { + td::parse(author_user_id_, parser); + } + if (has_prompt) { + td::parse(prompt_, parser); + } +} + +} // namespace td diff --git a/td/telegram/TranslationManager.cpp b/td/telegram/TranslationManager.cpp index 365d7d33f..dab90d37b 100644 --- a/td/telegram/TranslationManager.cpp +++ b/td/telegram/TranslationManager.cpp @@ -308,7 +308,8 @@ td_api::object_ptr<td_api::updateTextCompositionStyles> TranslationManager::get_ auto result = td_api::make_object<td_api::updateTextCompositionStyles>(); for (size_t i = 0; i < ai_compose_styles_.size(); i += 3) { result->styles_.push_back(td_api::make_object<td_api::textCompositionStyle>( - ai_compose_styles_[i], to_integer<int64>(ai_compose_styles_[i + 1]), ai_compose_styles_[i + 2])); + ai_compose_styles_[i], to_integer<int64>(ai_compose_styles_[i + 1]), ai_compose_styles_[i + 2], false, false, 0, + string(), 0)); } return result; } |
