2022-09-22 00:46:12 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2022-09-22 00:46:12 +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
|
|
|
|
|
2022-10-12 14:59:58 +02:00
|
|
|
#include "td/telegram/DialogId.h"
|
2022-09-22 00:46:12 +02:00
|
|
|
#include "td/telegram/Dimensions.h"
|
|
|
|
#include "td/telegram/files/FileId.h"
|
|
|
|
#include "td/telegram/Photo.h"
|
2022-10-12 14:59:58 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
2022-09-22 00:46:12 +02:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2022-10-12 14:59:58 +02:00
|
|
|
#include "td/utils/Status.h"
|
2022-09-22 00:46:12 +02:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Td;
|
|
|
|
|
|
|
|
class MessageExtendedMedia {
|
|
|
|
enum class Type : int32 { Empty, Unsupported, Preview, Photo, Video };
|
|
|
|
Type type_ = Type::Empty;
|
|
|
|
|
2022-09-22 14:30:12 +02:00
|
|
|
static constexpr int32 CURRENT_VERSION = 1;
|
|
|
|
|
|
|
|
// for Unsupported
|
|
|
|
int32 unsupported_version_ = 0;
|
|
|
|
|
2022-09-22 00:46:12 +02:00
|
|
|
// for Preview
|
|
|
|
int32 duration_ = 0;
|
|
|
|
Dimensions dimensions_;
|
|
|
|
string minithumbnail_;
|
|
|
|
|
|
|
|
// for Photo
|
|
|
|
Photo photo_;
|
|
|
|
|
|
|
|
// for Video
|
|
|
|
FileId video_file_id_;
|
|
|
|
|
|
|
|
friend bool operator==(const MessageExtendedMedia &lhs, const MessageExtendedMedia &rhs);
|
|
|
|
|
2024-06-21 14:47:12 +02:00
|
|
|
void init_from_media(Td *td, telegram_api::object_ptr<telegram_api::MessageMedia> &&media, DialogId owner_dialog_id);
|
|
|
|
|
2022-09-22 05:39:40 +02:00
|
|
|
bool is_media() const {
|
|
|
|
return type_ != Type::Empty && type_ != Type::Preview;
|
|
|
|
}
|
|
|
|
|
2022-09-22 00:46:12 +02:00
|
|
|
public:
|
|
|
|
MessageExtendedMedia() = default;
|
|
|
|
|
|
|
|
MessageExtendedMedia(Td *td, telegram_api::object_ptr<telegram_api::MessageExtendedMedia> &&extended_media,
|
2024-06-24 15:31:07 +02:00
|
|
|
DialogId owner_dialog_id);
|
2022-09-22 00:46:12 +02:00
|
|
|
|
2024-06-21 14:47:12 +02:00
|
|
|
MessageExtendedMedia(Td *td, telegram_api::object_ptr<telegram_api::MessageMedia> &&media, DialogId owner_dialog_id);
|
|
|
|
|
2022-09-23 15:16:56 +02:00
|
|
|
static Result<MessageExtendedMedia> get_message_extended_media(
|
2024-06-24 15:31:07 +02:00
|
|
|
Td *td, td_api::object_ptr<td_api::inputMessageExtendedMedia> &&paid_media, DialogId owner_dialog_id);
|
2022-09-23 15:16:56 +02:00
|
|
|
|
2022-09-22 00:46:12 +02:00
|
|
|
bool is_empty() const {
|
|
|
|
return type_ == Type::Empty;
|
|
|
|
}
|
|
|
|
|
2024-06-25 14:17:00 +02:00
|
|
|
bool has_input_media() const {
|
|
|
|
return type_ == Type::Photo || type_ == Type::Video;
|
|
|
|
}
|
|
|
|
|
2022-09-22 05:39:40 +02:00
|
|
|
void update_from(const MessageExtendedMedia &old_extended_media);
|
|
|
|
|
2022-09-23 11:07:07 +02:00
|
|
|
bool update_to(Td *td, telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media_ptr,
|
|
|
|
DialogId owner_dialog_id);
|
|
|
|
|
2024-06-20 18:01:21 +02:00
|
|
|
td_api::object_ptr<td_api::MessageExtendedMedia> get_message_extended_media_object(Td *td) const;
|
|
|
|
|
2022-09-22 00:46:12 +02:00
|
|
|
void append_file_ids(const Td *td, vector<FileId> &file_ids) const;
|
|
|
|
|
2022-09-22 17:05:58 +02:00
|
|
|
void delete_thumbnail(Td *td);
|
|
|
|
|
2022-09-22 14:30:12 +02:00
|
|
|
bool need_reget() const {
|
|
|
|
return type_ == Type::Unsupported && unsupported_version_ < CURRENT_VERSION;
|
|
|
|
}
|
|
|
|
|
2022-09-24 21:17:17 +02:00
|
|
|
bool need_poll() const {
|
|
|
|
return type_ == Type::Preview;
|
|
|
|
}
|
|
|
|
|
2022-09-22 17:05:58 +02:00
|
|
|
bool has_media_timestamp() const {
|
|
|
|
return type_ == Type::Video;
|
|
|
|
}
|
|
|
|
|
2022-09-24 21:55:03 +02:00
|
|
|
bool is_equal_but_different(const MessageExtendedMedia &other) const;
|
|
|
|
|
2022-09-22 17:05:58 +02:00
|
|
|
int32 get_duration(const Td *td) const;
|
|
|
|
|
|
|
|
FileId get_upload_file_id() const;
|
|
|
|
|
|
|
|
FileId get_any_file_id() const;
|
|
|
|
|
|
|
|
FileId get_thumbnail_file_id(const Td *td) const;
|
|
|
|
|
2024-06-24 18:51:12 +02:00
|
|
|
void update_file_id_remote(FileId file_id);
|
|
|
|
|
2024-06-25 14:17:00 +02:00
|
|
|
MessageExtendedMedia dup_to_send(Td *td) const;
|
|
|
|
|
2022-09-23 15:16:56 +02:00
|
|
|
telegram_api::object_ptr<telegram_api::InputMedia> get_input_media(
|
|
|
|
Td *td, tl_object_ptr<telegram_api::InputFile> input_file,
|
|
|
|
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const;
|
|
|
|
|
2024-06-25 15:45:37 +02:00
|
|
|
void merge_files(Td *td, MessageExtendedMedia &other, DialogId dialog_id, bool need_merge_files,
|
|
|
|
bool &is_content_changed, bool &need_update) const;
|
|
|
|
|
2022-09-22 00:46:12 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(const MessageExtendedMedia &lhs, const MessageExtendedMedia &rhs);
|
|
|
|
|
|
|
|
bool operator!=(const MessageExtendedMedia &lhs, const MessageExtendedMedia &rhs);
|
|
|
|
|
|
|
|
} // namespace td
|