Add load_quick_reply_shortcuts.
This commit is contained in:
parent
b53fca6284
commit
3d397c1d35
@ -658,6 +658,7 @@ td_api::object_ptr<td_api::quickReplyShortcut> QuickReplyManager::get_quick_repl
|
||||
}
|
||||
|
||||
void QuickReplyManager::get_quick_reply_shortcuts(Promise<Unit> &&promise) {
|
||||
load_quick_reply_shortcuts();
|
||||
if (shortcuts_.are_inited_) {
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
@ -1577,6 +1578,46 @@ void QuickReplyManager::save_quick_reply_shortcuts() {
|
||||
log_event_store(shortcuts_).as_slice().str());
|
||||
}
|
||||
|
||||
void QuickReplyManager::load_quick_reply_shortcuts() {
|
||||
if (shortcuts_.are_loaded_from_database_) {
|
||||
return;
|
||||
}
|
||||
shortcuts_.are_loaded_from_database_ = true;
|
||||
|
||||
auto shortcuts_str = G()->td_db()->get_binlog_pmc()->get(get_quick_reply_shortcuts_database_key());
|
||||
auto status = log_event_parse(shortcuts_, shortcuts_str);
|
||||
if (status.is_error()) {
|
||||
LOG(ERROR) << "Can't load quick replies: " << status;
|
||||
G()->td_db()->get_binlog_pmc()->erase(get_quick_reply_shortcuts_database_key());
|
||||
shortcuts_.shortcuts_.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
Dependencies dependencies;
|
||||
for (const auto &shortcut : shortcuts_.shortcuts_) {
|
||||
for (const auto &message : shortcut->messages_) {
|
||||
add_quick_reply_message_dependencies(dependencies, message.get());
|
||||
}
|
||||
}
|
||||
if (!dependencies.resolve_force(td_, "load_quick_reply_shortcuts")) {
|
||||
shortcuts_.shortcuts_.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
shortcuts_.are_inited_ = true;
|
||||
for (const auto &shortcut : shortcuts_.shortcuts_) {
|
||||
for (const auto &message : shortcut->messages_) {
|
||||
change_message_files({shortcut->shortcut_id_, message->message_id}, message.get(), {});
|
||||
}
|
||||
send_update_quick_reply_shortcut(shortcut.get(), "load_quick_reply_shortcuts");
|
||||
send_update_quick_reply_shortcut_messages(shortcut.get(), "load_quick_reply_shortcuts");
|
||||
}
|
||||
|
||||
send_update_quick_reply_shortcuts();
|
||||
|
||||
reload_quick_reply_shortcuts();
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::updateQuickReplyShortcut> QuickReplyManager::get_update_quick_reply_shortcut_object(
|
||||
const Shortcut *s, const char *source) const {
|
||||
return td_api::make_object<td_api::updateQuickReplyShortcut>(get_quick_reply_shortcut_object(s, source));
|
||||
|
@ -149,6 +149,7 @@ class QuickReplyManager final : public Actor {
|
||||
struct Shortcuts {
|
||||
vector<unique_ptr<Shortcut>> shortcuts_;
|
||||
bool are_inited_ = false;
|
||||
bool are_loaded_from_database_ = false;
|
||||
|
||||
vector<Promise<Unit>> load_queries_;
|
||||
|
||||
@ -281,6 +282,8 @@ class QuickReplyManager final : public Actor {
|
||||
|
||||
void save_quick_reply_shortcuts();
|
||||
|
||||
void load_quick_reply_shortcuts();
|
||||
|
||||
vector<FileId> get_message_file_ids(const QuickReplyMessage *m) const;
|
||||
|
||||
void delete_message_files(QuickReplyShortcutId shortcut_id, const QuickReplyMessage *m) const;
|
||||
|
Loading…
Reference in New Issue
Block a user