Merge remote-tracking branch 'origin/main' into livekit

This commit is contained in:
Zomatree
2025-06-02 02:11:51 +01:00
parent 48e0b48ea9
commit ea1c165d80
89 changed files with 1662 additions and 1651 deletions

View File

@@ -3,8 +3,8 @@ use crate::{Database, Message, AMQP};
use deadqueue::limited::Queue;
use once_cell::sync::Lazy;
use revolt_config::capture_message;
use revolt_models::v0::PushNotification;
use rocket::form::validate::Contains;
use std::{
collections::{HashMap, HashSet},
time::Duration,
@@ -65,6 +65,7 @@ pub async fn queue_ack(channel: String, user: String, event: AckEvent) {
);
}
/// Do not add more than one message per event.
pub async fn queue_message(channel: String, event: AckEvent) {
Q.try_push(Data {
channel,
@@ -114,7 +115,7 @@ pub async fn handle_ack_event(
}
AckEvent::ProcessMessage { messages } => {
let mut users: HashSet<&String> = HashSet::new();
debug!(
info!(
"Processing {} messages from channel {}",
messages.len(),
messages[0].1.channel
@@ -125,7 +126,7 @@ pub async fn handle_ack_event(
users.extend(recipents.iter());
});
debug!("Found {} users to notify.", users.len());
info!("Found {} users to notify.", users.len());
for user in users {
let message_ids: Vec<String> = messages
@@ -143,7 +144,7 @@ pub async fn handle_ack_event(
db.add_mention_to_unread(channel, user, &message_ids)
.await?;
}
debug!("Added {} mentions for user {}", message_ids.len(), &user);
info!("Added {} mentions for user {}", message_ids.len(), &user);
}
let mut mass_mentions = vec![];
@@ -232,7 +233,7 @@ pub async fn worker(db: Database, amqp: AMQP) {
revolt_config::capture_error(&err);
error!("{err:?} for {event:?}. ({user:?}, {channel})");
} else {
debug!("User {user:?} ack in {channel} with {event:?}");
info!("User {user:?} ack in {channel} with {event:?}");
}
}
}
@@ -247,6 +248,8 @@ pub async fn worker(db: Database, amqp: AMQP) {
mut event,
}) = Q.try_pop()
{
info!("Took next ack from queue, now {} remaining", Q.len());
let key: (Option<String>, String, u8) = (
user,
channel,
@@ -261,24 +264,31 @@ pub async fn worker(db: Database, amqp: AMQP) {
if let AckEvent::ProcessMessage { messages: existing } =
&mut task.data.event
{
// add the new message to the list of messages to be processed.
existing.append(new_data);
if let Some(new_event) = new_data.pop() {
// if the message contains a mass mention, do not delay it any further.
if new_event.1.contains_mass_push_mention() {
// add the new message to the list of messages to be processed.
existing.push(new_event);
task.run_immediately();
continue;
}
// if the message contains a mass mention, do not delay it any further.
if new_data[0].1.contains_mass_push_mention() {
task.run_immediately();
continue;
}
existing.push(new_event);
// put a cap on the amount of messages that can be queued, for particularly active channels
if (existing.length() as u16)
< revolt_config::config()
.await
.features
.advanced
.process_message_delay_limit
{
task.delay();
// put a cap on the amount of messages that can be queued, for particularly active channels
if (existing.length() as u16)
< revolt_config::config()
.await
.features
.advanced
.process_message_delay_limit
{
task.delay();
}
} else {
let err_msg = format!("Got zero-length message event: {event:?}");
capture_message(&err_msg, revolt_config::Level::Warning);
info!("{err_msg}")
}
} else {
panic!("Somehow got an ack message in the add mention arm");