tdlight/td/telegram/Photo.h

144 lines
5.5 KiB
C
Raw Normal View History

//
2022-12-31 22:28:08 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// 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"
2021-08-01 05:17:51 +02:00
#include "td/telegram/EncryptedFile.h"
#include "td/telegram/files/FileId.h"
2022-04-10 00:15:49 +02:00
#include "td/telegram/PhotoSize.h"
#include "td/telegram/secret_api.h"
2021-09-18 23:47:05 +02:00
#include "td/telegram/SecretInputMedia.h"
#include "td/telegram/StickerPhotoSize.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
2021-09-18 23:47:05 +02:00
#include "td/telegram/UserId.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/MovableValue.h"
#include "td/utils/StringBuilder.h"
#include "td/utils/unique_value_ptr.h"
namespace td {
class FileManager;
2023-01-20 15:31:33 +01:00
class Td;
struct DialogPhoto {
FileId small_file_id;
FileId big_file_id;
string minithumbnail;
bool has_animation = false;
2022-12-09 13:52:21 +01:00
bool is_personal = false;
};
struct ProfilePhoto final : public DialogPhoto {
int64 id = 0;
};
struct Photo {
MovableValue<int64, -2> id;
int32 date = 0;
string minithumbnail;
vector<PhotoSize> photos;
vector<AnimationSize> animations;
unique_value_ptr<StickerPhotoSize> sticker_photo_size;
2023-01-18 20:25:25 +01:00
bool has_stickers = false;
vector<FileId> sticker_file_ids;
bool is_empty() const {
return id.get() == -2;
}
2022-09-22 17:25:20 +02:00
bool is_bad() const {
if (is_empty()) {
return true;
}
for (auto &photo_size : photos) {
if (!photo_size.file_id.is_valid()) {
return true;
}
}
return false;
}
};
2022-12-22 20:38:30 +01:00
int64 get_profile_photo_id(const tl_object_ptr<telegram_api::UserProfilePhoto> &profile_photo_ptr);
ProfilePhoto get_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash,
tl_object_ptr<telegram_api::UserProfilePhoto> &&profile_photo_ptr);
tl_object_ptr<td_api::profilePhoto> get_profile_photo_object(FileManager *file_manager,
const ProfilePhoto &profile_photo);
bool need_update_profile_photo(const ProfilePhoto &from, const ProfilePhoto &to);
StringBuilder &operator<<(StringBuilder &string_builder, const ProfilePhoto &profile_photo);
DialogPhoto get_dialog_photo(FileManager *file_manager, DialogId dialog_id, int64 dialog_access_hash,
tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr);
tl_object_ptr<td_api::chatPhotoInfo> get_chat_photo_info_object(FileManager *file_manager,
const DialogPhoto *dialog_photo);
2022-12-09 13:52:21 +01:00
DialogPhoto as_fake_dialog_photo(const Photo &photo, DialogId dialog_id, bool is_personal);
2022-12-09 13:52:21 +01:00
DialogPhoto as_dialog_photo(FileManager *file_manager, DialogId dialog_id, int64 dialog_access_hash, const Photo &photo,
bool is_personal);
2022-04-28 19:33:24 +02:00
2022-12-09 13:52:21 +01:00
ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash, const Photo &photo,
bool is_personal);
2022-04-28 20:02:44 +02:00
bool is_same_dialog_photo(FileManager *file_manager, DialogId dialog_id, const Photo &photo,
2022-12-09 13:52:21 +01:00
const DialogPhoto &dialog_photo, bool is_personal);
2022-04-28 20:02:44 +02:00
vector<FileId> dialog_photo_get_file_ids(const DialogPhoto &dialog_photo);
bool need_update_dialog_photo(const DialogPhoto &from, const DialogPhoto &to);
StringBuilder &operator<<(StringBuilder &string_builder, const DialogPhoto &dialog_photo);
2023-01-20 15:31:33 +01:00
Photo get_photo(Td *td, tl_object_ptr<telegram_api::Photo> &&photo, DialogId owner_dialog_id);
Photo get_photo(Td *td, tl_object_ptr<telegram_api::photo> &&photo, DialogId owner_dialog_id);
2021-08-01 05:17:51 +02:00
Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr<EncryptedFile> &&file,
tl_object_ptr<secret_api::decryptedMessageMediaPhoto> &&photo, DialogId owner_dialog_id);
Photo get_web_document_photo(FileManager *file_manager, tl_object_ptr<telegram_api::WebDocument> web_document,
DialogId owner_dialog_id);
tl_object_ptr<td_api::photo> get_photo_object(FileManager *file_manager, const Photo &photo);
tl_object_ptr<td_api::chatPhoto> get_chat_photo_object(FileManager *file_manager, const Photo &photo);
void photo_delete_thumbnail(Photo &photo);
bool photo_has_input_media(FileManager *file_manager, const Photo &photo, bool is_secret, bool is_bot);
2022-09-22 17:25:20 +02:00
FileId get_photo_upload_file_id(const Photo &photo);
FileId get_photo_any_file_id(const Photo &photo);
FileId get_photo_thumbnail_file_id(const Photo &photo);
SecretInputMedia photo_get_secret_input_media(FileManager *file_manager, const Photo &photo,
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
const string &caption, BufferSlice thumbnail);
tl_object_ptr<telegram_api::InputMedia> photo_get_input_media(FileManager *file_manager, const Photo &photo,
tl_object_ptr<telegram_api::InputFile> input_file,
int32 ttl, bool has_spoiler);
vector<FileId> photo_get_file_ids(const Photo &photo);
bool operator==(const Photo &lhs, const Photo &rhs);
bool operator!=(const Photo &lhs, const Photo &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const Photo &photo);
tl_object_ptr<telegram_api::userProfilePhoto> convert_photo_to_profile_photo(
2022-12-09 13:52:21 +01:00
const tl_object_ptr<telegram_api::photo> &photo, bool is_personal);
} // namespace td