2023-06-08 16:27:24 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2023-06-08 16:27:24 +02:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2023-10-24 18:03:10 +02:00
|
|
|
#include "td/telegram/DialogId.h"
|
2023-10-27 12:06:38 +02:00
|
|
|
#include "td/telegram/MessageEntity.h"
|
2023-10-24 18:03:10 +02:00
|
|
|
#include "td/telegram/MessageFullId.h"
|
2023-06-08 16:27:24 +02:00
|
|
|
#include "td/telegram/MessageId.h"
|
|
|
|
#include "td/telegram/StoryFullId.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 {
|
|
|
|
|
2023-10-29 09:26:21 +01:00
|
|
|
class Dependencies;
|
|
|
|
|
2023-06-08 16:27:24 +02:00
|
|
|
class Td;
|
|
|
|
|
2023-10-27 02:03:52 +02:00
|
|
|
class MessageInputReplyTo {
|
2023-06-08 16:27:24 +02:00
|
|
|
MessageId message_id_;
|
2023-10-28 23:50:33 +02:00
|
|
|
DialogId dialog_id_;
|
2023-10-27 12:06:38 +02:00
|
|
|
FormattedText quote_;
|
2023-11-10 11:29:37 +01:00
|
|
|
int32 quote_position_ = 0;
|
2023-06-08 16:27:24 +02:00
|
|
|
// or
|
|
|
|
StoryFullId story_full_id_;
|
|
|
|
|
2023-10-24 14:02:57 +02:00
|
|
|
friend bool operator==(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs);
|
2023-06-08 16:27:24 +02:00
|
|
|
|
2023-10-27 02:03:52 +02:00
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const MessageInputReplyTo &input_reply_to);
|
|
|
|
|
|
|
|
friend class RepliedMessageInfo;
|
|
|
|
|
|
|
|
public:
|
2023-06-08 16:27:24 +02:00
|
|
|
MessageInputReplyTo() = default;
|
2023-10-27 02:37:26 +02:00
|
|
|
MessageInputReplyTo(const MessageInputReplyTo &) = delete;
|
|
|
|
MessageInputReplyTo &operator=(const MessageInputReplyTo &) = delete;
|
|
|
|
MessageInputReplyTo(MessageInputReplyTo &&) = default;
|
|
|
|
MessageInputReplyTo &operator=(MessageInputReplyTo &&) = default;
|
|
|
|
~MessageInputReplyTo();
|
2023-06-08 16:27:24 +02:00
|
|
|
|
2023-11-10 11:29:37 +01:00
|
|
|
MessageInputReplyTo(MessageId message_id, DialogId dialog_id, FormattedText &"e, int32 quote_position)
|
|
|
|
: message_id_(message_id)
|
|
|
|
, dialog_id_(dialog_id)
|
|
|
|
, quote_(std::move(quote))
|
|
|
|
, quote_position_(max(0, quote_position)) {
|
2023-10-29 00:25:21 +02:00
|
|
|
remove_unallowed_quote_entities(quote_);
|
2023-06-08 16:27:24 +02:00
|
|
|
}
|
|
|
|
|
2023-10-06 12:05:50 +02:00
|
|
|
explicit MessageInputReplyTo(StoryFullId story_full_id) : story_full_id_(story_full_id) {
|
|
|
|
}
|
2023-06-08 16:27:24 +02:00
|
|
|
|
2023-10-25 01:07:37 +02:00
|
|
|
MessageInputReplyTo(Td *td, telegram_api::object_ptr<telegram_api::InputReplyTo> &&input_reply_to);
|
|
|
|
|
2023-10-24 14:02:57 +02:00
|
|
|
bool is_empty() const {
|
2023-10-25 12:07:25 +02:00
|
|
|
return !message_id_.is_valid() && !message_id_.is_valid_scheduled() && !story_full_id_.is_valid();
|
2023-10-24 14:02:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_valid() const {
|
|
|
|
return !is_empty();
|
|
|
|
}
|
|
|
|
|
2023-11-06 11:20:16 +01:00
|
|
|
bool has_quote() const {
|
|
|
|
return !quote_.text.empty();
|
|
|
|
}
|
|
|
|
|
2023-11-10 11:29:37 +01:00
|
|
|
void set_quote(FormattedText &"e, int32 quote_position) {
|
2023-11-06 11:20:16 +01:00
|
|
|
quote_ = std::move(quote);
|
2023-11-10 11:29:37 +01:00
|
|
|
quote_position_ = max(0, quote_position);
|
2023-11-06 11:20:16 +01:00
|
|
|
}
|
|
|
|
|
2023-10-27 02:03:52 +02:00
|
|
|
StoryFullId get_story_full_id() const {
|
|
|
|
return story_full_id_;
|
|
|
|
}
|
|
|
|
|
2024-03-13 14:08:49 +01:00
|
|
|
MessageInputReplyTo clone() const {
|
|
|
|
if (story_full_id_.is_valid()) {
|
|
|
|
return MessageInputReplyTo(story_full_id_);
|
|
|
|
}
|
|
|
|
return MessageInputReplyTo(message_id_, dialog_id_, FormattedText(quote_), quote_position_);
|
|
|
|
}
|
|
|
|
|
2023-10-29 09:26:21 +01:00
|
|
|
void add_dependencies(Dependencies &dependencies) const;
|
|
|
|
|
2023-06-08 16:27:24 +02:00
|
|
|
telegram_api::object_ptr<telegram_api::InputReplyTo> get_input_reply_to(Td *td,
|
|
|
|
MessageId top_thread_message_id) const;
|
2023-10-24 14:02:57 +02:00
|
|
|
|
2023-10-28 23:50:33 +02:00
|
|
|
td_api::object_ptr<td_api::InputMessageReplyTo> get_input_message_reply_to_object(Td *td) const;
|
2023-10-24 14:02:57 +02:00
|
|
|
|
2023-10-27 12:33:00 +02:00
|
|
|
void set_message_id(MessageId new_message_id) {
|
|
|
|
CHECK(message_id_.is_valid() || message_id_.is_valid_scheduled());
|
|
|
|
message_id_ = new_message_id;
|
|
|
|
}
|
|
|
|
|
2023-10-27 02:03:52 +02:00
|
|
|
MessageId get_same_chat_reply_to_message_id() const;
|
|
|
|
|
2023-10-24 18:03:10 +02:00
|
|
|
MessageFullId get_reply_message_full_id(DialogId owner_dialog_id) const;
|
|
|
|
|
2023-10-24 14:02:57 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2023-06-08 16:27:24 +02:00
|
|
|
};
|
|
|
|
|
2023-10-24 14:02:57 +02:00
|
|
|
bool operator==(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs);
|
|
|
|
|
|
|
|
bool operator!=(const MessageInputReplyTo &lhs, const MessageInputReplyTo &rhs);
|
|
|
|
|
2023-06-08 16:27:24 +02:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const MessageInputReplyTo &input_reply_to);
|
|
|
|
|
2024-01-18 12:59:53 +01:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const MessageInputReplyTo *input_reply_to_ptr);
|
|
|
|
|
2023-06-08 16:27:24 +02:00
|
|
|
} // namespace td
|