Add and use add_message_update.

main
levlam 2 months ago
parent 4cd53aa866
commit 6ba35983a3

@ -16549,6 +16549,46 @@ void Client::add_new_message(object_ptr<td_api::message> &&message, bool is_edit
process_new_message_queue(chat_id, 0); process_new_message_queue(chat_id, 0);
} }
void Client::add_message_update(UpdateType update_type, const MessageInfo *message_info, int64 webhook_queue_id) {
int32 message_date = message_info->edit_date == 0 ? message_info->date : message_info->edit_date;
auto now = get_unix_time();
auto update_delay_time = now - td::max(message_date, parameters_->shared_data_->get_unix_time(webhook_set_time_));
const auto UPDATE_DELAY_WARNING_TIME = 10 * 60;
if (delayed_update_count_ > 0 && (update_type != delayed_update_type_ || message_info->chat_id != delayed_chat_id_)) {
if (delayed_update_count_ == 1) {
LOG(ERROR) << "Receive very old update " << get_update_type_name(delayed_update_type_) << " sent at "
<< delayed_min_date_ << " in chat " << delayed_chat_id_ << " with a delay of " << delayed_max_time_
<< " seconds";
} else {
LOG(ERROR) << "Receive " << delayed_update_count_ << " very old updates "
<< get_update_type_name(delayed_update_type_) << " sent from " << delayed_min_date_ << " to "
<< delayed_max_date_ << " in chat " << delayed_chat_id_ << " with a delay up to " << delayed_max_time_
<< " seconds";
}
delayed_update_count_ = 0;
}
if (message_date > log_in_date_ && update_delay_time > UPDATE_DELAY_WARNING_TIME &&
message_date > last_synchronization_error_date_ + 60) {
if (delayed_update_count_ == 0) {
delayed_update_type_ = update_type;
delayed_chat_id_ = message_info->chat_id;
delayed_min_date_ = message_date;
delayed_max_date_ = message_date;
delayed_max_time_ = update_delay_time;
} else {
delayed_min_date_ = td::min(message_date, delayed_min_date_);
delayed_max_date_ = td::max(message_date, delayed_max_date_);
delayed_max_time_ = td::max(update_delay_time, delayed_max_time_);
}
delayed_update_count_++;
}
auto left_time = message_date + 86400 - now;
message_info->is_content_changed = false;
add_update(update_type, JsonMessage(message_info, true, get_update_type_name(update_type).str(), this), left_time,
webhook_queue_id);
}
void Client::add_update_poll(object_ptr<td_api::updatePoll> &&update) { void Client::add_update_poll(object_ptr<td_api::updatePoll> &&update) {
CHECK(update != nullptr); CHECK(update != nullptr);
add_update(UpdateType::Poll, JsonPoll(update->poll_.get(), nullptr, this), 86400, update->poll_->id_); add_update(UpdateType::Poll, JsonPoll(update->poll_.get(), nullptr, this), 86400, update->poll_->id_);
@ -17421,55 +17461,16 @@ void Client::process_new_message_queue(int64 chat_id, int state) {
continue; continue;
} }
UpdateType update_type;
auto chat = get_chat(chat_id); auto chat = get_chat(chat_id);
CHECK(chat != nullptr); CHECK(chat != nullptr);
bool is_channel_post = if (chat->type == ChatInfo::Type::Supergroup && !get_supergroup_info(chat->supergroup_id)->is_supergroup) {
(chat->type == ChatInfo::Type::Supergroup && !get_supergroup_info(chat->supergroup_id)->is_supergroup);
UpdateType update_type;
if (is_channel_post) {
update_type = is_edited ? UpdateType::EditedChannelPost : UpdateType::ChannelPost; update_type = is_edited ? UpdateType::EditedChannelPost : UpdateType::ChannelPost;
} else { } else {
update_type = is_edited ? UpdateType::EditedMessage : UpdateType::Message; update_type = is_edited ? UpdateType::EditedMessage : UpdateType::Message;
} }
int32 message_date = message_info->edit_date == 0 ? message_info->date : message_info->edit_date; add_message_update(update_type, message_info, chat_id);
if (delayed_update_count_ > 0 && (update_type != delayed_update_type_ || chat_id != delayed_chat_id_)) {
if (delayed_update_count_ == 1) {
LOG(ERROR) << "Receive very old update " << get_update_type_name(delayed_update_type_) << " sent at "
<< delayed_min_date_ << " in chat " << delayed_chat_id_ << " with a delay of " << delayed_max_time_
<< " seconds";
} else {
LOG(ERROR) << "Receive " << delayed_update_count_ << " very old updates "
<< get_update_type_name(delayed_update_type_) << " sent from " << delayed_min_date_ << " to "
<< delayed_max_date_ << " in chat " << delayed_chat_id_ << " with a delay up to "
<< delayed_max_time_ << " seconds";
}
delayed_update_count_ = 0;
}
auto now = get_unix_time();
auto update_delay_time = now - td::max(message_date, parameters_->shared_data_->get_unix_time(webhook_set_time_));
const auto UPDATE_DELAY_WARNING_TIME = 10 * 60;
if (message_date > log_in_date_ && update_delay_time > UPDATE_DELAY_WARNING_TIME &&
message_date > last_synchronization_error_date_ + 60) {
if (delayed_update_count_ == 0) {
delayed_update_type_ = update_type;
delayed_chat_id_ = chat_id;
delayed_min_date_ = message_date;
delayed_max_date_ = message_date;
delayed_max_time_ = update_delay_time;
} else {
delayed_min_date_ = td::min(message_date, delayed_min_date_);
delayed_max_date_ = td::max(message_date, delayed_max_date_);
delayed_max_time_ = td::max(update_delay_time, delayed_max_time_);
}
delayed_update_count_++;
}
auto left_time = message_date + 86400 - now;
message_info->is_content_changed = false;
add_update(update_type, JsonMessage(message_info, true, get_update_type_name(update_type).str(), this), left_time,
chat_id);
} }
new_message_queues_.erase(chat_id); new_message_queues_.erase(chat_id);
} }
@ -17515,13 +17516,9 @@ void Client::process_new_business_message_queue(const td::string &connection_id,
continue; continue;
} }
auto message_date = message_info->edit_date == 0 ? message_info->date : message_info->edit_date;
auto now = get_unix_time();
auto left_time = message_date + 86400 - now;
auto webhook_queue_id = message_info->chat_id + (static_cast<int64>(11) << 33); auto webhook_queue_id = message_info->chat_id + (static_cast<int64>(11) << 33);
auto update_type = is_edited ? UpdateType::EditedBusinessMessage : UpdateType::BusinessMessage; auto update_type = is_edited ? UpdateType::EditedBusinessMessage : UpdateType::BusinessMessage;
add_update(update_type, JsonMessage(message_info.get(), true, get_update_type_name(update_type).str(), this), add_message_update(update_type, message_info.get(), webhook_queue_id);
left_time, webhook_queue_id);
} }
new_business_message_queues_.erase(connection_id); new_business_message_queues_.erase(connection_id);
} }

@ -1384,6 +1384,8 @@ class Client final : public WebhookActor::Callback {
void add_update_impl(UpdateType update_type, const td::VirtuallyJsonable &update, int32 timeout, void add_update_impl(UpdateType update_type, const td::VirtuallyJsonable &update, int32 timeout,
int64 webhook_queue_id); int64 webhook_queue_id);
void add_message_update(UpdateType update_type, const MessageInfo *message_info, int64 webhook_queue_id);
std::size_t get_pending_update_count() const; std::size_t get_pending_update_count() const;
void update_last_synchronization_error_date(); void update_last_synchronization_error_date();

Loading…
Cancel
Save