forked from jmug/stoatchat
Don't panic on empty message list
... even though it shouldn't be possible.
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::{Database, Message, AMQP};
|
|||||||
|
|
||||||
use deadqueue::limited::Queue;
|
use deadqueue::limited::Queue;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
use revolt_config::capture_message;
|
||||||
use revolt_models::v0::PushNotification;
|
use revolt_models::v0::PushNotification;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
@@ -64,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) {
|
pub async fn queue_message(channel: String, event: AckEvent) {
|
||||||
Q.try_push(Data {
|
Q.try_push(Data {
|
||||||
channel,
|
channel,
|
||||||
@@ -262,15 +264,17 @@ pub async fn worker(db: Database, amqp: AMQP) {
|
|||||||
if let AckEvent::ProcessMessage { messages: existing } =
|
if let AckEvent::ProcessMessage { messages: existing } =
|
||||||
&mut task.data.event
|
&mut task.data.event
|
||||||
{
|
{
|
||||||
// add the new message to the list of messages to be processed.
|
if let Some(new_event) = new_data.pop() {
|
||||||
existing.append(new_data);
|
|
||||||
|
|
||||||
// if the message contains a mass mention, do not delay it any further.
|
// if the message contains a mass mention, do not delay it any further.
|
||||||
if new_data[0].1.contains_mass_push_mention() {
|
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();
|
task.run_immediately();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
existing.push(new_event);
|
||||||
|
|
||||||
// put a cap on the amount of messages that can be queued, for particularly active channels
|
// put a cap on the amount of messages that can be queued, for particularly active channels
|
||||||
if (existing.length() as u16)
|
if (existing.length() as u16)
|
||||||
< revolt_config::config()
|
< revolt_config::config()
|
||||||
@@ -281,6 +285,11 @@ pub async fn worker(db: Database, amqp: AMQP) {
|
|||||||
{
|
{
|
||||||
task.delay();
|
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 {
|
} else {
|
||||||
panic!("Somehow got an ack message in the add mention arm");
|
panic!("Somehow got an ack message in the add mention arm");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user