Add updateQuickReplyShortcuts.

This commit is contained in:
levlam 2024-02-22 22:55:09 +03:00
parent c73a19c319
commit 99f1369e8c
3 changed files with 35 additions and 0 deletions

View File

@ -6590,6 +6590,9 @@ updateQuickReplyShortcut shortcut:quickReplyShortcut = Update;
//@description A quick reply shortcut was deleted @name The name of the deleted shortcut
updateQuickReplyShortcutDeleted name:string = Update;
//@description The list of quick reply shortcuts has changed @shortcuts The new list of existing quick reply shortcuts
updateQuickReplyShortcuts shortcuts:vector<string> = Update;
//@description Basic information about a topic in a forum chat was changed @chat_id Chat identifier @info New information about the topic
updateForumTopicInfo chat_id:int53 info:forumTopicInfo = Update;

View File

@ -293,6 +293,7 @@ void QuickReplyManager::on_reload_quick_reply_shortcuts(
case telegram_api::messages_quickRepliesNotModified::ID:
if (!shortcuts_.are_inited_) {
shortcuts_.are_inited_ = true;
send_update_quick_reply_shortcuts();
}
break;
case telegram_api::messages_quickReplies::ID: {
@ -386,12 +387,24 @@ void QuickReplyManager::on_reload_quick_reply_shortcuts(
new_shortcuts.push_back(std::move(shortcut));
}
}
bool is_list_changed = !shortcuts_.are_inited_ || shortcuts_.shortcuts_.size() != new_shortcuts.size();
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_.are_inited_ = true;
for (auto shortcut_id : changed_shortcut_ids) {
send_update_quick_reply_shortcut(get_shortcut(shortcut_id), "on_reload_quick_reply_shortcuts 2");
}
if (is_list_changed) {
send_update_quick_reply_shortcuts();
}
break;
}
}
@ -518,6 +531,17 @@ void QuickReplyManager::send_update_quick_reply_shortcut_deleted(const Shortcut
send_closure(G()->td(), &Td::send_update, get_update_quick_reply_shortcut_deleted_object(s));
}
td_api::object_ptr<td_api::updateQuickReplyShortcuts> QuickReplyManager::get_update_quick_reply_shortcuts_object()
const {
CHECK(shortcuts_.are_inited_);
return td_api::make_object<td_api::updateQuickReplyShortcuts>(
transform(shortcuts_.shortcuts_, [](const unique_ptr<Shortcut> &shortcut) { return shortcut->name_; }));
}
void QuickReplyManager::send_update_quick_reply_shortcuts() {
send_closure(G()->td(), &Td::send_update, get_update_quick_reply_shortcuts_object());
}
void QuickReplyManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
if (td_->auth_manager_->is_bot()) {
return;
@ -526,6 +550,10 @@ void QuickReplyManager::get_current_state(vector<td_api::object_ptr<td_api::Upda
for (auto &shortcut : shortcuts_.shortcuts_) {
updates.push_back(get_update_quick_reply_shortcut_object(shortcut.get(), "get_current_state"));
}
if (shortcuts_.are_inited_) {
updates.push_back(get_update_quick_reply_shortcuts_object());
}
}
} // namespace td

View File

@ -166,6 +166,10 @@ class QuickReplyManager final : public Actor {
void send_update_quick_reply_shortcut_deleted(const Shortcut *s);
td_api::object_ptr<td_api::updateQuickReplyShortcuts> get_update_quick_reply_shortcuts_object() const;
void send_update_quick_reply_shortcuts();
Shortcuts shortcuts_;
Td *td_;