Support file reference repair for bot media preview info.
This commit is contained in:
parent
61ce58b133
commit
15eb2754bd
@ -181,9 +181,10 @@ class GetPreviewInfoQuery final : public Td::ResultHandler {
|
||||
}
|
||||
}
|
||||
if (!file_ids.empty()) {
|
||||
// auto file_source_id = td_->bot_info_manager_->get_bot_media_preview_file_source_id(bot_user_id_);
|
||||
auto file_source_id =
|
||||
td_->bot_info_manager_->get_bot_media_preview_info_file_source_id(bot_user_id_, language_code_);
|
||||
for (auto file_id : file_ids) {
|
||||
// td_->file_manager_->add_file_source(file_id, file_source_id);
|
||||
td_->file_manager_->add_file_source(file_id, file_source_id);
|
||||
}
|
||||
}
|
||||
promise_.set_value(
|
||||
@ -251,7 +252,8 @@ class BotInfoManager::AddPreviewMediaQuery final : public Td::ResultHandler {
|
||||
}
|
||||
auto file_ids = get_story_content_file_ids(td_, content.get());
|
||||
if (!file_ids.empty()) {
|
||||
auto file_source_id = td_->bot_info_manager_->get_bot_media_preview_file_source_id(bot_user_id);
|
||||
auto file_source_id = td_->bot_info_manager_->get_bot_media_preview_info_file_source_id(
|
||||
bot_user_id, pending_preview_->language_code_);
|
||||
for (auto file_id : file_ids) {
|
||||
td_->file_manager_->add_file_source(file_id, file_source_id);
|
||||
}
|
||||
@ -566,7 +568,8 @@ BotInfoManager::BotInfoManager(Td *td, ActorShared<> parent) : td_(td), parent_(
|
||||
}
|
||||
|
||||
BotInfoManager::~BotInfoManager() {
|
||||
Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), bot_media_preview_file_source_ids_);
|
||||
Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), bot_media_preview_file_source_ids_,
|
||||
bot_media_preview_info_file_source_ids_);
|
||||
}
|
||||
|
||||
void BotInfoManager::tear_down() {
|
||||
@ -675,6 +678,21 @@ FileSourceId BotInfoManager::get_bot_media_preview_file_source_id(UserId bot_use
|
||||
return source_id;
|
||||
}
|
||||
|
||||
FileSourceId BotInfoManager::get_bot_media_preview_info_file_source_id(UserId bot_user_id,
|
||||
const string &language_code) {
|
||||
if (!bot_user_id.is_valid()) {
|
||||
return FileSourceId();
|
||||
}
|
||||
|
||||
auto &source_id = bot_media_preview_info_file_source_ids_[{bot_user_id, language_code}];
|
||||
if (!source_id.is_valid()) {
|
||||
source_id = td_->file_reference_manager_->create_bot_media_preview_info_file_source(bot_user_id, language_code);
|
||||
}
|
||||
VLOG(file_references) << "Return " << source_id << " for media preview info of " << bot_user_id << " for "
|
||||
<< language_code;
|
||||
return source_id;
|
||||
}
|
||||
|
||||
Result<telegram_api::object_ptr<telegram_api::InputUser>> BotInfoManager::get_media_preview_bot_input_user(
|
||||
UserId user_id, bool can_be_edited) {
|
||||
TRY_RESULT(bot_data, td_->user_manager_->get_bot_data(user_id));
|
||||
@ -712,6 +730,20 @@ void BotInfoManager::reload_bot_media_previews(UserId bot_user_id, Promise<Unit>
|
||||
}));
|
||||
}
|
||||
|
||||
void BotInfoManager::reload_bot_media_preview_info(UserId bot_user_id, const string &language_code,
|
||||
Promise<Unit> &&promise) {
|
||||
get_bot_media_preview_info(
|
||||
bot_user_id, language_code,
|
||||
PromiseCreator::lambda(
|
||||
[promise = std::move(promise)](Result<td_api::object_ptr<td_api::botMediaPreviewInfo>> result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void BotInfoManager::add_bot_media_preview(UserId bot_user_id, const string &language_code,
|
||||
td_api::object_ptr<td_api::InputStoryContent> &&input_content,
|
||||
Promise<td_api::object_ptr<td_api::StoryContent>> &&promise) {
|
||||
|
@ -43,6 +43,8 @@ class BotInfoManager final : public Actor {
|
||||
|
||||
FileSourceId get_bot_media_preview_file_source_id(UserId bot_user_id);
|
||||
|
||||
FileSourceId get_bot_media_preview_info_file_source_id(UserId bot_user_id, const string &language_code);
|
||||
|
||||
void get_bot_media_previews(UserId bot_user_id, Promise<td_api::object_ptr<td_api::botMediaPreviews>> &&promise);
|
||||
|
||||
void get_bot_media_preview_info(UserId bot_user_id, const string &language_code,
|
||||
@ -50,6 +52,8 @@ class BotInfoManager final : public Actor {
|
||||
|
||||
void reload_bot_media_previews(UserId bot_user_id, Promise<Unit> &&promise);
|
||||
|
||||
void reload_bot_media_preview_info(UserId bot_user_id, const string &language_code, Promise<Unit> &&promise);
|
||||
|
||||
void add_bot_media_preview(UserId bot_user_id, const string &language_code,
|
||||
td_api::object_ptr<td_api::InputStoryContent> &&input_content,
|
||||
Promise<td_api::object_ptr<td_api::StoryContent>> &&promise);
|
||||
@ -154,6 +158,26 @@ class BotInfoManager final : public Actor {
|
||||
|
||||
FlatHashMap<UserId, FileSourceId, UserIdHash> bot_media_preview_file_source_ids_;
|
||||
|
||||
struct MediaPreviewSource {
|
||||
UserId bot_user_id_;
|
||||
string language_code_;
|
||||
|
||||
MediaPreviewSource() = default;
|
||||
MediaPreviewSource(UserId bot_user_id, string language_code)
|
||||
: bot_user_id_(bot_user_id), language_code_(std::move(language_code)) {
|
||||
}
|
||||
|
||||
friend bool operator==(const MediaPreviewSource &lhs, const MediaPreviewSource &rhs) {
|
||||
return lhs.bot_user_id_ == rhs.bot_user_id_ && lhs.language_code_ == rhs.language_code_;
|
||||
}
|
||||
};
|
||||
struct MediaPreviewSourceHash {
|
||||
uint32 operator()(MediaPreviewSource source) const {
|
||||
return combine_hashes(UserIdHash()(source.bot_user_id_), Hash<string>()(source.language_code_));
|
||||
}
|
||||
};
|
||||
FlatHashMap<MediaPreviewSource, FileSourceId, MediaPreviewSourceHash> bot_media_preview_info_file_source_ids_;
|
||||
|
||||
FlatHashMap<FileId, unique_ptr<PendingBotMediaPreview>, FileIdHash> being_uploaded_files_;
|
||||
|
||||
std::shared_ptr<UploadMediaCallback> upload_media_callback_;
|
||||
|
@ -87,6 +87,7 @@ fileSourceStory chat_id:int53 story_id:int32 = FileSource;
|
||||
fileSourceQuickReplyMessage shortcut_id:int32 message_id:int53 = FileSource; // messages.getQuickReplyMessages
|
||||
fileSourceStarTransaction chat_id:int53 transaction_id:string is_refund:Bool = FileSource; // payments.getStarsTransactionsByID
|
||||
fileSourceBotMediaPreview bot_user_id:int53 = FileSource; // bots.getPreviewMedias
|
||||
fileSourceBotMediaPreviewInfo bot_user_id:int53 language_code:string = FileSource; // bots.getPreviewMediaInfo
|
||||
*/
|
||||
|
||||
FileSourceId FileReferenceManager::get_current_file_source_id() const {
|
||||
@ -192,6 +193,12 @@ FileSourceId FileReferenceManager::create_bot_media_preview_file_source(UserId b
|
||||
return add_file_source_id(source, PSLICE() << "bot media preview " << bot_user_id);
|
||||
}
|
||||
|
||||
FileSourceId FileReferenceManager::create_bot_media_preview_info_file_source(UserId bot_user_id,
|
||||
const string &language_code) {
|
||||
FileSourceBotMediaPreviewInfo source{bot_user_id, language_code};
|
||||
return add_file_source_id(source, PSLICE() << "bot media preview info " << bot_user_id << " for " << language_code);
|
||||
}
|
||||
|
||||
FileReferenceManager::Node &FileReferenceManager::add_node(NodeId node_id) {
|
||||
CHECK(node_id.is_valid());
|
||||
auto &node = nodes_[node_id];
|
||||
@ -419,6 +426,10 @@ void FileReferenceManager::send_query(Destination dest, FileSourceId file_source
|
||||
[&](const FileSourceBotMediaPreview &source) {
|
||||
send_closure_later(G()->bot_info_manager(), &BotInfoManager::reload_bot_media_previews, source.bot_user_id,
|
||||
std::move(promise));
|
||||
},
|
||||
[&](const FileSourceBotMediaPreviewInfo &source) {
|
||||
send_closure_later(G()->bot_info_manager(), &BotInfoManager::reload_bot_media_preview_info, source.bot_user_id,
|
||||
source.language_code, std::move(promise));
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,7 @@ class FileReferenceManager final : public Actor {
|
||||
FileSourceId create_quick_reply_message_file_source(QuickReplyMessageFullId message_full_id);
|
||||
FileSourceId create_star_transaction_file_source(DialogId dialog_id, const string &transaction_id, bool is_refund);
|
||||
FileSourceId create_bot_media_preview_file_source(UserId bot_user_id);
|
||||
FileSourceId create_bot_media_preview_info_file_source(UserId bot_user_id, const string &language_code);
|
||||
|
||||
using NodeId = FileId;
|
||||
void repair_file_reference(NodeId node_id, Promise<> promise);
|
||||
@ -190,6 +191,10 @@ class FileReferenceManager final : public Actor {
|
||||
struct FileSourceBotMediaPreview {
|
||||
UserId bot_user_id;
|
||||
};
|
||||
struct FileSourceBotMediaPreviewInfo {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
};
|
||||
|
||||
// append only
|
||||
using FileSource =
|
||||
@ -197,7 +202,8 @@ class FileReferenceManager final : public Actor {
|
||||
FileSourceWebPage, FileSourceSavedAnimations, FileSourceRecentStickers, FileSourceFavoriteStickers,
|
||||
FileSourceBackground, FileSourceChatFull, FileSourceChannelFull, FileSourceAppConfig,
|
||||
FileSourceSavedRingtones, FileSourceUserFull, FileSourceAttachMenuBot, FileSourceWebApp, FileSourceStory,
|
||||
FileSourceQuickReplyMessage, FileSourceStarTransaction, FileSourceBotMediaPreview>;
|
||||
FileSourceQuickReplyMessage, FileSourceStarTransaction, FileSourceBotMediaPreview,
|
||||
FileSourceBotMediaPreviewInfo>;
|
||||
WaitFreeVector<FileSource> file_sources_;
|
||||
|
||||
int64 query_generation_{0};
|
||||
|
@ -73,7 +73,11 @@ void FileReferenceManager::store_file_source(FileSourceId file_source_id, Storer
|
||||
td::store(source.transaction_id, storer);
|
||||
td::store(source.is_refund, storer);
|
||||
},
|
||||
[&](const FileSourceBotMediaPreview &source) { td::store(source.bot_user_id, storer); }));
|
||||
[&](const FileSourceBotMediaPreview &source) { td::store(source.bot_user_id, storer); },
|
||||
[&](const FileSourceBotMediaPreviewInfo &source) {
|
||||
td::store(source.bot_user_id, storer);
|
||||
td::store(source.language_code, storer);
|
||||
}));
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
@ -180,6 +184,13 @@ FileSourceId FileReferenceManager::parse_file_source(Td *td, ParserT &parser) {
|
||||
td::parse(bot_user_id, parser);
|
||||
return td->bot_info_manager_->get_bot_media_preview_file_source_id(bot_user_id);
|
||||
}
|
||||
case 21: {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
td::parse(bot_user_id, parser);
|
||||
td::parse(language_code, parser);
|
||||
return td->bot_info_manager_->get_bot_media_preview_info_file_source_id(bot_user_id, language_code);
|
||||
}
|
||||
default:
|
||||
parser.set_error("Invalid type in FileSource");
|
||||
return FileSourceId();
|
||||
|
Loading…
Reference in New Issue
Block a user