Support updateDeleteQuickReplyMessages.

This commit is contained in:
levlam 2024-02-29 14:43:32 +03:00
parent 2e4a9c11d3
commit b7ee5c2ada
4 changed files with 60 additions and 7 deletions

View File

@ -807,6 +807,37 @@ void QuickReplyManager::reorder_quick_reply_shortcuts_on_server(vector<QuickRepl
td_->create_handler<ReorderQuickRepliesQuery>(std::move(promise))->send(std::move(shortcut_ids)); td_->create_handler<ReorderQuickRepliesQuery>(std::move(promise))->send(std::move(shortcut_ids));
} }
void QuickReplyManager::delete_quick_reply_messages(QuickReplyShortcutId shortcut_id,
const vector<MessageId> &message_ids) {
auto s = get_shortcut(shortcut_id);
if (s == nullptr) {
return;
}
bool is_changed = false;
bool is_list_changed = false;
for (auto &message_id : message_ids) {
auto it = get_message_it(s, message_id);
if (it == s->messages_.end()) {
if (it == s->messages_.begin()) {
is_list_changed = true;
}
is_changed = true;
s->messages_.erase(it);
}
}
if (s->messages_.empty()) {
send_update_quick_reply_shortcut_deleted(s);
shortcuts_.shortcuts_.erase(get_shortcut_it(shortcut_id));
CHECK(is_list_changed && is_changed);
}
if (is_list_changed) {
send_update_quick_reply_shortcuts();
}
if (is_changed) {
save_quick_reply_shortcuts();
}
}
void QuickReplyManager::get_quick_reply_shortcut_messages( void QuickReplyManager::get_quick_reply_shortcut_messages(
QuickReplyShortcutId shortcut_id, Promise<td_api::object_ptr<td_api::quickReplyMessages>> &&promise) { QuickReplyShortcutId shortcut_id, Promise<td_api::object_ptr<td_api::quickReplyMessages>> &&promise) {
auto s = get_shortcut(shortcut_id); auto s = get_shortcut(shortcut_id);
@ -970,6 +1001,17 @@ vector<unique_ptr<QuickReplyManager::Shortcut>>::iterator QuickReplyManager::get
return shortcuts_.shortcuts_.end(); return shortcuts_.shortcuts_.end();
} }
vector<unique_ptr<QuickReplyManager::QuickReplyMessage>>::iterator QuickReplyManager::get_message_it(
Shortcut *s, MessageId message_id) {
CHECK(s != nullptr);
for (auto it = s->messages_.begin(); it != s->messages_.end(); ++it) {
if ((*it)->message_id == message_id) {
return it;
}
}
return s->messages_.end();
}
vector<QuickReplyShortcutId> QuickReplyManager::get_shortcut_ids() const { vector<QuickReplyShortcutId> QuickReplyManager::get_shortcut_ids() const {
return transform(shortcuts_.shortcuts_, [](const unique_ptr<Shortcut> &shortcut) { return shortcut->shortcut_id_; }); return transform(shortcuts_.shortcuts_, [](const unique_ptr<Shortcut> &shortcut) { return shortcut->shortcut_id_; });
} }

View File

@ -37,6 +37,8 @@ class QuickReplyManager final : public Actor {
void reorder_quick_reply_shortcuts(const vector<QuickReplyShortcutId> &shortcut_ids, Promise<Unit> &&promise); void reorder_quick_reply_shortcuts(const vector<QuickReplyShortcutId> &shortcut_ids, Promise<Unit> &&promise);
void delete_quick_reply_messages(QuickReplyShortcutId shortcut_id, const vector<MessageId> &message_ids);
void get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, void get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id,
Promise<td_api::object_ptr<td_api::quickReplyMessages>> &&promise); Promise<td_api::object_ptr<td_api::quickReplyMessages>> &&promise);
@ -179,6 +181,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);
vector<unique_ptr<QuickReplyMessage>>::iterator get_message_it(Shortcut *s, MessageId message_id);
bool is_shortcut_list_changed(const vector<unique_ptr<Shortcut>> &new_shortcuts) const; bool is_shortcut_list_changed(const vector<unique_ptr<Shortcut>> &new_shortcuts) const;
vector<QuickReplyShortcutId> get_shortcut_ids() const; vector<QuickReplyShortcutId> get_shortcut_ids() const;

View File

@ -53,6 +53,7 @@
#include "td/telegram/PrivacyManager.h" #include "td/telegram/PrivacyManager.h"
#include "td/telegram/PublicDialogType.h" #include "td/telegram/PublicDialogType.h"
#include "td/telegram/QuickReplyManager.h" #include "td/telegram/QuickReplyManager.h"
#include "td/telegram/QuickReplyShortcutId.h"
#include "td/telegram/ReactionListType.h" #include "td/telegram/ReactionListType.h"
#include "td/telegram/ReactionManager.h" #include "td/telegram/ReactionManager.h"
#include "td/telegram/ReactionType.h" #include "td/telegram/ReactionType.h"
@ -4489,15 +4490,21 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteQuickRepl
promise.set_value(Unit()); promise.set_value(Unit());
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteQuickReplyMessages> update,
Promise<Unit> &&promise) {
vector<MessageId> message_ids;
for (auto message : update->messages_) {
message_ids.push_back(MessageId(ServerMessageId(message)));
}
td_->quick_reply_manager_->delete_quick_reply_messages(QuickReplyShortcutId(update->shortcut_id_),
std::move(message_ids));
promise.set_value(Unit());
}
// unsupported updates // unsupported updates
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateQuickReplyMessage> update, Promise<Unit> &&promise) { void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateQuickReplyMessage> update, Promise<Unit> &&promise) {
promise.set_value(Unit()); promise.set_value(Unit());
} }
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDeleteQuickReplyMessages> update,
Promise<Unit> &&promise) {
promise.set_value(Unit());
}
} // namespace td } // namespace td

View File

@ -658,11 +658,11 @@ class UpdatesManager final : public Actor {
void on_update(tl_object_ptr<telegram_api::updateDeleteQuickReply> update, Promise<Unit> &&promise); void on_update(tl_object_ptr<telegram_api::updateDeleteQuickReply> update, Promise<Unit> &&promise);
void on_update(tl_object_ptr<telegram_api::updateDeleteQuickReplyMessages> update, Promise<Unit> &&promise);
// unsupported updates // unsupported updates
void on_update(tl_object_ptr<telegram_api::updateQuickReplyMessage> update, Promise<Unit> &&promise); void on_update(tl_object_ptr<telegram_api::updateQuickReplyMessage> update, Promise<Unit> &&promise);
void on_update(tl_object_ptr<telegram_api::updateDeleteQuickReplyMessages> update, Promise<Unit> &&promise);
}; };
} // namespace td } // namespace td