diff --git a/CMakeLists.txt b/CMakeLists.txt index 93cd5407f..6a8303d24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -461,6 +461,7 @@ set(TDLIB_SOURCE_PART1 td/telegram/MessageOrigin.cpp td/telegram/MessageQuote.cpp td/telegram/MessageReaction.cpp + td/telegram/MessageReactor.cpp td/telegram/MessageReplyHeader.cpp td/telegram/MessageReplyInfo.cpp td/telegram/MessageSearchFilter.cpp @@ -779,6 +780,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/MessageOrigin.h td/telegram/MessageQuote.h td/telegram/MessageReaction.h + td/telegram/MessageReactor.h td/telegram/MessageReplyHeader.h td/telegram/MessageReplyInfo.h td/telegram/MessageSearchFilter.h @@ -1002,6 +1004,7 @@ set(TDLIB_SOURCE_PART2 td/telegram/MessageOrigin.hpp td/telegram/MessageQuote.hpp td/telegram/MessageReaction.hpp + td/telegram/MessageReactor.hpp td/telegram/MessageReplyInfo.hpp td/telegram/MinChannel.hpp td/telegram/NotificationGroupInfo.hpp diff --git a/SplitSource.php b/SplitSource.php index 1a1b12152..f3ac19b13 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -378,6 +378,7 @@ function split_file($file, $chunks, $undo) { 'MessageLinkInfo' => 'MessageLinkInfo', 'MessageQuote' => 'MessageQuote', 'MessageReaction|UnreadMessageReaction|[a-z_]*message[a-z_]*reaction' => 'MessageReaction', + 'MessageReactor' => 'MessageReactor', 'MessageSearchOffset' => 'MessageSearchOffset', '[a-z_]*_message_sender' => 'MessageSender', 'messages_manager[_(-](?![.]get[(][)])|MessagesManager' => 'MessagesManager', diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ba893b1f8..b7d9e5e4c 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1495,6 +1495,14 @@ reactionTypeCustomEmoji custom_emoji_id:int64 = ReactionType; reactionTypePaid = ReactionType; +//@description Contains information about a user that added paid reactions +//@sender_id Identifier of the user or chat that added the reactions; may be null for anonymous reactors that aren't the current user +//@star_count Number of Telegram Stars added +//@is_top True, if the reactor is one of the most active reactors; can be false if the reactor is the current user +//@is_me True, if the paid reaction was added by the current user +//@is_anonymous True, if the reactor is anonymous +paidReactor sender_id:MessageSender star_count:int32 is_top:Bool is_me:Bool is_anonymous:Bool = PaidReactor; + //@description Contains information about a forwarded message //@origin Origin of the forwarded message //@date Point in time (Unix timestamp) when the message was originally sent diff --git a/td/telegram/MessageReactor.cpp b/td/telegram/MessageReactor.cpp new file mode 100644 index 000000000..64e7cfe6c --- /dev/null +++ b/td/telegram/MessageReactor.cpp @@ -0,0 +1,36 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 +// +// 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/MessageReactor.h" + +#include "td/telegram/MessageSender.h" + +namespace td { + +MessageReactor::MessageReactor(telegram_api::object_ptr &&reactor) + : dialog_id_(reactor->peer_id_ == nullptr ? DialogId() : DialogId(reactor->peer_id_)) + , count_(reactor->count_) + , is_top_(reactor->top_) + , is_me_(reactor->my_) + , is_anonymous_(reactor->anonymous_) { +} + +td_api::object_ptr MessageReactor::get_paid_reactor_object(Td *td) const { + return td_api::make_object( + dialog_id_ == DialogId() ? nullptr : get_message_sender_object(td, dialog_id_, "paidReactor"), count_, is_top_, + is_me_, is_anonymous_); +} + +bool operator==(const MessageReactor &lhs, const MessageReactor &rhs) { + return lhs.dialog_id_ == rhs.dialog_id_ && lhs.count_ == rhs.count_ && lhs.is_top_ == rhs.is_top_ && + lhs.is_me_ == rhs.is_me_ && lhs.is_anonymous_ == rhs.is_anonymous_; +} + +StringBuilder &operator<<(StringBuilder &string_builder, const MessageReactor &reactor) { + return string_builder << "PaidReactor[" << reactor.dialog_id_ << " - " << reactor.count_ << ']'; +} + +} // namespace td diff --git a/td/telegram/MessageReactor.h b/td/telegram/MessageReactor.h new file mode 100644 index 000000000..b709c42c0 --- /dev/null +++ b/td/telegram/MessageReactor.h @@ -0,0 +1,57 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 +// +// 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/DialogId.h" +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class Td; + +class MessageReactor { + DialogId dialog_id_; + int32 count_ = 0; + bool is_top_ = false; + bool is_me_ = false; + bool is_anonymous_ = false; + + friend bool operator==(const MessageReactor &lhs, const MessageReactor &rhs); + + friend StringBuilder &operator<<(StringBuilder &string_builder, const MessageReactor &reactor); + + public: + MessageReactor() = default; + + explicit MessageReactor(telegram_api::object_ptr &&reactor); + + bool is_valid() const { + return (dialog_id_.is_valid() || (!is_me_ && !is_anonymous_)) && count_ > 0; + } + + td_api::object_ptr get_paid_reactor_object(Td *td) const; + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); +}; + +bool operator==(const MessageReactor &lhs, const MessageReactor &rhs); + +inline bool operator!=(const MessageReactor &lhs, const MessageReactor &rhs) { + return !(lhs == rhs); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const MessageReactor &reactor); + +} // namespace td diff --git a/td/telegram/MessageReactor.hpp b/td/telegram/MessageReactor.hpp new file mode 100644 index 000000000..d50f21ba9 --- /dev/null +++ b/td/telegram/MessageReactor.hpp @@ -0,0 +1,46 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 +// +// 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/MessageReactor.h" + +#include "td/utils/common.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void MessageReactor::store(StorerT &storer) const { + bool has_dialog_id = dialog_id_.is_valid(); + BEGIN_STORE_FLAGS(); + STORE_FLAG(is_top_); + STORE_FLAG(is_me_); + STORE_FLAG(is_anonymous_); + STORE_FLAG(has_dialog_id); + END_STORE_FLAGS(); + if (has_dialog_id) { + td::store(dialog_id_, storer); + } + td::store(count_, storer); +} + +template +void MessageReactor::parse(ParserT &parser) { + bool has_dialog_id; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(is_top_); + PARSE_FLAG(is_me_); + PARSE_FLAG(is_anonymous_); + PARSE_FLAG(has_dialog_id); + END_PARSE_FLAGS(); + if (has_dialog_id) { + td::parse(dialog_id_, parser); + } + td::parse(count_, parser); +} + +} // namespace td