Add td_api::loadQuickReplyShortcutMessages instead of getQuickReplyShortcutMessages.

This commit is contained in:
levlam 2024-02-29 16:05:16 +03:00
parent c99dd3d59d
commit 3b62a65bea
6 changed files with 18 additions and 36 deletions

View File

@ -3777,9 +3777,6 @@ storyInteractions total_count:int32 total_forward_count:int32 total_reaction_cou
//@content Content of the message
quickReplyMessage id:int53 sending_state:MessageSendingState can_be_edited:Bool reply_to_message_id:int53 via_bot_user_id:int53 media_album_id:int64 content:MessageContent = QuickReplyMessage;
//@description Contains a list of quick reply messages @messages List of messages
quickReplyMessages messages:vector<quickReplyMessage> = QuickReplyMessages;
//@description Describes a shortcut that can be used for a quick reply
//@id Unique shortcut identifier
//@name The name of the shortcut that can be used to use the shortcut
@ -6645,7 +6642,9 @@ updateQuickReplyShortcutDeleted shortcut_id:int32 = Update;
//@description The list of quick reply shortcuts has changed @shortcut_ids The new list of identifiers of quick reply shortcuts
updateQuickReplyShortcuts shortcut_ids:vector<int32> = Update;
//@description The list of quick reply shortcut messages has changed @shortcut_id The identifier of the shortcut @messages The new list of quick reply messages for the shortcut
//@description The list of quick reply shortcut messages has changed
//@shortcut_id The identifier of the shortcut
//@messages The new list of quick reply messages for the shortcut in order from the first to the last sent
updateQuickReplyShortcutMessages shortcut_id:int32 messages:vector<quickReplyMessage> = Update;
//@description Basic information about a topic in a forum chat was changed @chat_id Chat identifier @info New information about the topic
@ -7784,8 +7783,9 @@ deleteQuickReplyShortcut shortcut_id:int32 = Ok;
//@description Changes the order of quick reply shortcuts @shortcut_ids The new order of quick reply shortcuts
reorderQuickReplyShortcuts shortcut_ids:vector<int32> = Ok;
//@description Returns all messages that can be sent by a quick reply shortcut. The messages are returned in order from the first to the last sent @shortcut_id Unique identifier of the quick reply shortcut
getQuickReplyShortcutMessages shortcut_id:int32 = QuickReplyMessages;
//@description Loads quick reply messages that can be sent by a given quick reply shortcut. The loaded messages will be sent through updateQuickReplyShortcutMessages
//@shortcut_id Unique identifier of the quick reply shortcut
loadQuickReplyShortcutMessages shortcut_id:int32 = Ok;
//@description Returns list of custom emojis, which can be used as forum topic icon by all users

View File

