Extract only relevant random_id from updates.
This commit is contained in:
parent
f8a5f42886
commit
70cfbab277
@ -13232,19 +13232,20 @@ void MessagesManager::on_update_viewed_messages_timeout(DialogId dialog_id) {
|
||||
update_viewed_messages_timeout_.add_timeout_in(dialog_id.get(), UPDATE_VIEWED_MESSAGES_PERIOD);
|
||||
}
|
||||
|
||||
MessageId MessagesManager::get_message_id(const tl_object_ptr<telegram_api::Message> &message_ptr, bool is_scheduled) {
|
||||
MessageId MessagesManager::get_message_id(const telegram_api::Message *message_ptr, bool is_scheduled) {
|
||||
CHECK(message_ptr != nullptr)
|
||||
switch (message_ptr->get_id()) {
|
||||
case telegram_api::messageEmpty::ID: {
|
||||
auto message = static_cast<const telegram_api::messageEmpty *>(message_ptr.get());
|
||||
auto message = static_cast<const telegram_api::messageEmpty *>(message_ptr);
|
||||
return is_scheduled ? MessageId() : MessageId(ServerMessageId(message->id_));
|
||||
}
|
||||
case telegram_api::message::ID: {
|
||||
auto message = static_cast<const telegram_api::message *>(message_ptr.get());
|
||||
auto message = static_cast<const telegram_api::message *>(message_ptr);
|
||||
return is_scheduled ? MessageId(ScheduledServerMessageId(message->id_), message->date_)
|
||||
: MessageId(ServerMessageId(message->id_));
|
||||
}
|
||||
case telegram_api::messageService::ID: {
|
||||
auto message = static_cast<const telegram_api::messageService *>(message_ptr.get());
|
||||
auto message = static_cast<const telegram_api::messageService *>(message_ptr);
|
||||
return is_scheduled ? MessageId(ScheduledServerMessageId(message->id_), message->date_)
|
||||
: MessageId(ServerMessageId(message->id_));
|
||||
}
|
||||
@ -13254,6 +13255,10 @@ MessageId MessagesManager::get_message_id(const tl_object_ptr<telegram_api::Mess
|
||||
}
|
||||
}
|
||||
|
||||
MessageId MessagesManager::get_message_id(const tl_object_ptr<telegram_api::Message> &message_ptr, bool is_scheduled) {
|
||||
return get_message_id(message_ptr.get(), is_scheduled);
|
||||
}
|
||||
|
||||
DialogId MessagesManager::get_message_dialog_id(const telegram_api::Message *message_ptr) {
|
||||
CHECK(message_ptr != nullptr);
|
||||
switch (message_ptr->get_id()) {
|
||||
|
@ -165,6 +165,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
static vector<int32> get_scheduled_server_message_ids(const vector<MessageId> &message_ids);
|
||||
|
||||
static MessageId get_message_id(const telegram_api::Message *message_ptr, bool is_scheduled);
|
||||
|
||||
static MessageId get_message_id(const tl_object_ptr<telegram_api::Message> &message_ptr, bool is_scheduled);
|
||||
|
||||
static DialogId get_message_dialog_id(const telegram_api::Message *message_ptr);
|
||||
|
@ -1149,12 +1149,20 @@ FlatHashSet<int64> UpdatesManager::get_sent_messages_random_ids(const telegram_a
|
||||
auto new_messages = get_new_messages(updates_ptr);
|
||||
for (auto &update : *updates) {
|
||||
if (update->get_id() == telegram_api::updateMessageID::ID) {
|
||||
int64 random_id = static_cast<const telegram_api::updateMessageID *>(update.get())->random_id_;
|
||||
auto update_message_id = static_cast<const telegram_api::updateMessageID *>(update.get());
|
||||
int64 random_id = update_message_id->random_id_;
|
||||
if (random_id != 0) {
|
||||
bool found_message = true;
|
||||
// for (auto *message : new_messages) {
|
||||
// TODO
|
||||
// }
|
||||
bool found_message = false;
|
||||
for (auto message : new_messages) {
|
||||
MessageId message_id = MessagesManager::get_message_id(message.first, message.second);
|
||||
if (message.second) {
|
||||
found_message |= message_id.is_valid_scheduled() &&
|
||||
message_id.get_scheduled_server_message_id().get() == update_message_id->id_;
|
||||
} else {
|
||||
found_message |=
|
||||
message_id.is_valid() && message_id.get_server_message_id().get() == update_message_id->id_;
|
||||
}
|
||||
}
|
||||
if (found_message && !random_ids.insert(random_id).second) {
|
||||
LOG(ERROR) << "Receive twice updateMessageID for " << random_id;
|
||||
}
|
||||
@ -1234,7 +1242,7 @@ vector<std::pair<const telegram_api::Message *, bool>> UpdatesManager::get_new_m
|
||||
is_scheduled = true;
|
||||
}
|
||||
|
||||
if (is_additional_service_message(message)) {
|
||||
if (message != nullptr && !is_additional_service_message(message)) {
|
||||
messages.emplace_back(message, is_scheduled);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user