From 017d1a531d8c9bea13a7bd54b3b4ea77e770cdcf Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 24 Oct 2023 15:02:57 +0300 Subject: [PATCH] Add MessageInputReplyTo storer/parser. --- CMakeLists.txt | 1 + td/telegram/MessageInputReplyTo.cpp | 23 ++++++++++++++ td/telegram/MessageInputReplyTo.h | 24 ++++++++++++-- td/telegram/MessageInputReplyTo.hpp | 49 +++++++++++++++++++++++++++++ td/telegram/MessageOrigin.h | 5 +++ 5 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 td/telegram/MessageInputReplyTo.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1766617bf..5acfb9abd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -867,6 +867,7 @@ set(TDLIB_SOURCE td/telegram/MediaAreaCoordinates.hpp td/telegram/MessageEntity.hpp td/telegram/MessageExtendedMedia.hpp + td/telegram/MessageInputReplyTo.hpp td/telegram/MessageOrigin.hpp td/telegram/MessageReaction.hpp td/telegram/MessageReplyInfo.hpp diff --git a/td/telegram/MessageInputReplyTo.cpp b/td/telegram/MessageInputReplyTo.cpp index 0c2d088ed..b4c5dfc1b 100644 --- a/td/telegram/MessageInputReplyTo.cpp +++ b/td/telegram/MessageInputReplyTo.cpp @@ -8,6 +8,7 @@ #include "td/telegram/ContactsManager.h" #include "td/telegram/DialogId.h" +#include "td/telegram/MessagesManager.h" #include "td/telegram/StoryId.h" #include "td/telegram/Td.h" @@ -66,6 +67,28 @@ telegram_api::object_ptr MessageInputReplyTo::get_in nullptr, string(), Auto()); } +td_api::object_ptr MessageInputReplyTo::get_input_message_reply_to_object( + Td *td, DialogId dialog_id) const { + CHECK(dialog_id.is_valid()); + if (story_full_id_.is_valid()) { + return td_api::make_object( + td->messages_manager_->get_chat_id_object(story_full_id_.get_dialog_id(), "inputMessageReplyToStory"), + story_full_id_.get_story_id().get()); + } + if (!message_id_.is_valid()) { + return nullptr; + } + return td_api::make_object(message_id_.get()); +} + +bool operator==(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs) { + return lhs.message_id_ == rhs.message_id_ && lhs.story_full_id_ == rhs.story_full_id_; +} + +bool operator!=(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs) { + return !(lhs == rhs); +} + StringBuilder &operator<<(StringBuilder &string_builder, const MessageInputReplyTo &input_reply_to) { if (input_reply_to.message_id_.is_valid()) { return string_builder << input_reply_to.message_id_; diff --git a/td/telegram/MessageInputReplyTo.h b/td/telegram/MessageInputReplyTo.h index 146c92e29..2c9f9e6a5 100644 --- a/td/telegram/MessageInputReplyTo.h +++ b/td/telegram/MessageInputReplyTo.h @@ -23,9 +23,7 @@ struct MessageInputReplyTo { // or StoryFullId story_full_id_; - bool is_valid() const { - return message_id_.is_valid() || story_full_id_.is_valid(); - } + friend bool operator==(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs); MessageInputReplyTo() = default; @@ -35,10 +33,30 @@ struct MessageInputReplyTo { explicit MessageInputReplyTo(StoryFullId story_full_id) : story_full_id_(story_full_id) { } + bool is_empty() const { + return !message_id_.is_valid() && !story_full_id_.is_valid(); + } + + bool is_valid() const { + return !is_empty(); + } + telegram_api::object_ptr get_input_reply_to(Td *td, MessageId top_thread_message_id) const; + + td_api::object_ptr get_input_message_reply_to_object(Td *td, DialogId dialog_id) const; + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); }; +bool operator==(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs); + +bool operator!=(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs); + StringBuilder &operator<<(StringBuilder &string_builder, const MessageInputReplyTo &input_reply_to); } // namespace td diff --git a/td/telegram/MessageInputReplyTo.hpp b/td/telegram/MessageInputReplyTo.hpp new file mode 100644 index 000000000..6912bded5 --- /dev/null +++ b/td/telegram/MessageInputReplyTo.hpp @@ -0,0 +1,49 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// 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/MessageInputReplyTo.h" + +#include "td/telegram/MessageOrigin.hpp" + +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void MessageInputReplyTo::store(StorerT &storer) const { + bool has_message_id = message_id_.is_valid(); + bool has_story_full_id = story_full_id_.is_valid(); + BEGIN_STORE_FLAGS(); + STORE_FLAG(has_message_id); + STORE_FLAG(has_story_full_id); + END_STORE_FLAGS(); + if (has_message_id) { + td::store(message_id_, storer); + } + if (has_story_full_id) { + td::store(story_full_id_, storer); + } +} + +template +void MessageInputReplyTo::parse(ParserT &parser) { + bool has_message_id = message_id_.is_valid(); + bool has_story_full_id = story_full_id_.is_valid(); + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(has_message_id); + PARSE_FLAG(has_story_full_id); + END_PARSE_FLAGS(); + if (has_message_id) { + td::parse(message_id_, parser); + } + if (has_story_full_id) { + td::parse(story_full_id_, parser); + } +} + +} // namespace td diff --git a/td/telegram/MessageOrigin.h b/td/telegram/MessageOrigin.h index 234ea5ac5..b722d5e88 100644 --- a/td/telegram/MessageOrigin.h +++ b/td/telegram/MessageOrigin.h @@ -46,6 +46,11 @@ class MessageOrigin { static Result get_message_origin( Td *td, telegram_api::object_ptr &&forward_header); + bool is_empty() const { + return !sender_user_id_.is_valid() && !sender_dialog_id_.is_valid() && !message_id_.is_valid() && + author_signature_.empty() && sender_name_.empty(); + } + td_api::object_ptr get_message_forward_origin_object(const Td *td) const; bool is_sender_hidden() const;