Post-handle hook, partial updates and group delete.

This commit is contained in:
Paul Makles
2021-01-19 13:06:22 +00:00
parent c38977e026
commit 8bb694a1c8
8 changed files with 174 additions and 60 deletions

View File

@@ -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 &notification {
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();
}
},
}
}
_ => {}
}
}

View File

@@ -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(&notification);
if let Ok(data) = to_string(&notification) {
debug!("Pushing out notification. {}", data);
websocket::publish(ids, notification);