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
|
/// Push presence change to the user and all associated server topics
|
||||||
pub async fn broadcast_presence_change(&self, _target: bool) {
|
pub async fn broadcast_presence_change(&self, target: bool) {
|
||||||
// disabled events
|
let config = revolt_config::config().await;
|
||||||
// if if let Some(status) = &self.cache.users.get(&self.cache.user_id).unwrap().status {
|
if config.disable_events_dont_use {
|
||||||
// status.presence != Some(Presence::Invisible)
|
return;
|
||||||
// } 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()),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// for server in self.cache.servers.keys() {
|
if if let Some(status) = &self.cache.users.get(&self.cache.user_id).unwrap().status {
|
||||||
// event.clone().p(server.clone()).await;
|
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
|
/// Handle an incoming event for protocol version 1
|
||||||
|
|||||||
@@ -428,6 +428,8 @@ async fn worker(
|
|||||||
mut read: WsReader,
|
mut read: WsReader,
|
||||||
write: &Mutex<WsWriter>,
|
write: &Mutex<WsWriter>,
|
||||||
) {
|
) {
|
||||||
|
let revolt_config = revolt_config::config().await;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let t1 = read.try_next().fuse();
|
let t1 = read.try_next().fuse();
|
||||||
let t2 = kill_signal_r.recv().fuse();
|
let t2 = kill_signal_r.recv().fuse();
|
||||||
@@ -463,31 +465,38 @@ async fn worker(
|
|||||||
};
|
};
|
||||||
|
|
||||||
match payload {
|
match payload {
|
||||||
// disabled events
|
ClientMessage::BeginTyping { channel } => {
|
||||||
// ClientMessage::BeginTyping { channel } => {
|
if revolt_config.disable_events_dont_use {
|
||||||
// if !subscribed.read().await.contains(&channel) {
|
continue;
|
||||||
// continue;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// EventV1::ChannelStartTyping {
|
if !subscribed.read().await.contains(&channel) {
|
||||||
// id: channel.clone(),
|
continue;
|
||||||
// user: user_id.clone(),
|
}
|
||||||
// }
|
|
||||||
// .p(channel.clone())
|
|
||||||
// .await;
|
|
||||||
// }
|
|
||||||
// ClientMessage::EndTyping { channel } => {
|
|
||||||
// if !subscribed.read().await.contains(&channel) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// EventV1::ChannelStopTyping {
|
EventV1::ChannelStartTyping {
|
||||||
// id: channel.clone(),
|
id: channel.clone(),
|
||||||
// user: user_id.clone(),
|
user: user_id.clone(),
|
||||||
// }
|
}
|
||||||
// .p(channel.clone())
|
.p(channel.clone())
|
||||||
// .await;
|
.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 } => {
|
ClientMessage::Subscribe { server_id } => {
|
||||||
let mut servers = active_servers.lock().await;
|
let mut servers = active_servers.lock().await;
|
||||||
let has_item = servers.contains_key(&server_id);
|
let has_item = servers.contains_key(&server_id);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
production = false
|
production = false
|
||||||
|
disable_events_dont_use = false
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
# MongoDB connection URL
|
# MongoDB connection URL
|
||||||
|
|||||||
@@ -423,6 +423,7 @@ pub struct Settings {
|
|||||||
pub features: Features,
|
pub features: Features,
|
||||||
pub sentry: Sentry,
|
pub sentry: Sentry,
|
||||||
pub production: bool,
|
pub production: bool,
|
||||||
|
pub disable_events_dont_use: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
|
|||||||
Reference in New Issue
Block a user