2019-01-30 22:37:38 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2019-01-30 22:37:38 +01: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/AnimationsManager.h"
|
2022-08-10 20:12:05 +02:00
|
|
|
#include "td/telegram/AttachMenuManager.h"
|
2019-05-07 04:51:56 +02:00
|
|
|
#include "td/telegram/BackgroundManager.h"
|
2024-07-18 17:32:57 +02:00
|
|
|
#include "td/telegram/BotInfoManager.h"
|
2019-01-30 22:37:38 +01:00
|
|
|
#include "td/telegram/ChannelId.h"
|
|
|
|
#include "td/telegram/ChatId.h"
|
2024-04-02 12:06:22 +02:00
|
|
|
#include "td/telegram/ChatManager.h"
|
2019-01-30 22:37:38 +01:00
|
|
|
#include "td/telegram/FileReferenceManager.h"
|
|
|
|
#include "td/telegram/files/FileSourceId.h"
|
2023-09-21 18:11:17 +02:00
|
|
|
#include "td/telegram/MessageFullId.h"
|
2019-01-30 22:37:38 +01:00
|
|
|
#include "td/telegram/MessagesManager.h"
|
2022-04-15 15:27:30 +02:00
|
|
|
#include "td/telegram/NotificationSettingsManager.h"
|
2024-02-29 15:41:05 +01:00
|
|
|
#include "td/telegram/QuickReplyManager.h"
|
|
|
|
#include "td/telegram/QuickReplyMessageFullId.h"
|
2024-06-28 13:05:25 +02:00
|
|
|
#include "td/telegram/StarManager.h"
|
2019-02-02 11:30:49 +01:00
|
|
|
#include "td/telegram/StickersManager.h"
|
2023-05-20 00:23:33 +02:00
|
|
|
#include "td/telegram/StoryFullId.h"
|
|
|
|
#include "td/telegram/StoryManager.h"
|
2019-01-30 22:37:38 +01:00
|
|
|
#include "td/telegram/Td.h"
|
|
|
|
#include "td/telegram/UserId.h"
|
2024-04-02 02:52:34 +02:00
|
|
|
#include "td/telegram/UserManager.h"
|
2019-01-30 22:37:38 +01:00
|
|
|
#include "td/telegram/WebPagesManager.h"
|
|
|
|
|
2019-02-12 22:26:36 +01:00
|
|
|
#include "td/utils/common.h"
|
2019-01-30 22:37:38 +01:00
|
|
|
#include "td/utils/overloaded.h"
|
|
|
|
#include "td/utils/tl_helpers.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void FileReferenceManager::store_file_source(FileSourceId file_source_id, StorerT &storer) const {
|
|
|
|
auto index = static_cast<size_t>(file_source_id.get()) - 1;
|
|
|
|
CHECK(index < file_sources_.size());
|
|
|
|
auto &source = file_sources_[index];
|
|
|
|
td::store(source.get_offset(), storer);
|
2024-06-28 13:05:25 +02:00
|
|
|
source.visit(overloaded([&](const FileSourceMessage &source) { td::store(source.message_full_id, storer); },
|
|
|
|
[&](const FileSourceUserPhoto &source) {
|
|
|
|
td::store(source.user_id, storer);
|
|
|
|
td::store(source.photo_id, storer);
|
|
|
|
},
|
|
|
|
[&](const FileSourceChatPhoto &source) { td::store(source.chat_id, storer); },
|
|
|
|
[&](const FileSourceChannelPhoto &source) { td::store(source.channel_id, storer); },
|
|
|
|
[&](const FileSourceWallpapers &source) {},
|
|
|
|
[&](const FileSourceWebPage &source) { td::store(source.url, storer); },
|
|
|
|
[&](const FileSourceSavedAnimations &source) {},
|
|
|
|
[&](const FileSourceRecentStickers &source) { td::store(source.is_attached, storer); },
|
|
|
|
[&](const FileSourceFavoriteStickers &source) {},
|
|
|
|
[&](const FileSourceBackground &source) {
|
|
|
|
td::store(source.background_id, storer);
|
|
|
|
td::store(source.access_hash, storer);
|
|
|
|
},
|
|
|
|
[&](const FileSourceChatFull &source) { td::store(source.chat_id, storer); },
|
|
|
|
[&](const FileSourceChannelFull &source) { td::store(source.channel_id, storer); },
|
|
|
|
[&](const FileSourceAppConfig &source) {}, [&](const FileSourceSavedRingtones &source) {},
|
|
|
|
[&](const FileSourceUserFull &source) { td::store(source.user_id, storer); },
|
|
|
|
[&](const FileSourceAttachMenuBot &source) { td::store(source.user_id, storer); },
|
|
|
|
[&](const FileSourceWebApp &source) {
|
|
|
|
td::store(source.user_id, storer);
|
|
|
|
td::store(source.short_name, storer);
|
|
|
|
},
|
|
|
|
[&](const FileSourceStory &source) { td::store(source.story_full_id, storer); },
|
|
|
|
[&](const FileSourceQuickReplyMessage &source) { td::store(source.message_full_id, storer); },
|
|
|
|
[&](const FileSourceStarTransaction &source) {
|
|
|
|
td::store(source.dialog_id, storer);
|
|
|
|
td::store(source.transaction_id, storer);
|
|
|
|
td::store(source.is_refund, storer);
|
2024-07-18 17:32:57 +02:00
|
|
|
},
|
|
|
|
[&](const FileSourceBotMediaPreview &source) { td::store(source.bot_user_id, storer); }));
|
2019-01-30 22:37:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
FileSourceId FileReferenceManager::parse_file_source(Td *td, ParserT &parser) {
|
|
|
|
auto type = parser.fetch_int();
|
|
|
|
switch (type) {
|
|
|
|
case 0: {
|
2023-09-21 18:11:17 +02:00
|
|
|
MessageFullId message_full_id;
|
|
|
|
td::parse(message_full_id, parser);
|
|
|
|
return td->messages_manager_->get_message_file_source_id(message_full_id);
|
2019-01-30 22:37:38 +01:00
|
|
|
}
|
|
|
|
case 1: {
|
|
|
|
UserId user_id;
|
|
|
|
int64 photo_id;
|
|
|
|
td::parse(user_id, parser);
|
|
|
|
td::parse(photo_id, parser);
|
2024-04-02 02:52:34 +02:00
|
|
|
return td->user_manager_->get_user_profile_photo_file_source_id(user_id, photo_id);
|
2019-01-30 22:37:38 +01:00
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
ChatId chat_id;
|
|
|
|
td::parse(chat_id, parser);
|
2020-06-27 16:05:45 +02:00
|
|
|
return FileSourceId(); // there is no need to repair chat photos
|
2019-01-30 22:37:38 +01:00
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
ChannelId channel_id;
|
|
|
|
td::parse(channel_id, parser);
|
2020-06-27 16:05:45 +02:00
|
|
|
return FileSourceId(); // there is no need to repair channel photos
|
2019-01-30 22:37:38 +01:00
|
|
|
}
|
|
|
|
case 4:
|
2019-05-07 04:51:56 +02:00
|
|
|
return FileSourceId(); // there is no way to repair old wallpapers
|
2019-01-30 22:37:38 +01:00
|
|
|
case 5: {
|
|
|
|
string url;
|
|
|
|
td::parse(url, parser);
|
|
|
|
return td->web_pages_manager_->get_url_file_source_id(url);
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
return td->animations_manager_->get_saved_animations_file_source_id();
|
2019-02-02 11:30:49 +01:00
|
|
|
case 7: {
|
|
|
|
bool is_attached;
|
|
|
|
td::parse(is_attached, parser);
|
|
|
|
return td->stickers_manager_->get_recent_stickers_file_source_id(is_attached);
|
|
|
|
}
|
2019-02-02 11:54:40 +01:00
|
|
|
case 8:
|
|
|
|
return td->stickers_manager_->get_favorite_stickers_file_source_id();
|
2019-05-09 03:07:21 +02:00
|
|
|
case 9: {
|
|
|
|
BackgroundId background_id;
|
|
|
|
int64 access_hash;
|
|
|
|
td::parse(background_id, parser);
|
|
|
|
td::parse(access_hash, parser);
|
|
|
|
return td->background_manager_->get_background_file_source_id(background_id, access_hash);
|
|
|
|
}
|
2020-07-06 14:26:29 +02:00
|
|
|
case 10: {
|
|
|
|
ChatId chat_id;
|
|
|
|
td::parse(chat_id, parser);
|
2024-04-02 12:06:22 +02:00
|
|
|
return td->chat_manager_->get_chat_full_file_source_id(chat_id);
|
2020-07-06 14:26:29 +02:00
|
|
|
}
|
|
|
|
case 11: {
|
|
|
|
ChannelId channel_id;
|
|
|
|
td::parse(channel_id, parser);
|
2024-04-02 12:06:22 +02:00
|
|
|
return td->chat_manager_->get_channel_full_file_source_id(channel_id);
|
2020-07-06 14:26:29 +02:00
|
|
|
}
|
2021-10-08 12:41:22 +02:00
|
|
|
case 12:
|
|
|
|
return td->stickers_manager_->get_app_config_file_source_id();
|
2022-04-15 15:27:30 +02:00
|
|
|
case 13:
|
|
|
|
return td->notification_settings_manager_->get_saved_ringtones_file_source_id();
|
2022-08-06 12:42:35 +02:00
|
|
|
case 14: {
|
|
|
|
UserId user_id;
|
|
|
|
td::parse(user_id, parser);
|
2024-04-02 02:52:34 +02:00
|
|
|
return td->user_manager_->get_user_full_file_source_id(user_id);
|
2022-08-06 12:42:35 +02:00
|
|
|
}
|
2022-08-10 20:12:05 +02:00
|
|
|
case 15: {
|
|
|
|
UserId user_id;
|
|
|
|
td::parse(user_id, parser);
|
|
|
|
return td->attach_menu_manager_->get_attach_menu_bot_file_source_id(user_id);
|
|
|
|
}
|
2023-02-28 12:11:49 +01:00
|
|
|
case 16: {
|
|
|
|
UserId user_id;
|
|
|
|
string short_name;
|
|
|
|
td::parse(user_id, parser);
|
|
|
|
td::parse(short_name, parser);
|
|
|
|
return td->attach_menu_manager_->get_web_app_file_source_id(user_id, short_name);
|
|
|
|
}
|
2023-05-20 00:23:33 +02:00
|
|
|
case 17: {
|
|
|
|
StoryFullId story_full_id;
|
|
|
|
td::parse(story_full_id, parser);
|
|
|
|
return td->story_manager_->get_story_file_source_id(story_full_id);
|
|
|
|
}
|
2024-02-29 15:41:05 +01:00
|
|
|
case 18: {
|
|
|
|
QuickReplyMessageFullId message_full_id;
|
|
|
|
td::parse(message_full_id, parser);
|
|
|
|
return td->quick_reply_manager_->get_quick_reply_message_file_source_id(message_full_id);
|
|
|
|
}
|
2024-06-28 13:05:25 +02:00
|
|
|
case 19: {
|
|
|
|
DialogId dialog_id;
|
|
|
|
string transaction_id;
|
|
|
|
bool is_refund;
|
|
|
|
td::parse(dialog_id, parser);
|
|
|
|
td::parse(transaction_id, parser);
|
|
|
|
td::parse(is_refund, parser);
|
|
|
|
return td->star_manager_->get_star_transaction_file_source_id(dialog_id, transaction_id, is_refund);
|
|
|
|
}
|
2024-07-18 17:32:57 +02:00
|
|
|
case 20: {
|
|
|
|
UserId bot_user_id;
|
|
|
|
td::parse(bot_user_id, parser);
|
|
|
|
return td->bot_info_manager_->get_bot_media_preview_file_source_id(bot_user_id);
|
|
|
|
}
|
2019-01-30 22:37:38 +01:00
|
|
|
default:
|
|
|
|
parser.set_error("Invalid type in FileSource");
|
|
|
|
return FileSourceId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|