Don't return SetMessagesTTL messages in get_new_messages.

This commit is contained in:
levlam 2022-12-01 23:44:58 +03:00
parent 02ff843bbb
commit fff8e81261
3 changed files with 28 additions and 6 deletions

View File

@ -33393,7 +33393,7 @@ void MessagesManager::on_create_new_dialog_success(int64 random_id, tl_object_pt
DialogType expected_type, Promise<Unit> &&promise) {
auto sent_messages = UpdatesManager::get_new_messages(updates.get());
auto sent_messages_random_ids = UpdatesManager::get_sent_messages_random_ids(updates.get());
if (sent_messages.size() < 1u || sent_messages_random_ids.size() < 1u) {
if (sent_messages.size() != 1u || sent_messages_random_ids.size() != 1u) {
LOG(ERROR) << "Receive wrong result for create group or channel chat " << oneline(to_string(updates));
return on_create_new_dialog_fail(random_id, Status::Error(500, "Unsupported server response"), std::move(promise));
}

View File

@ -1146,11 +1146,18 @@ FlatHashSet<int64> UpdatesManager::get_sent_messages_random_ids(const telegram_a
FlatHashSet<int64> random_ids;
auto updates = get_updates(updates_ptr);
if (updates != nullptr) {
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_;
if (random_id != 0 && !random_ids.insert(random_id).second) {
LOG(ERROR) << "Receive twice updateMessageID for " << random_id;
if (random_id != 0) {
bool found_message = false;
for (auto *message : new_messages) {
// TODO
}
if (found_message && !random_ids.insert(random_id).second) {
LOG(ERROR) << "Receive twice updateMessageID for " << random_id;
}
}
}
}
@ -1201,19 +1208,32 @@ const telegram_api::Message *UpdatesManager::get_message_by_random_id(const tele
return result;
}
bool UpdatesManager::is_additional_service_message(const telegram_api::Message *message) {
if (message->get_id() != telegram_api::messageService::ID) {
return false;
}
auto action_id = static_cast<const telegram_api::messageService *>(message)->action_->get_id();
return action_id == telegram_api::messageActionSetMessagesTTL::ID;
}
vector<const tl_object_ptr<telegram_api::Message> *> UpdatesManager::get_new_messages(
const telegram_api::Updates *updates_ptr) {
vector<const tl_object_ptr<telegram_api::Message> *> messages;
auto updates = get_updates(updates_ptr);
if (updates != nullptr) {
for (auto &update : *updates) {
const tl_object_ptr<telegram_api::Message> *message = nullptr;
auto constructor_id = update->get_id();
if (constructor_id == telegram_api::updateNewMessage::ID) {
messages.emplace_back(&static_cast<const telegram_api::updateNewMessage *>(update.get())->message_);
message = &static_cast<const telegram_api::updateNewMessage *>(update.get())->message_;
} else if (constructor_id == telegram_api::updateNewChannelMessage::ID) {
messages.emplace_back(&static_cast<const telegram_api::updateNewChannelMessage *>(update.get())->message_);
message = &static_cast<const telegram_api::updateNewChannelMessage *>(update.get())->message_;
} else if (constructor_id == telegram_api::updateNewScheduledMessage::ID) {
messages.emplace_back(&static_cast<const telegram_api::updateNewScheduledMessage *>(update.get())->message_);
message = &static_cast<const telegram_api::updateNewScheduledMessage *>(update.get())->message_;
}
if (is_additional_service_message((*message).get())) {
messages.push_back(message);
}
}
}

View File

@ -379,6 +379,8 @@ class UpdatesManager final : public Actor {
static bool is_channel_pts_update(const telegram_api::Update *update);
static bool is_additional_service_message(const telegram_api::Message *message);
static const vector<tl_object_ptr<telegram_api::Update>> *get_updates(const telegram_api::Updates *updates_ptr);
static vector<tl_object_ptr<telegram_api::Update>> *get_updates(telegram_api::Updates *updates_ptr);