Add QuickReplyMessageUniqueId typedef.

This commit is contained in:
levlam 2024-02-22 21:44:13 +03:00
parent d478ba05c4
commit f1fbd90ae6
2 changed files with 15 additions and 12 deletions

View File

@ -428,18 +428,17 @@ void QuickReplyManager::sort_quick_reply_messages(vector<unique_ptr<QuickReplyMe
}); });
} }
vector<std::pair<MessageId, int32>> QuickReplyManager::get_quick_reply_message_ids( vector<QuickReplyManager::QuickReplyMessageUniqueId> QuickReplyManager::get_quick_reply_unique_ids(
const vector<unique_ptr<QuickReplyMessage>> &messages) { const vector<unique_ptr<QuickReplyMessage>> &messages) {
return transform(messages, [](const unique_ptr<QuickReplyMessage> &message) { return transform(messages, [](const unique_ptr<QuickReplyMessage> &message) {
return std::make_pair(message->message_id, message->edit_date); return QuickReplyMessageUniqueId(message->message_id, message->edit_date);
}); });
} }
vector<std::pair<MessageId, int32>> QuickReplyManager::get_server_quick_reply_message_ids( vector<QuickReplyManager::QuickReplyMessageUniqueId> QuickReplyManager::get_server_quick_reply_unique_ids(
const vector<unique_ptr<QuickReplyMessage>> &messages) { const vector<unique_ptr<QuickReplyMessage>> &messages) {
auto message_ids = get_quick_reply_message_ids(messages); auto message_ids = get_quick_reply_unique_ids(messages);
td::remove_if(message_ids, td::remove_if(message_ids, [](const QuickReplyMessageUniqueId &message_id) { return !message_id.first.is_server(); });
[](const std::pair<MessageId, int32> &message_id) { return !message_id.first.is_server(); });
return message_ids; return message_ids;
} }
@ -454,7 +453,7 @@ bool QuickReplyManager::update_shortcut_from(Shortcut *new_shortcut, Shortcut *o
if (is_partial) { if (is_partial) {
// only the first server message is known // only the first server message is known
// delete all definitely deleted server messages and insert the new message in the correct place // delete all definitely deleted server messages and insert the new message in the correct place
auto old_message_ids = get_quick_reply_message_ids(old_shortcut->messages_); auto old_message_ids = get_quick_reply_unique_ids(old_shortcut->messages_);
auto new_first_message_id = new_shortcut->messages_[0]->message_id; auto new_first_message_id = new_shortcut->messages_[0]->message_id;
auto it = old_shortcut->messages_.begin(); auto it = old_shortcut->messages_.begin();
while (it != old_shortcut->messages_.end() && (*it)->message_id < new_first_message_id) { while (it != old_shortcut->messages_.end() && (*it)->message_id < new_first_message_id) {
@ -470,10 +469,10 @@ bool QuickReplyManager::update_shortcut_from(Shortcut *new_shortcut, Shortcut *o
*it = std::move(new_shortcut->messages_[0]); *it = std::move(new_shortcut->messages_[0]);
} }
new_shortcut->messages_ = std::move(old_shortcut->messages_); new_shortcut->messages_ = std::move(old_shortcut->messages_);
is_changed = (old_message_ids != get_quick_reply_message_ids(new_shortcut->messages_)); is_changed = (old_message_ids != get_quick_reply_unique_ids(new_shortcut->messages_));
} else { } else {
auto old_server_message_ids = get_server_quick_reply_message_ids(old_shortcut->messages_); auto old_server_message_ids = get_server_quick_reply_unique_ids(old_shortcut->messages_);
auto new_server_message_ids = get_server_quick_reply_message_ids(new_shortcut->messages_); auto new_server_message_ids = get_server_quick_reply_unique_ids(new_shortcut->messages_);
if (old_server_message_ids == new_server_message_ids) { if (old_server_message_ids == new_server_message_ids) {
new_shortcut->messages_ = std::move(old_shortcut->messages_); new_shortcut->messages_ = std::move(old_shortcut->messages_);
} else { } else {

View File

@ -15,6 +15,8 @@
#include "td/utils/common.h" #include "td/utils/common.h"
#include <utility>
namespace td { namespace td {
class Dependencies; class Dependencies;
@ -141,10 +143,12 @@ class QuickReplyManager final : public Actor {
static void sort_quick_reply_messages(vector<unique_ptr<QuickReplyMessage>> &messages); static void sort_quick_reply_messages(vector<unique_ptr<QuickReplyMessage>> &messages);
static vector<std::pair<MessageId, int32>> get_quick_reply_message_ids( using QuickReplyMessageUniqueId = std::pair<MessageId, int32>;
static vector<QuickReplyMessageUniqueId> get_quick_reply_unique_ids(
const vector<unique_ptr<QuickReplyMessage>> &messages); const vector<unique_ptr<QuickReplyMessage>> &messages);
static vector<std::pair<MessageId, int32>> get_server_quick_reply_message_ids( static vector<QuickReplyMessageUniqueId> get_server_quick_reply_unique_ids(
const vector<unique_ptr<QuickReplyMessage>> &messages); const vector<unique_ptr<QuickReplyMessage>> &messages);
static bool update_shortcut_from(Shortcut *new_shortcut, Shortcut *old_shortcut, bool is_partial); static bool update_shortcut_from(Shortcut *new_shortcut, Shortcut *old_shortcut, bool is_partial);