forked from jmug/stoatchat
fix: add flag for disabling events instead of commenting them out (#695)
Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -428,6 +428,8 @@ async fn worker(
|
||||
mut read: WsReader,
|
||||
write: &Mutex<WsWriter>,
|
||||
) {
|
||||
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);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
production = false
|
||||
disable_events_dont_use = false
|
||||
|
||||
[database]
|
||||
# MongoDB connection URL
|
||||
|
||||
@@ -423,6 +423,7 @@ pub struct Settings {
|
||||
pub features: Features,
|
||||
pub sentry: Sentry,
|
||||
pub production: bool,
|
||||
pub disable_events_dont_use: bool,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
|
||||
Reference in New Issue
Block a user