2020-09-07 13:07:40 +02:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
2020-09-07 13:07:40 +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
|
|
|
|
|
|
|
|
#include "td/telegram/ChannelId.h"
|
2020-09-09 01:32:07 +02:00
|
|
|
#include "td/telegram/DialogId.h"
|
2020-09-15 18:45:45 +02:00
|
|
|
#include "td/telegram/MessageId.h"
|
2020-10-12 09:24:30 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
2020-09-07 13:07:40 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2020-10-08 20:17:24 +02:00
|
|
|
class ContactsManager;
|
2020-10-17 23:07:39 +02:00
|
|
|
class MessagesManager;
|
2020-10-08 20:17:24 +02:00
|
|
|
|
2020-09-07 13:07:40 +02:00
|
|
|
struct MessageReplyInfo {
|
|
|
|
int32 reply_count = -1;
|
|
|
|
int32 pts = -1;
|
2020-09-15 18:45:45 +02:00
|
|
|
vector<DialogId> recent_replier_dialog_ids; // comments only
|
|
|
|
ChannelId channel_id; // comments only
|
2020-09-19 21:01:28 +02:00
|
|
|
MessageId max_message_id;
|
|
|
|
MessageId last_read_inbox_message_id;
|
|
|
|
MessageId last_read_outbox_message_id;
|
2020-09-07 13:07:40 +02:00
|
|
|
bool is_comment = false;
|
|
|
|
|
2021-12-20 13:47:03 +01:00
|
|
|
static constexpr size_t MAX_RECENT_REPLIERS = 3;
|
|
|
|
|
2020-09-07 13:07:40 +02:00
|
|
|
MessageReplyInfo() = default;
|
|
|
|
|
|
|
|
MessageReplyInfo(tl_object_ptr<telegram_api::messageReplies> &&reply_info, bool is_bot);
|
|
|
|
|
|
|
|
bool is_empty() const {
|
|
|
|
return reply_count < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool need_update_to(const MessageReplyInfo &other) const;
|
2020-09-16 15:41:08 +02:00
|
|
|
|
2020-09-18 17:32:59 +02:00
|
|
|
bool update_max_message_ids(MessageId other_max_message_id, MessageId other_last_read_inbox_message_id,
|
|
|
|
MessageId other_last_read_outbox_message_id);
|
2020-09-07 13:07:40 +02:00
|
|
|
|
2020-09-15 18:45:45 +02:00
|
|
|
bool update_max_message_ids(const MessageReplyInfo &other);
|
|
|
|
|
2020-10-31 11:55:53 +01:00
|
|
|
bool add_reply(DialogId replier_dialog_id, MessageId reply_message_id, int diff);
|
2020-09-11 19:12:31 +02:00
|
|
|
|
2020-10-17 23:07:39 +02:00
|
|
|
td_api::object_ptr<td_api::messageReplyInfo> get_message_reply_info_object(
|
|
|
|
ContactsManager *contacts_manager, const MessagesManager *messages_manager) const;
|
2020-10-08 20:17:24 +02:00
|
|
|
|
2020-09-07 13:07:40 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
|
|
|
CHECK(!is_empty());
|
2020-09-09 01:32:07 +02:00
|
|
|
bool has_recent_replier_dialog_ids = !recent_replier_dialog_ids.empty();
|
2020-09-07 13:07:40 +02:00
|
|
|
bool has_channel_id = channel_id.is_valid();
|
2020-09-15 18:45:45 +02:00
|
|
|
bool has_max_message_id = max_message_id.is_valid();
|
2020-09-18 17:32:59 +02:00
|
|
|
bool has_last_read_inbox_message_id = last_read_inbox_message_id.is_valid();
|
|
|
|
bool has_last_read_outbox_message_id = last_read_outbox_message_id.is_valid();
|
2020-09-07 13:07:40 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(is_comment);
|
2020-09-09 01:32:07 +02:00
|
|
|
STORE_FLAG(has_recent_replier_dialog_ids);
|
2020-09-07 13:07:40 +02:00
|
|
|
STORE_FLAG(has_channel_id);
|
2020-09-15 18:45:45 +02:00
|
|
|
STORE_FLAG(has_max_message_id);
|
2020-09-18 17:32:59 +02:00
|
|
|
STORE_FLAG(has_last_read_inbox_message_id);
|
|
|
|
STORE_FLAG(has_last_read_outbox_message_id);
|
2020-09-07 13:07:40 +02:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
td::store(reply_count, storer);
|
|
|
|
td::store(pts, storer);
|
2020-09-09 01:32:07 +02:00
|
|
|
if (has_recent_replier_dialog_ids) {
|
|
|
|
td::store(recent_replier_dialog_ids, storer);
|
2020-09-07 13:07:40 +02:00
|
|
|
}
|
|
|
|
if (has_channel_id) {
|
|
|
|
td::store(channel_id, storer);
|
|
|
|
}
|
2020-09-15 18:45:45 +02:00
|
|
|
if (has_max_message_id) {
|
|
|
|
td::store(max_message_id, storer);
|
|
|
|
}
|
2020-09-18 17:32:59 +02:00
|
|
|
if (has_last_read_inbox_message_id) {
|
|
|
|
td::store(last_read_inbox_message_id, storer);
|
|
|
|
}
|
|
|
|
if (has_last_read_outbox_message_id) {
|
|
|
|
td::store(last_read_outbox_message_id, storer);
|
2020-09-15 18:45:45 +02:00
|
|
|
}
|
2020-09-07 13:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
2020-09-15 18:45:45 +02:00
|
|
|
bool has_recent_replier_dialog_ids;
|
|
|
|
bool has_channel_id;
|
|
|
|
bool has_max_message_id;
|
2020-09-18 17:32:59 +02:00
|
|
|
bool has_last_read_inbox_message_id;
|
|
|
|
bool has_last_read_outbox_message_id;
|
2020-09-07 13:07:40 +02:00
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(is_comment);
|
2020-09-09 01:32:07 +02:00
|
|
|
PARSE_FLAG(has_recent_replier_dialog_ids);
|
2020-09-07 13:07:40 +02:00
|
|
|
PARSE_FLAG(has_channel_id);
|
2020-09-15 18:45:45 +02:00
|
|
|
PARSE_FLAG(has_max_message_id);
|
2020-09-18 17:32:59 +02:00
|
|
|
PARSE_FLAG(has_last_read_inbox_message_id);
|
|
|
|
PARSE_FLAG(has_last_read_outbox_message_id);
|
2020-09-07 13:07:40 +02:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
td::parse(reply_count, parser);
|
|
|
|
td::parse(pts, parser);
|
2020-09-09 01:32:07 +02:00
|
|
|
if (has_recent_replier_dialog_ids) {
|
|
|
|
td::parse(recent_replier_dialog_ids, parser);
|
2020-09-07 13:07:40 +02:00
|
|
|
}
|
|
|
|
if (has_channel_id) {
|
|
|
|
td::parse(channel_id, parser);
|
|
|
|
}
|
2020-09-15 18:45:45 +02:00
|
|
|
if (has_max_message_id) {
|
|
|
|
td::parse(max_message_id, parser);
|
|
|
|
}
|
2020-09-18 17:32:59 +02:00
|
|
|
if (has_last_read_inbox_message_id) {
|
|
|
|
td::parse(last_read_inbox_message_id, parser);
|
|
|
|
}
|
|
|
|
if (has_last_read_outbox_message_id) {
|
|
|
|
td::parse(last_read_outbox_message_id, parser);
|
2020-09-15 18:45:45 +02:00
|
|
|
}
|
2021-09-24 11:31:27 +02:00
|
|
|
if (channel_id.get() == 777) {
|
|
|
|
*this = MessageReplyInfo();
|
|
|
|
}
|
2021-12-20 13:47:03 +01:00
|
|
|
if (recent_replier_dialog_ids.size() > MAX_RECENT_REPLIERS) {
|
|
|
|
recent_replier_dialog_ids.resize(MAX_RECENT_REPLIERS);
|
|
|
|
}
|
2020-09-07 13:07:40 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const MessageReplyInfo &reply_info);
|
|
|
|
|
|
|
|
} // namespace td
|