Add td_api::reorderQuickReplyShortcuts.
This commit is contained in:
parent
bf01eb3b91
commit
693bb5f09e
|
@ -6599,8 +6599,8 @@ updateQuickReplyShortcut shortcut:quickReplyShortcut = Update;
|
||||||
//@description A quick reply shortcut was deleted @name The name of the deleted shortcut
|
//@description A quick reply shortcut was deleted @name The name of the deleted shortcut
|
||||||
updateQuickReplyShortcutDeleted name:string = Update;
|
updateQuickReplyShortcutDeleted name:string = Update;
|
||||||
|
|
||||||
//@description The list of quick reply shortcuts has changed @shortcuts The new list of existing quick reply shortcuts
|
//@description The list of quick reply shortcuts has changed @shortcut_names The new list of names of quick reply shortcuts
|
||||||
updateQuickReplyShortcuts shortcuts:vector<string> = Update;
|
updateQuickReplyShortcuts shortcut_names: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
|
//@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;
|
updateForumTopicInfo chat_id:int53 info:forumTopicInfo = Update;
|
||||||
|
@ -7732,8 +7732,11 @@ editMessageSchedulingState chat_id:int53 message_id:int53 scheduling_state:Messa
|
||||||
//@description Loads quick reply shortcuts created by the current user. The loaded topics will be sent through updateQuickReplyShortcuts
|
//@description Loads quick reply shortcuts created by the current user. The loaded topics will be sent through updateQuickReplyShortcuts
|
||||||
loadQuickReplyShortcuts = Ok;
|
loadQuickReplyShortcuts = Ok;
|
||||||
|
|
||||||
//@description Deletes a quick reply shortcut @name The name of the quick reply shortcut
|
//@description Deletes a quick reply shortcut @shortcut_name The name of the quick reply shortcut
|
||||||
deleteQuickReplyShortcut name:string = Ok;
|
deleteQuickReplyShortcut shortcut_name:string = Ok;
|
||||||
|
|
||||||
|
//@description Changes the order of quick reply shortcuts @shortcut_names The new order of quick reply shortcuts
|
||||||
|
reorderQuickReplyShortcuts shortcut_names:vector<string> = 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
|
||||||
|
|
|
@ -79,6 +79,36 @@ class DeleteQuickReplyShortcutQuery final : public Td::ResultHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_error(Status status) final {
|
void on_error(Status status) final {
|
||||||
|
td_->quick_reply_manager_->reload_quick_reply_shortcuts();
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ReorderQuickRepliesQuery final : public Td::ResultHandler {
|
||||||
|
Promise<Unit> promise_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ReorderQuickRepliesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(vector<QuickReplyShortcutId> shortcut_ids) {
|
||||||
|
send_query(
|
||||||
|
G()->net_query_creator().create(telegram_api::messages_reorderQuickReplies(
|
||||||
|
QuickReplyShortcutId::get_input_quick_reply_shortcut_ids(shortcut_ids)),
|
||||||
|
{{"me"}}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::messages_reorderQuickReplies>(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_shortcuts();
|
||||||
promise_.set_error(std::move(status));
|
promise_.set_error(std::move(status));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -711,6 +741,53 @@ void QuickReplyManager::delete_quick_reply_shortcut_from_server(QuickReplyShortc
|
||||||
td_->create_handler<DeleteQuickReplyShortcutQuery>(std::move(promise))->send(shortcut_id);
|
td_->create_handler<DeleteQuickReplyShortcutQuery>(std::move(promise))->send(shortcut_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QuickReplyManager::reorder_quick_reply_shortcuts(const vector<string> &names, Promise<Unit> &&promise) {
|
||||||
|
FlatHashSet<string> unique_names;
|
||||||
|
for (const auto &name : names) {
|
||||||
|
if (get_shortcut(name) == nullptr) {
|
||||||
|
return promise.set_error(Status::Error(400, "Shortcut not found"));
|
||||||
|
}
|
||||||
|
unique_names.insert(name);
|
||||||
|
}
|
||||||
|
if (unique_names.size() != names.size()) {
|
||||||
|
return promise.set_error(Status::Error(400, "Duplicate shortcut names specified"));
|
||||||
|
}
|
||||||
|
if (!shortcuts_.are_inited_) {
|
||||||
|
return promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
vector<unique_ptr<Shortcut>> shortcuts;
|
||||||
|
for (const auto &name : names) {
|
||||||
|
auto it = get_shortcut_it(name);
|
||||||
|
CHECK(it != shortcuts_.shortcuts_.end() && *it != nullptr);
|
||||||
|
shortcuts.push_back(std::move(*it));
|
||||||
|
}
|
||||||
|
for (auto &shortcut : shortcuts_.shortcuts_) {
|
||||||
|
if (shortcut != nullptr) {
|
||||||
|
CHECK(unique_names.count(shortcut->name_) == 0);
|
||||||
|
shortcuts.push_back(std::move(shortcut));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto old_server_shortcut_ids = get_server_shortcut_ids();
|
||||||
|
bool is_list_changed = is_shortcut_list_changed(shortcuts);
|
||||||
|
shortcuts_.shortcuts_ = std::move(shortcuts);
|
||||||
|
if (!is_list_changed) {
|
||||||
|
return promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
send_update_quick_reply_shortcuts();
|
||||||
|
|
||||||
|
auto new_server_shortcut_ids = get_server_shortcut_ids();
|
||||||
|
if (new_server_shortcut_ids == old_server_shortcut_ids || new_server_shortcut_ids.empty()) {
|
||||||
|
return promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
|
reorder_quick_reply_shortcuts_on_server(new_server_shortcut_ids, std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuickReplyManager::reorder_quick_reply_shortcuts_on_server(vector<QuickReplyShortcutId> shortcut_ids,
|
||||||
|
Promise<Unit> &&promise) {
|
||||||
|
td_->create_handler<ReorderQuickRepliesQuery>(std::move(promise))->send(std::move(shortcut_ids));
|
||||||
|
}
|
||||||
|
|
||||||
QuickReplyManager::Shortcut *QuickReplyManager::get_shortcut(QuickReplyShortcutId shortcut_id) {
|
QuickReplyManager::Shortcut *QuickReplyManager::get_shortcut(QuickReplyShortcutId shortcut_id) {
|
||||||
if (!shortcuts_.are_inited_) {
|
if (!shortcuts_.are_inited_) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -744,6 +821,16 @@ vector<unique_ptr<QuickReplyManager::Shortcut>>::iterator QuickReplyManager::get
|
||||||
return shortcuts_.shortcuts_.end();
|
return shortcuts_.shortcuts_.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<QuickReplyShortcutId> QuickReplyManager::get_server_shortcut_ids() const {
|
||||||
|
vector<QuickReplyShortcutId> shortcut_ids;
|
||||||
|
for (auto &shortcut : shortcuts_.shortcuts_) {
|
||||||
|
if (shortcut->shortcut_id_.is_server()) {
|
||||||
|
shortcut_ids.push_back(shortcut->shortcut_id_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return shortcut_ids;
|
||||||
|
}
|
||||||
|
|
||||||
void QuickReplyManager::sort_quick_reply_messages(vector<unique_ptr<QuickReplyMessage>> &messages) {
|
void QuickReplyManager::sort_quick_reply_messages(vector<unique_ptr<QuickReplyMessage>> &messages) {
|
||||||
std::sort(messages.begin(), messages.end(),
|
std::sort(messages.begin(), messages.end(),
|
||||||
[](const unique_ptr<QuickReplyMessage> &lhs, const unique_ptr<QuickReplyMessage> &rhs) {
|
[](const unique_ptr<QuickReplyMessage> &lhs, const unique_ptr<QuickReplyMessage> &rhs) {
|
||||||
|
|
|
@ -35,6 +35,8 @@ class QuickReplyManager final : public Actor {
|
||||||
|
|
||||||
void delete_quick_reply_shortcut(const string &name, Promise<Unit> &&promise);
|
void delete_quick_reply_shortcut(const string &name, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void reorder_quick_reply_shortcuts(const vector<string> &names, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void reload_quick_reply_shortcuts();
|
void reload_quick_reply_shortcuts();
|
||||||
|
|
||||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||||
|
@ -172,6 +174,8 @@ class QuickReplyManager final : public Actor {
|
||||||
|
|
||||||
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_server_shortcut_ids() 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>;
|
||||||
|
@ -203,6 +207,8 @@ class QuickReplyManager final : public Actor {
|
||||||
|
|
||||||
void delete_quick_reply_shortcut_from_server(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise);
|
void delete_quick_reply_shortcut_from_server(QuickReplyShortcutId shortcut_id, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void reorder_quick_reply_shortcuts_on_server(vector<QuickReplyShortcutId> shortcut_ids, Promise<Unit> &&promise);
|
||||||
|
|
||||||
Shortcuts shortcuts_;
|
Shortcuts shortcuts_;
|
||||||
|
|
||||||
FlatHashSet<QuickReplyShortcutId, QuickReplyShortcutIdHash> deleted_shortcut_ids_;
|
FlatHashSet<QuickReplyShortcutId, QuickReplyShortcutIdHash> deleted_shortcut_ids_;
|
||||||
|
|
|
@ -31,6 +31,16 @@ class QuickReplyShortcutId {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static vector<int32> get_input_quick_reply_shortcut_ids(
|
||||||
|
const vector<QuickReplyShortcutId> &quick_reply_shortcut_ids) {
|
||||||
|
vector<int32> input_quick_reply_shortcut_ids;
|
||||||
|
input_quick_reply_shortcut_ids.reserve(quick_reply_shortcut_ids.size());
|
||||||
|
for (auto &quick_reply_shortcut_id : quick_reply_shortcut_ids) {
|
||||||
|
input_quick_reply_shortcut_ids.emplace_back(quick_reply_shortcut_id.get());
|
||||||
|
}
|
||||||
|
return input_quick_reply_shortcut_ids;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const QuickReplyShortcutId &other) const {
|
bool operator==(const QuickReplyShortcutId &other) const {
|
||||||
return id == other.id;
|
return id == other.id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5768,7 +5768,13 @@ void Td::on_request(uint64 id, const td_api::loadQuickReplyShortcuts &request) {
|
||||||
void Td::on_request(uint64 id, const td_api::deleteQuickReplyShortcut &request) {
|
void Td::on_request(uint64 id, const td_api::deleteQuickReplyShortcut &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CREATE_OK_REQUEST_PROMISE();
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
quick_reply_manager_->delete_quick_reply_shortcut(request.name_, std::move(promise));
|
quick_reply_manager_->delete_quick_reply_shortcut(request.shortcut_name_, std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, const td_api::reorderQuickReplyShortcuts &request) {
|
||||||
|
CHECK_IS_USER();
|
||||||
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
|
quick_reply_manager_->reorder_quick_reply_shortcuts(request.shortcut_names_, 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) {
|
||||||
|
|
|
@ -868,6 +868,8 @@ class Td final : public Actor {
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::deleteQuickReplyShortcut &request);
|
void on_request(uint64 id, const td_api::deleteQuickReplyShortcut &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, const td_api::reorderQuickReplyShortcuts &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);
|
||||||
|
|
|
@ -4831,6 +4831,10 @@ class CliClient final : public Actor {
|
||||||
string name;
|
string name;
|
||||||
get_args(args, name);
|
get_args(args, name);
|
||||||
send_request(td_api::make_object<td_api::deleteQuickReplyShortcut>(name));
|
send_request(td_api::make_object<td_api::deleteQuickReplyShortcut>(name));
|
||||||
|
} else if (op == "rqrs") {
|
||||||
|
string names;
|
||||||
|
get_args(args, names);
|
||||||
|
send_request(td_api::make_object<td_api::reorderQuickReplyShortcuts>(autosplit_str(names)));
|
||||||
} 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") {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user