diff options
| -rw-r--r-- | CMakeLists.txt | 3 | ||||
| -rw-r--r-- | SplitSource.php | 1 | ||||
| -rw-r--r-- | td/telegram/MessageEntity.cpp | 6 | ||||
| -rw-r--r-- | td/telegram/MessageEntity.h | 2 | ||||
| -rw-r--r-- | td/telegram/ToDoItem.cpp | 38 | ||||
| -rw-r--r-- | td/telegram/ToDoItem.h | 42 | ||||
| -rw-r--r-- | td/telegram/ToDoItem.hpp | 34 |
7 files changed, 122 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b9babae88..26c610ea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -642,6 +642,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/ThemeManager.cpp td/telegram/ThemeSettings.cpp td/telegram/TimeZoneManager.cpp + td/telegram/ToDoItem.cpp td/telegram/TopDialogCategory.cpp td/telegram/TopDialogManager.cpp td/telegram/TranscriptionInfo.cpp @@ -1027,6 +1028,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/ThemeManager.h td/telegram/ThemeSettings.h td/telegram/TimeZoneManager.h + td/telegram/ToDoItem.h td/telegram/TopDialogCategory.h td/telegram/TopDialogManager.h td/telegram/TranscriptionInfo.h @@ -1145,6 +1147,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/SuggestedAction.hpp td/telegram/TermsOfService.hpp td/telegram/ThemeSettings.hpp + td/telegram/ToDoItem.hpp td/telegram/TranscriptionInfo.hpp td/telegram/VideoNotesManager.hpp td/telegram/VideosManager.hpp diff --git a/SplitSource.php b/SplitSource.php index 9eac66295..209fb49c7 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -455,6 +455,7 @@ function split_file($file, $chunks, $undo) { 'theme_manager[_(-](?![.]get[(][)])|ThemeManager' => 'ThemeManager', 'ThemeSettings' => 'ThemeSettings', 'time_zone_manager[_(-](?![.]get[(][)])|TimeZoneManager' => 'TimeZoneManager', + 'ToDoItem' => 'ToDoItem', 'TopDialogCategory|get_top_dialog_category' => 'TopDialogCategory', 'top_dialog_manager[_(-](?![.]get[(][)])|TopDialogManager' => 'TopDialogManager', 'translation_manager[_(-](?![.]get[(][)])|TranslationManager' => 'TranslationManager', diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 1b9147979..3f7f8bf0f 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -4753,9 +4753,9 @@ vector<tl_object_ptr<telegram_api::MessageEntity>> get_input_message_entities(co return {}; } -void keep_only_custom_emoji(FormattedText &text) { - td::remove_if(text.entities, - [&](const MessageEntity &entity) { return entity.type != MessageEntity::Type::CustomEmoji; }); +bool keep_only_custom_emoji(FormattedText &text) { + return td::remove_if(text.entities, + [&](const MessageEntity &entity) { return entity.type != MessageEntity::Type::CustomEmoji; }); } void remove_premium_custom_emoji_entities(const Td *td, vector<MessageEntity> &entities, bool remove_unknown) { diff --git a/td/telegram/MessageEntity.h b/td/telegram/MessageEntity.h index 58a3c82f6..2b80a97a9 100644 --- a/td/telegram/MessageEntity.h +++ b/td/telegram/MessageEntity.h @@ -168,7 +168,7 @@ td_api::object_ptr<td_api::formattedText> get_formatted_text_object(const UserMa const FormattedText &text, bool skip_bot_commands, int32 max_media_timestamp); -void keep_only_custom_emoji(FormattedText &text); +bool keep_only_custom_emoji(FormattedText &text); void remove_premium_custom_emoji_entities(const Td *td, vector<MessageEntity> &entities, bool remove_unknown); diff --git a/td/telegram/ToDoItem.cpp b/td/telegram/ToDoItem.cpp new file mode 100644 index 000000000..d560d6cc8 --- /dev/null +++ b/td/telegram/ToDoItem.cpp @@ -0,0 +1,38 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025 +// +// 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/ToDoItem.h" + +#include "td/utils/utf8.h" + +namespace td { + +ToDoItem::ToDoItem(const UserManager *user_manager, telegram_api::object_ptr<telegram_api::todoItem> &&item) { + CHECK(item != nullptr); + id_ = item->id_; + title_ = get_formatted_text(user_manager, std::move(item->title_), true, true, "ToDoItem"); + validate("telegram_api::todoItem"); +} + +void ToDoItem::validate(const char *source) { + if (keep_only_custom_emoji(title_)) { + LOG(ERROR) << "Receive unexpected to do list task entities from " << source; + } + if (!check_utf8(title_.text)) { + LOG(ERROR) << "Receive invalid to do list task from " << source; + title_ = {}; + } +} + +bool operator==(const ToDoItem &lhs, const ToDoItem &rhs) { + return lhs.id_ == rhs.id_ && lhs.title_ == rhs.title_; +} + +bool operator!=(const ToDoItem &lhs, const ToDoItem &rhs) { + return !(lhs == rhs); +} + +} // namespace td diff --git a/td/telegram/ToDoItem.h b/td/telegram/ToDoItem.h new file mode 100644 index 000000000..20aef1dba --- /dev/null +++ b/td/telegram/ToDoItem.h @@ -0,0 +1,42 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025 +// +// 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/MessageEntity.h" +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" + +namespace td { + +class Td; + +class ToDoItem { + int32 id_ = 0; + FormattedText title_; + + void validate(const char *source); + + friend bool operator==(const ToDoItem &lhs, const ToDoItem &rhs); + + public: + ToDoItem() = default; + + ToDoItem(const UserManager *user_manager, telegram_api::object_ptr<telegram_api::todoItem> &&item); + + template <class StorerT> + void store(StorerT &storer) const; + + template <class ParserT> + void parse(ParserT &parser); +}; + +bool operator==(const ToDoItem &lhs, const ToDoItem &rhs); +bool operator!=(const ToDoItem &lhs, const ToDoItem &rhs); + +} // namespace td diff --git a/td/telegram/ToDoItem.hpp b/td/telegram/ToDoItem.hpp new file mode 100644 index 000000000..79dae2c23 --- /dev/null +++ b/td/telegram/ToDoItem.hpp @@ -0,0 +1,34 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025 +// +// 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/ToDoItem.h" + +#include "td/telegram/MessageEntity.hpp" + +#include "td/utils/tl_helpers.h" + +namespace td { + +template <class StorerT> +void ToDoItem::store(StorerT &storer) const { + BEGIN_STORE_FLAGS(); + END_STORE_FLAGS(); + td::store(id_, storer); + td::store(title_, storer); +} + +template <class ParserT> +void ToDoItem::parse(ParserT &parser) { + BEGIN_PARSE_FLAGS(); + END_PARSE_FLAGS(); + td::parse(id_, parser); + td::parse(title_, parser); + validate("parse"); +} + +} // namespace td |
