forked from jmug/stoatchat
feat: Add Mass Mentions to the backend (#394)
* feat: create base of push daemon Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com> * Add outbound senders * Make web_push send to rabbit instead (temp stuff) * feat: stability and friend requests * make vapid fr stuff not suck * swap naming of queue * move pushd into daemons folder * fix cargo file for move into daemons folder * feat: probably working fcm push notifs * comment out fcm webpush stuff since the config keys dont exist * fix fcm, name queues according to their prod status and configure routing keys * add pushd to docker * mix: Remove old code, add stuff to pushd * fix: lockfile * feat: update rocket to 5.0.1 * fix: fix queues and ack bugs * Move rabbit messsage processing into ack queue * chore: update readme * chore: optimizations for ack database hits * pushd flowchart * misc: update flowchart * exit dependancy hell * add rocket_impl flag to authifier * make the tests file of delta actually compile * fix: don't silence every push message * fix: don't silence all messages * add debug logging for sending data to rabbit from message events * validate mentions at a server membership level * put back that import that was actually important * minor fix to lockfile * update delta authifier * feat: proper permissions for push notifications * add unit test for mention sanitization * remove local file dependancy on authifier * update ports to proper defaults * fixTM the node bindings * Theoretically configure docker releases for pushd Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com> * declare exchange in pushd and delta * fix createbuckets script Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com> * fix: reference db implementation Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com> * fix: remove finally redundant code Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com> * fix: changes Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com> * fix: other changes Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com> * fix: make channel name return result Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com> * Add role mention parsing * feat: update to mongo 3.1, add member generator. * integrate mass mentions into pushd * patch redis-rs with updated versions * feat: chunk role mentions * move permission bits to 37/38 to avoid livekit conflict * change role mention format to <%id> * fix the lockfile from merge * fix: PR change requests * feat: add tests * fix: i am a dumbass * fix: tests, again --------- Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@ use validator::HasLen;
|
||||
use revolt_result::Result;
|
||||
|
||||
use super::DelayedTask;
|
||||
use crate::Channel::{TextChannel, VoiceChannel};
|
||||
|
||||
/// Enumeration of possible events
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
@@ -120,17 +121,22 @@ pub async fn handle_ack_event(
|
||||
);
|
||||
|
||||
// find all the users we'll be notifying
|
||||
messages
|
||||
.iter()
|
||||
.for_each(|(_, _, recipents, _)| users.extend(recipents.iter()));
|
||||
messages.iter().for_each(|(_, _, recipents, _)| {
|
||||
users.extend(recipents.iter());
|
||||
});
|
||||
|
||||
debug!("Found {} users to notify.", users.len());
|
||||
|
||||
for user in users {
|
||||
let message_ids: Vec<String> = messages
|
||||
.iter()
|
||||
.filter(|(_, _, recipients, _)| recipients.contains(user))
|
||||
.map(|(_, message, _, _)| message.id.clone())
|
||||
.filter_map(|(_, message, recipients, _)| {
|
||||
if recipients.contains(user) {
|
||||
Some(message.id.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
if !message_ids.is_empty() {
|
||||
@@ -140,13 +146,18 @@ pub async fn handle_ack_event(
|
||||
debug!("Added {} mentions for user {}", message_ids.len(), &user);
|
||||
}
|
||||
|
||||
for (push, _, recipients, silenced) in messages {
|
||||
if *silenced || recipients.is_empty() || push.is_none() {
|
||||
let mut mass_mentions = vec![];
|
||||
|
||||
for (push, message, recipients, silenced) in messages {
|
||||
if *silenced
|
||||
|| push.is_none()
|
||||
|| (recipients.is_empty() && !message.contains_mass_push_mention())
|
||||
{
|
||||
debug!(
|
||||
"Rejecting push: silenced: {}, recipient count: {}, push exists: {:?}",
|
||||
*silenced,
|
||||
recipients.length(),
|
||||
push
|
||||
push.is_some()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@@ -162,6 +173,35 @@ pub async fn handle_ack_event(
|
||||
{
|
||||
revolt_config::capture_error(&err);
|
||||
}
|
||||
|
||||
if message.contains_mass_push_mention() {
|
||||
mass_mentions.push(push.clone().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
if !mass_mentions.is_empty() {
|
||||
debug!(
|
||||
"Sending mass mention push event to AMQP; channel {}",
|
||||
&mass_mentions[0].message.channel
|
||||
);
|
||||
|
||||
let channel = db
|
||||
.fetch_channel(&mass_mentions[0].message.channel)
|
||||
.await
|
||||
.expect("Failed to fetch channel from db");
|
||||
|
||||
match channel {
|
||||
TextChannel { server, .. } | VoiceChannel { server, .. } => {
|
||||
if let Err(err) =
|
||||
amqp.mass_mention_message_sent(server, mass_mentions).await
|
||||
{
|
||||
revolt_config::capture_error(&err);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
panic!("Unknown channel type when sending mass mention event");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -192,7 +232,7 @@ pub async fn worker(db: Database, amqp: AMQP) {
|
||||
revolt_config::capture_error(&err);
|
||||
error!("{err:?} for {event:?}. ({user:?}, {channel})");
|
||||
} else {
|
||||
info!("User {user:?} ack in {channel} with {event:?}");
|
||||
debug!("User {user:?} ack in {channel} with {event:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,6 +264,12 @@ pub async fn worker(db: Database, amqp: AMQP) {
|
||||
// add the new message to the list of messages to be processed.
|
||||
existing.append(new_data);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// put a cap on the amount of messages that can be queued, for particularly active channels
|
||||
if (existing.length() as u16)
|
||||
< revolt_config::config()
|
||||
|
||||
Reference in New Issue
Block a user