forked from jmug/stoatchat
Merge remote-tracking branch 'origin/main' into livekit
This commit is contained in:
@@ -2,6 +2,7 @@ use std::{collections::HashMap, time::Duration};
|
||||
|
||||
use amqprs::{channel::Channel as AmqpChannel, consumer::AsyncConsumer, BasicProperties, Deliver};
|
||||
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use async_trait::async_trait;
|
||||
use fcm_v1::{
|
||||
android::AndroidConfig,
|
||||
@@ -65,22 +66,16 @@ impl FcmOutboundConsumer {
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[async_trait]
|
||||
impl AsyncConsumer for FcmOutboundConsumer {
|
||||
async fn consume(
|
||||
async fn consume_event(
|
||||
&mut self,
|
||||
channel: &AmqpChannel,
|
||||
deliver: Deliver,
|
||||
basic_properties: BasicProperties,
|
||||
_channel: &AmqpChannel,
|
||||
_deliver: Deliver,
|
||||
_basic_properties: BasicProperties,
|
||||
content: Vec<u8>,
|
||||
) {
|
||||
let content = String::from_utf8(content).unwrap();
|
||||
let payload: PayloadToService = serde_json::from_str(content.as_str()).unwrap();
|
||||
|
||||
let config = revolt_config::config().await;
|
||||
) -> Result<()> {
|
||||
let content = String::from_utf8(content)?;
|
||||
let payload: PayloadToService = serde_json::from_str(content.as_str())?;
|
||||
|
||||
#[allow(clippy::needless_late_init)]
|
||||
let resp: Result<Message, FcmError>;
|
||||
@@ -95,7 +90,7 @@ impl AsyncConsumer for FcmOutboundConsumer {
|
||||
alert.from_user.username, alert.from_user.discriminator
|
||||
)))
|
||||
.clone()
|
||||
.unwrap();
|
||||
.ok_or_else(|| anyhow!("missing name"))?;
|
||||
|
||||
let mut data = HashMap::new();
|
||||
data.insert(
|
||||
@@ -123,7 +118,7 @@ impl AsyncConsumer for FcmOutboundConsumer {
|
||||
alert.accepted_user.username, alert.accepted_user.discriminator
|
||||
)))
|
||||
.clone()
|
||||
.unwrap();
|
||||
.ok_or_else(|| anyhow!("missing name"))?;
|
||||
|
||||
let mut data: HashMap<String, Value> = HashMap::new();
|
||||
data.insert(
|
||||
@@ -176,7 +171,7 @@ impl AsyncConsumer for FcmOutboundConsumer {
|
||||
}
|
||||
|
||||
PayloadKind::BadgeUpdate(_) => {
|
||||
panic!("FCM cannot handle badge updates, and they should not be sent here.")
|
||||
bail!("FCM cannot handle badge updates and they should not be sent here.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,5 +191,27 @@ impl AsyncConsumer for FcmOutboundConsumer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[async_trait]
|
||||
impl AsyncConsumer for FcmOutboundConsumer {
|
||||
async fn consume(
|
||||
&mut self,
|
||||
channel: &AmqpChannel,
|
||||
deliver: Deliver,
|
||||
basic_properties: BasicProperties,
|
||||
content: Vec<u8>,
|
||||
) {
|
||||
if let Err(err) = self
|
||||
.consume_event(channel, deliver, basic_properties, content)
|
||||
.await
|
||||
{
|
||||
revolt_config::capture_anyhow(&err);
|
||||
eprintln!("Failed to process FCM event: {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user