Add and use QuickReplyManager::get_shortcut_it.

This commit is contained in:
levlam 2024-02-24 13:37:02 +03:00
parent 5ef3562533
commit 2c8c883fbf
2 changed files with 15 additions and 5 deletions

View File

@ -684,13 +684,12 @@ int64 QuickReplyManager::get_shortcuts_hash() const {
}
void QuickReplyManager::delete_quick_reply_shortcut(const string &name, Promise<Unit> &&promise) {
auto s = get_shortcut(name);
if (s == nullptr) {
auto it = get_shortcut_it(name);
if (it == shortcuts_.shortcuts_.end()) {
return promise.set_error(Status::Error(400, "Shortcut not found"));
}
auto shortcut_id = s->shortcut_id_;
td::remove_if(shortcuts_.shortcuts_,
[shortcut_id](const unique_ptr<Shortcut> &shortcut) { return shortcut->shortcut_id_ == shortcut_id; });
auto shortcut_id = (*it)->shortcut_id_;
shortcuts_.shortcuts_.erase(it);
if (!shortcut_id.is_server()) {
return promise.set_value(Unit());
@ -731,6 +730,15 @@ QuickReplyManager::Shortcut *QuickReplyManager::get_shortcut(const string &name)
return nullptr;
}
vector<unique_ptr<QuickReplyManager::Shortcut>>::iterator QuickReplyManager::get_shortcut_it(const string &name) {
for (auto it = shortcuts_.shortcuts_.begin(); it != shortcuts_.shortcuts_.end(); ++it) {
if ((*it)->name_ == name) {
return it;
}
}
return shortcuts_.shortcuts_.end();
}
void QuickReplyManager::sort_quick_reply_messages(vector<unique_ptr<QuickReplyMessage>> &messages) {
std::sort(messages.begin(), messages.end(),
[](const unique_ptr<QuickReplyMessage> &lhs, const unique_ptr<QuickReplyMessage> &rhs) {

View File

@ -168,6 +168,8 @@ class QuickReplyManager final : public Actor {
Shortcut *get_shortcut(const string &name);
vector<unique_ptr<Shortcut>>::iterator get_shortcut_it(const string &name);
static void sort_quick_reply_messages(vector<unique_ptr<QuickReplyMessage>> &messages);
using QuickReplyMessageUniqueId = std::pair<MessageId, int32>;