Post-handle hook, partial updates and group delete.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use hive_pubsub::PubSub;
|
||||
use rauth::auth::Session;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use snafu::Snafu;
|
||||
|
||||
@@ -38,12 +39,13 @@ pub enum ClientboundNotification {
|
||||
},
|
||||
|
||||
Message(Message),
|
||||
MessageEdit(Message),
|
||||
MessageUpdate(JsonValue),
|
||||
MessageDelete {
|
||||
id: String,
|
||||
},
|
||||
|
||||
ChannelCreate(Channel),
|
||||
ChannelUpdate(JsonValue),
|
||||
ChannelGroupJoin {
|
||||
id: String,
|
||||
user: String,
|
||||
@@ -52,6 +54,9 @@ pub enum ClientboundNotification {
|
||||
id: String,
|
||||
user: String,
|
||||
},
|
||||
ChannelDelete {
|
||||
id: String,
|
||||
},
|
||||
|
||||
UserRelationship {
|
||||
id: String,
|
||||
@@ -95,17 +100,31 @@ pub fn prehandle_hook(notification: &ClientboundNotification) {
|
||||
.unsubscribe(&user.to_string(), &id.to_string())
|
||||
.ok();
|
||||
}
|
||||
ClientboundNotification::UserRelationship { id, user, status } => match status {
|
||||
RelationshipStatus::None => {
|
||||
ClientboundNotification::UserRelationship { id, user, status } => {
|
||||
if status != &RelationshipStatus::None {
|
||||
subscribe_if_exists(id.clone(), user.clone()).ok();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn posthandle_hook(notification: &ClientboundNotification) {
|
||||
match ¬ification {
|
||||
ClientboundNotification::ChannelDelete { id } => {
|
||||
get_hive()
|
||||
.hive
|
||||
.drop_topic(&id)
|
||||
.ok();
|
||||
}
|
||||
ClientboundNotification::UserRelationship { id, user, status } => {
|
||||
if status == &RelationshipStatus::None {
|
||||
get_hive()
|
||||
.hive
|
||||
.unsubscribe(&id.to_string(), &user.to_string())
|
||||
.ok();
|
||||
}
|
||||
_ => {
|
||||
subscribe_if_exists(id.clone(), user.clone()).ok();
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ static HIVE: OnceCell<Hive> = OnceCell::new();
|
||||
pub async fn init_hive() {
|
||||
let hive = MongodbPubSub::new(
|
||||
|ids, notification| {
|
||||
super::events::posthandle_hook(¬ification);
|
||||
|
||||
if let Ok(data) = to_string(¬ification) {
|
||||
debug!("Pushing out notification. {}", data);
|
||||
websocket::publish(ids, notification);
|
||||
|
||||
Reference in New Issue
Block a user