From a5cd08a655dece4269f3ac84fa2387ae356709a5 Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 27 Mar 2026 17:03:48 -0700 Subject: [PATCH] fix: add flag for disabling events instead of commenting them out (#695) Signed-off-by: IAmTomahawkx --- crates/bonfire/src/events/impl.rs | 46 ++++++++++++++------------ crates/bonfire/src/websocket.rs | 55 ++++++++++++++++++------------- crates/core/config/Revolt.toml | 1 + crates/core/config/src/lib.rs | 1 + 4 files changed, 59 insertions(+), 44 deletions(-) diff --git a/crates/bonfire/src/events/impl.rs b/crates/bonfire/src/events/impl.rs index c6d07d2f..12113537 100644 --- a/crates/bonfire/src/events/impl.rs +++ b/crates/bonfire/src/events/impl.rs @@ -400,29 +400,33 @@ impl State { } /// Push presence change to the user and all associated server topics - pub async fn broadcast_presence_change(&self, _target: bool) { - // disabled events - // if if let Some(status) = &self.cache.users.get(&self.cache.user_id).unwrap().status { - // status.presence != Some(Presence::Invisible) - // } else { - // true - // } { - // let event = EventV1::UserUpdate { - // id: self.cache.user_id.clone(), - // data: v0::PartialUser { - // online: Some(target), - // ..Default::default() - // }, - // clear: vec![], - // event_id: Some(ulid::Ulid::new().to_string()), - // }; + pub async fn broadcast_presence_change(&self, target: bool) { + let config = revolt_config::config().await; + if config.disable_events_dont_use { + return; + } - // for server in self.cache.servers.keys() { - // event.clone().p(server.clone()).await; - // } + if if let Some(status) = &self.cache.users.get(&self.cache.user_id).unwrap().status { + status.presence != Some(Presence::Invisible) + } else { + true + } { + let event = EventV1::UserUpdate { + id: self.cache.user_id.clone(), + data: v0::PartialUser { + online: Some(target), + ..Default::default() + }, + clear: vec![], + event_id: Some(ulid::Ulid::new().to_string()), + }; - // event.p(self.cache.user_id.clone()).await; - // } + for server in self.cache.servers.keys() { + event.clone().p(server.clone()).await; + } + + event.p(self.cache.user_id.clone()).await; + } } /// Handle an incoming event for protocol version 1 diff --git a/crates/bonfire/src/websocket.rs b/crates/bonfire/src/websocket.rs index 4a8cfe4c..ec4202dc 100644 --- a/crates/bonfire/src/websocket.rs +++ b/crates/bonfire/src/websocket.rs @@ -428,6 +428,8 @@ async fn worker( mut read: WsReader, write: &Mutex, ) { + let revolt_config = revolt_config::config().await; + loop { let t1 = read.try_next().fuse(); let t2 = kill_signal_r.recv().fuse(); @@ -463,31 +465,38 @@ async fn worker( }; match payload { - // disabled events - // ClientMessage::BeginTyping { channel } => { - // if !subscribed.read().await.contains(&channel) { - // continue; - // } + ClientMessage::BeginTyping { channel } => { + if revolt_config.disable_events_dont_use { + continue; + } - // EventV1::ChannelStartTyping { - // id: channel.clone(), - // user: user_id.clone(), - // } - // .p(channel.clone()) - // .await; - // } - // ClientMessage::EndTyping { channel } => { - // if !subscribed.read().await.contains(&channel) { - // continue; - // } + if !subscribed.read().await.contains(&channel) { + continue; + } - // EventV1::ChannelStopTyping { - // id: channel.clone(), - // user: user_id.clone(), - // } - // .p(channel.clone()) - // .await; - // } + EventV1::ChannelStartTyping { + id: channel.clone(), + user: user_id.clone(), + } + .p(channel.clone()) + .await; + } + ClientMessage::EndTyping { channel } => { + if revolt_config.disable_events_dont_use { + continue; + } + + if !subscribed.read().await.contains(&channel) { + continue; + } + + EventV1::ChannelStopTyping { + id: channel.clone(), + user: user_id.clone(), + } + .p(channel.clone()) + .await; + } ClientMessage::Subscribe { server_id } => { let mut servers = active_servers.lock().await; let has_item = servers.contains_key(&server_id); diff --git a/crates/core/config/Revolt.toml b/crates/core/config/Revolt.toml index 4468517f..289ab0df 100644 --- a/crates/core/config/Revolt.toml +++ b/crates/core/config/Revolt.toml @@ -1,4 +1,5 @@ production = false +disable_events_dont_use = false [database] # MongoDB connection URL diff --git a/crates/core/config/src/lib.rs b/crates/core/config/src/lib.rs index 23f7edf3..6183cca9 100644 --- a/crates/core/config/src/lib.rs +++ b/crates/core/config/src/lib.rs @@ -423,6 +423,7 @@ pub struct Settings { pub features: Features, pub sentry: Sentry, pub production: bool, + pub disable_events_dont_use: bool, } impl Settings {