Add td_api::deleteQuickReplyShortcutMessages.

This commit is contained in:
levlam 2024-02-29 21:34:45 +03:00
parent 3d60b43196
commit de6f15c973
6 changed files with 92 additions and 2 deletions

View File

@ -7787,6 +7787,11 @@ reorderQuickReplyShortcuts shortcut_ids:vector<int32> = Ok;
//@shortcut_id Unique identifier of the quick reply shortcut //@shortcut_id Unique identifier of the quick reply shortcut
loadQuickReplyShortcutMessages shortcut_id:int32 = Ok; loadQuickReplyShortcutMessages shortcut_id:int32 = Ok;
//@description Deletes specified quick reply messages
//@shortcut_id Unique identifier of the quick reply shortcut to which the messages belong
//@message_ids Unique identifiers of the messages
deleteQuickReplyShortcutMessages shortcut_id:int32 message_ids:vector<int53> = Ok;
//@description Returns list of custom emojis, which can be used as forum topic icon by all users //@description Returns list of custom emojis, which can be used as forum topic icon by all users
getForumTopicDefaultIcons = Stickers; getForumTopicDefaultIcons = Stickers;

View File

@ -148,6 +148,36 @@ class GetQuickReplyMessagesQuery final : public Td::ResultHandler {
} }
}; };
class DeleteQuickReplyMessagesQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
QuickReplyShortcutId shortcut_id_;
public:
explicit DeleteQuickReplyMessagesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(QuickReplyShortcutId shortcut_id, const vector<MessageId> &message_ids) {
shortcut_id_ = shortcut_id;
send_query(G()->net_query_creator().create(telegram_api::messages_deleteQuickReplyMessages(
shortcut_id.get(), MessageId::get_server_message_ids(message_ids)),
{{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_deleteQuickReplyMessages>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(Status status) final {
td_->quick_reply_manager_->reload_quick_reply_messages(shortcut_id_, Promise<Unit>());
promise_.set_error(std::move(status));
}
};
QuickReplyManager::QuickReplyMessage::~QuickReplyMessage() = default; QuickReplyManager::QuickReplyMessage::~QuickReplyMessage() = default;
template <class StorerT> template <class StorerT>
@ -933,6 +963,40 @@ void QuickReplyManager::delete_quick_reply_messages(Shortcut *s, const vector<Me
} }
} }
void QuickReplyManager::delete_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id,
const vector<MessageId> &message_ids,
Promise<Unit> &&promise) {
auto s = get_shortcut(shortcut_id);
if (s == nullptr) {
return promise.set_error(Status::Error(400, "Shortcut not found"));
}
if (message_ids.empty()) {
return promise.set_value(Unit());
}
vector<MessageId> deleted_server_message_ids;
for (auto &message_id : message_ids) {
if (!message_id.is_valid()) {
return promise.set_error(Status::Error(400, "Invalid message identifier"));
}
// message_id = get_persistent_message_id(s, message_id);
if (message_id.is_server()) {
deleted_server_message_ids.push_back(message_id);
}
}
delete_quick_reply_messages_on_server(shortcut_id, std::move(deleted_server_message_ids), std::move(promise));
delete_quick_reply_messages(s, message_ids);
}
void QuickReplyManager::delete_quick_reply_messages_on_server(QuickReplyShortcutId shortcut_id,
const vector<MessageId> &message_ids,
Promise<Unit> &&promise) {
td_->create_handler<DeleteQuickReplyMessagesQuery>(std::move(promise))->send(shortcut_id, message_ids);
}
void QuickReplyManager::get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise) { void QuickReplyManager::get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise) {
auto s = get_shortcut(shortcut_id); auto s = get_shortcut(shortcut_id);
if (s == nullptr) { if (s == nullptr) {

View File

@ -46,8 +46,13 @@ class QuickReplyManager final : public Actor {
void get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise); void get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise);
void delete_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, const vector<MessageId> &message_ids,
Promise<Unit> &&promise);
void reload_quick_reply_shortcuts(); void reload_quick_reply_shortcuts();
void reload_quick_reply_messages(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise);
void reload_quick_reply_message(QuickReplyShortcutId shortcut_id, MessageId message_id, Promise<Unit> &&promise); void reload_quick_reply_message(QuickReplyShortcutId shortcut_id, MessageId message_id, Promise<Unit> &&promise);
FileSourceId get_quick_reply_message_file_source_id(QuickReplyMessageFullId message_full_id); FileSourceId get_quick_reply_message_file_source_id(QuickReplyMessageFullId message_full_id);
@ -175,8 +180,6 @@ class QuickReplyManager final : public Actor {
int64 get_shortcuts_hash() const; int64 get_shortcuts_hash() const;
void reload_quick_reply_messages(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise);
void on_reload_quick_reply_messages(QuickReplyShortcutId shortcut_id, void on_reload_quick_reply_messages(QuickReplyShortcutId shortcut_id,
Result<telegram_api::object_ptr<telegram_api::messages_Messages>> r_messages); Result<telegram_api::object_ptr<telegram_api::messages_Messages>> r_messages);
@ -246,6 +249,9 @@ class QuickReplyManager final : public Actor {
void reorder_quick_reply_shortcuts_on_server(vector<QuickReplyShortcutId> shortcut_ids, Promise<Unit> &&promise); void reorder_quick_reply_shortcuts_on_server(vector<QuickReplyShortcutId> shortcut_ids, Promise<Unit> &&promise);
void delete_quick_reply_messages_on_server(QuickReplyShortcutId shortcut_id, const vector<MessageId> &message_ids,
Promise<Unit> &&promise);
string get_quick_reply_shortcuts_database_key(); string get_quick_reply_shortcuts_database_key();
void save_quick_reply_shortcuts(); void save_quick_reply_shortcuts();

View File

@ -5787,6 +5787,13 @@ void Td::on_request(uint64 id, const td_api::loadQuickReplyShortcutMessages &req
std::move(promise)); std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::deleteQuickReplyShortcutMessages &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
quick_reply_manager_->delete_quick_reply_shortcut_messages(
QuickReplyShortcutId(request.shortcut_id_), MessageId::get_message_ids(request.message_ids_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getStory &request) { void Td::on_request(uint64 id, const td_api::getStory &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();

View File

@ -872,6 +872,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::loadQuickReplyShortcutMessages &request); void on_request(uint64 id, const td_api::loadQuickReplyShortcutMessages &request);
void on_request(uint64 id, const td_api::deleteQuickReplyShortcutMessages &request);
void on_request(uint64 id, const td_api::getStory &request); void on_request(uint64 id, const td_api::getStory &request);
void on_request(uint64 id, const td_api::getChatsToSendStories &request); void on_request(uint64 id, const td_api::getChatsToSendStories &request);

View File

@ -4859,6 +4859,12 @@ class CliClient final : public Actor {
ShortcutId shortcut_id; ShortcutId shortcut_id;
get_args(args, shortcut_id); get_args(args, shortcut_id);
send_request(td_api::make_object<td_api::loadQuickReplyShortcutMessages>(shortcut_id)); send_request(td_api::make_object<td_api::loadQuickReplyShortcutMessages>(shortcut_id));
} else if (op == "dqrsm") {
ShortcutId shortcut_id;
string message_ids;
get_args(args, shortcut_id, message_ids);
send_request(
td_api::make_object<td_api::deleteQuickReplyShortcutMessages>(shortcut_id, as_message_ids(message_ids)));
} else if (op == "gftdi") { } else if (op == "gftdi") {
send_request(td_api::make_object<td_api::getForumTopicDefaultIcons>()); send_request(td_api::make_object<td_api::getForumTopicDefaultIcons>());
} else if (op == "cft") { } else if (op == "cft") {