tdlight/td/telegram/MessageForwardInfo.h

180 lines
5.5 KiB
C
Raw Normal View History

2024-01-11 16:20:53 +01:00
//
// 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
2024-01-11 16:46:10 +01:00
#include "td/telegram/ChannelId.h"
2024-01-11 16:20:53 +01:00
#include "td/telegram/DialogId.h"
2024-01-11 17:11:16 +01:00
#include "td/telegram/MessageFullId.h"
2024-01-11 16:20:53 +01:00
#include "td/telegram/MessageId.h"
#include "td/telegram/MessageOrigin.h"
2024-01-11 16:46:10 +01:00
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
2024-01-11 16:20:53 +01:00
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
namespace td {
2024-01-11 16:46:10 +01:00
class Dependencies;
2024-01-11 16:20:53 +01:00
class Td;
2024-01-11 20:33:12 +01:00
class LastForwardedMessageInfo {
DialogId dialog_id_;
MessageId message_id_;
2024-01-11 22:23:33 +01:00
DialogId sender_dialog_id_;
string sender_name_;
int32 date_ = 0;
bool is_outgoing_ = false;
2024-01-11 20:33:12 +01:00
friend bool operator==(const LastForwardedMessageInfo &lhs, const LastForwardedMessageInfo &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const LastForwardedMessageInfo &last_message_info);
public:
LastForwardedMessageInfo() = default;
2024-01-11 22:23:33 +01:00
LastForwardedMessageInfo(DialogId dialog_id, MessageId message_id, DialogId sender_dialog_id, string sender_name,
int32 date, bool is_outgoing)
: dialog_id_(dialog_id)
, message_id_(message_id)
, sender_dialog_id_(sender_dialog_id)
, sender_name_(std::move(sender_name))
, date_(date)
, is_outgoing_(is_outgoing) {
2024-01-11 20:33:12 +01:00
}
bool is_empty() const;
void validate();
2024-01-11 20:33:12 +01:00
2024-01-11 22:23:33 +01:00
void hide_sender_if_needed(Td *td);
2024-01-11 20:33:12 +01:00
void add_dependencies(Dependencies &dependencies) const;
void add_min_user_ids(vector<UserId> &user_ids) const;
void add_min_channel_ids(vector<ChannelId> &channel_ids) const;
td_api::object_ptr<td_api::forwardSource> get_forward_source_object(Td *td, bool for_saved_messages,
const MessageOrigin &origin,
int32 origin_date) const;
2024-01-11 20:48:22 +01:00
2024-01-11 20:33:12 +01:00
DialogId get_dialog_id() const {
return dialog_id_;
}
MessageFullId get_message_full_id() const {
return {dialog_id_, message_id_};
}
2024-01-11 22:23:33 +01:00
bool has_sender_name() const {
return !sender_name_.empty();
}
2024-01-11 20:33:12 +01:00
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
class MessageForwardInfo {
MessageOrigin origin_;
int32 date_ = 0;
2024-01-11 20:33:12 +01:00
LastForwardedMessageInfo last_message_info_;
string psa_type_;
bool is_imported_ = false;
2024-01-11 16:20:53 +01:00
friend bool operator==(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const MessageForwardInfo &forward_info);
public:
2024-01-11 16:20:53 +01:00
MessageForwardInfo() = default;
2024-01-11 20:33:12 +01:00
MessageForwardInfo(MessageOrigin &&origin, int32 date, LastForwardedMessageInfo &&last_message_info,
2024-01-11 16:20:53 +01:00
string &&psa_type, bool is_imported)
: origin_(std::move(origin))
, date_(date)
2024-01-11 20:33:12 +01:00
, last_message_info_(std::move(last_message_info))
, psa_type_(std::move(psa_type))
, is_imported_(is_imported) {
2024-01-11 20:33:12 +01:00
last_message_info_.validate();
2024-01-11 16:20:53 +01:00
}
2024-01-11 16:46:10 +01:00
static unique_ptr<MessageForwardInfo> get_message_forward_info(
Td *td, telegram_api::object_ptr<telegram_api::messageFwdHeader> &&forward_header);
static unique_ptr<MessageForwardInfo> copy_message_forward_info(Td *td, const MessageForwardInfo &forward_info,
2024-01-11 20:33:12 +01:00
LastForwardedMessageInfo &&last_message_info);
td_api::object_ptr<td_api::messageForwardInfo> get_message_forward_info_object(Td *td, bool for_saved_messages) const;
2024-01-11 16:46:10 +01:00
td_api::object_ptr<td_api::messageImportInfo> get_message_import_info_object() const;
void add_dependencies(Dependencies &dependencies) const;
void add_min_user_ids(vector<UserId> &user_ids) const;
void add_min_channel_ids(vector<ChannelId> &channel_ids) const;
static bool need_change_warning(const MessageForwardInfo *lhs, const MessageForwardInfo *rhs, MessageId message_id);
int32 get_origin_date() const {
return date_;
}
2024-01-11 17:39:32 +01:00
bool is_imported() const {
return is_imported_;
}
const MessageOrigin &get_origin() const {
return origin_;
}
2024-01-11 17:11:16 +01:00
MessageFullId get_origin_message_full_id() const {
return origin_.get_message_full_id();
2024-01-11 17:11:16 +01:00
}
DialogId get_last_dialog_id() const {
2024-01-11 20:33:12 +01:00
return last_message_info_.get_dialog_id();
2024-01-11 17:11:16 +01:00
}
MessageFullId get_last_message_full_id() const {
2024-01-11 20:33:12 +01:00
return last_message_info_.get_message_full_id();
2024-01-11 17:11:16 +01:00
}
bool has_last_sender_name() const {
return last_message_info_.has_sender_name();
}
2024-01-11 16:20:53 +01:00
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
2024-01-11 20:33:12 +01:00
bool operator==(const LastForwardedMessageInfo &lhs, const LastForwardedMessageInfo &rhs);
bool operator!=(const LastForwardedMessageInfo &lhs, const LastForwardedMessageInfo &rhs);
2024-01-11 16:20:53 +01:00
bool operator==(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs);
bool operator!=(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs);
bool operator==(const unique_ptr<MessageForwardInfo> &lhs, const unique_ptr<MessageForwardInfo> &rhs);
bool operator!=(const unique_ptr<MessageForwardInfo> &lhs, const unique_ptr<MessageForwardInfo> &rhs);
2024-01-11 16:20:53 +01:00
StringBuilder &operator<<(StringBuilder &string_builder, const MessageForwardInfo &forward_info);
StringBuilder &operator<<(StringBuilder &string_builder, const unique_ptr<MessageForwardInfo> &forward_info);
2024-01-11 16:20:53 +01:00
} // namespace td