Add and use QuickReplyManager::is_shortcut_list_changed.

This commit is contained in:
levlam 2024-02-24 14:22:01 +03:00
parent bf825d76cb
commit bf01eb3b91
2 changed files with 15 additions and 9 deletions

View File

@ -636,15 +636,7 @@ void QuickReplyManager::on_reload_quick_reply_shortcuts(
new_shortcuts.push_back(std::move(shortcut)); new_shortcuts.push_back(std::move(shortcut));
} }
} }
bool is_list_changed = !shortcuts_.are_inited_ || shortcuts_.shortcuts_.size() != new_shortcuts.size(); bool is_list_changed = is_shortcut_list_changed(new_shortcuts);
if (!is_list_changed) {
for (size_t i = 0; i < new_shortcuts.size(); i++) {
if (shortcuts_.shortcuts_[i]->name_ != new_shortcuts[i]->name_) {
is_list_changed = true;
break;
}
}
}
shortcuts_.shortcuts_ = std::move(new_shortcuts); shortcuts_.shortcuts_ = std::move(new_shortcuts);
shortcuts_.are_inited_ = true; shortcuts_.are_inited_ = true;
@ -660,6 +652,18 @@ void QuickReplyManager::on_reload_quick_reply_shortcuts(
on_load_quick_reply_success(); on_load_quick_reply_success();
} }
bool QuickReplyManager::is_shortcut_list_changed(const vector<unique_ptr<Shortcut>> &new_shortcuts) const {
if (!shortcuts_.are_inited_ || shortcuts_.shortcuts_.size() != new_shortcuts.size()) {
return true;
}
for (size_t i = 0; i < new_shortcuts.size(); i++) {
if (shortcuts_.shortcuts_[i]->name_ != new_shortcuts[i]->name_) {
return true;
}
}
return false;
}
void QuickReplyManager::on_load_quick_reply_success() { void QuickReplyManager::on_load_quick_reply_success() {
set_promises(shortcuts_.load_queries_); set_promises(shortcuts_.load_queries_);
} }

View File

@ -170,6 +170,8 @@ class QuickReplyManager final : public Actor {
vector<unique_ptr<Shortcut>>::iterator get_shortcut_it(const string &name); vector<unique_ptr<Shortcut>>::iterator get_shortcut_it(const string &name);
bool is_shortcut_list_changed(const vector<unique_ptr<Shortcut>> &new_shortcuts) const;
static void sort_quick_reply_messages(vector<unique_ptr<QuickReplyMessage>> &messages); static void sort_quick_reply_messages(vector<unique_ptr<QuickReplyMessage>> &messages);
using QuickReplyMessageUniqueId = std::pair<MessageId, int32>; using QuickReplyMessageUniqueId = std::pair<MessageId, int32>;