@ -850,22 +850,20 @@ void QuickReplyManager::delete_quick_reply_messages(QuickReplyShortcutId shortcu
}
}
void QuickReplyManager::get_quick_reply_shortcut_messages(
QuickReplyShortcutId shortcut_id, Promise<td_api::object_ptr<td_api::quickReplyMessages>> &&promise) {
void QuickReplyManager::get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise) {
auto s = get_shortcut(shortcut_id);
if (s == nullptr) {
return promise.set_error(Status::Error(400, "Shortcut not found"));
}
if (have_all_shortcut_messages(s)) {
return promise.set_value(get_quick_reply_messages_object(s));
return promise.set_value(Unit());
}
CHECK(shortcut_id.is_server());
reload_quick_reply_messages(shortcut_id, std::move(promise));
}
void QuickReplyManager::reload_quick_reply_messages(QuickReplyShortcutId shortcut_id,
Promise<td_api::object_ptr<td_api::quickReplyMessages>> &&promise) {
void QuickReplyManager::reload_quick_reply_messages(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise) {
auto &queries = get_shortcut_messages_queries_[shortcut_id];
queries.push_back(std::move(promise));
if (queries.size() != 1) {
@ -955,9 +953,7 @@ void QuickReplyManager::on_reload_quick_reply_messages(
return fail_promises(promises, Status::Error(400, "Shortcut not found"));
}
for (auto &promise : promises) {
if (promise) {
promise.set_value(get_quick_reply_messages_object(s));
}
promise.set_value(Unit());
}
}
@ -1155,14 +1151,6 @@ void QuickReplyManager::send_update_quick_reply_shortcuts() {
send_closure(G()->td(), &Td::send_update, get_update_quick_reply_shortcuts_object());
}
td_api::object_ptr<td_api::quickReplyMessages> QuickReplyManager::get_quick_reply_messages_object(
const Shortcut *s) const {
auto messages = transform(s->messages_, [this](const unique_ptr<QuickReplyMessage> &message) {
return get_quick_reply_message_object(message.get(), "get_quick_reply_messages_object");
});
return td_api::make_object<td_api::quickReplyMessages>(std::move(messages));
}
td_api::object_ptr<td_api::updateQuickReplyShortcutMessages>
QuickReplyManager::get_update_quick_reply_shortcut_messages_object(const Shortcut *s) const {
CHECK(s != nullptr);

View File

@ -39,8 +39,7 @@ class QuickReplyManager final : public Actor {
void delete_quick_reply_messages(QuickReplyShortcutId shortcut_id, const vector<MessageId> &message_ids);
void get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id,
Promise<td_api::object_ptr<td_api::quickReplyMessages>> &&promise);
void get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise);
void reload_quick_reply_shortcuts();
@ -167,8 +166,7 @@ class QuickReplyManager final : public Actor {
int64 get_shortcuts_hash() const;
void reload_quick_reply_messages(QuickReplyShortcutId shortcut_id,
Promise<td_api::object_ptr<td_api::quickReplyMessages>> &&promise);
void reload_quick_reply_messages(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise);
void on_reload_quick_reply_messages(QuickReplyShortcutId shortcut_id,
Result<telegram_api::object_ptr<telegram_api::messages_Messages>> r_messages);
@ -220,8 +218,6 @@ class QuickReplyManager final : public Actor {
void send_update_quick_reply_shortcuts();
td_api::object_ptr<td_api::quickReplyMessages> get_quick_reply_messages_object(const Shortcut *s) const;
td_api::object_ptr<td_api::updateQuickReplyShortcutMessages> get_update_quick_reply_shortcut_messages_object(
const Shortcut *s) const;
@ -239,9 +235,7 @@ class QuickReplyManager final : public Actor {
FlatHashSet<QuickReplyShortcutId, QuickReplyShortcutIdHash> deleted_shortcut_ids_;
FlatHashMap<QuickReplyShortcutId, vector<Promise<td_api::object_ptr<td_api::quickReplyMessages>>>,
QuickReplyShortcutIdHash>
get_shortcut_messages_queries_;
FlatHashMap<QuickReplyShortcutId, vector<Promise<Unit>>, QuickReplyShortcutIdHash> get_shortcut_messages_queries_;
Td *td_;
ActorShared<> parent_;

View File

@ -5780,9 +5780,9 @@ void Td::on_request(uint64 id, const td_api::reorderQuickReplyShortcuts &request
QuickReplyShortcutId::get_quick_reply_shortcut_ids(request.shortcut_ids_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getQuickReplyShortcutMessages &request) {
void Td::on_request(uint64 id, const td_api::loadQuickReplyShortcutMessages &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
CREATE_OK_REQUEST_PROMISE();
quick_reply_manager_->get_quick_reply_shortcut_messages(QuickReplyShortcutId(request.shortcut_id_),
std::move(promise));
}

View File

@ -870,7 +870,7 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::reorderQuickReplyShortcuts &request);
void on_request(uint64 id, const td_api::getQuickReplyShortcutMessages &request);
void on_request(uint64 id, const td_api::loadQuickReplyShortcutMessages &request);
void on_request(uint64 id, const td_api::getStory &request);

View File

@ -4855,10 +4855,10 @@ class CliClient final : public Actor {
string shortcut_ids;
get_args(args, shortcut_ids);
send_request(td_api::make_object<td_api::reorderQuickReplyShortcuts>(as_shortcut_ids(shortcut_ids)));
} else if (op == "gqrsm") {
} else if (op == "lqrsm") {
ShortcutId shortcut_id;
get_args(args, shortcut_id);
send_request(td_api::make_object<td_api::getQuickReplyShortcutMessages>(shortcut_id));
send_request(td_api::make_object<td_api::loadQuickReplyShortcutMessages>(shortcut_id));
} else if (op == "gftdi") {
send_request(td_api::make_object<td_api::getForumTopicDefaultIcons>());
} else if (op == "cft") {