diff --git a/src/controllers/user_ws_actions.rs b/src/controllers/user_ws_actions.rs index df7c6d4..8d92cb6 100644 --- a/src/controllers/user_ws_actions.rs +++ b/src/controllers/user_ws_actions.rs @@ -4,6 +4,7 @@ use crate::data::base_request_handler::BaseRequestHandler; use crate::data::error::Res; +use crate::data::post::PostAccessLevel; use crate::data::user_ws_request_handler::UserWsRequestHandler; /// Update incognito status of the connection @@ -26,4 +27,18 @@ pub fn unregister_conv(r: &mut UserWsRequestHandler) -> Res { let conv_id = r.post_u64("convID")?; r.update_conn(|c| { c.conversations.remove(&conv_id); })?; r.success("ok") +} + +/// Register a post +pub fn register_post(r: &mut UserWsRequestHandler) -> Res { + let post = r.post_post_with_access("postID", PostAccessLevel::BASIC_ACCESS)?; + r.update_conn(|c| { c.posts.insert(post.id); })?; + r.success("ok") +} + +/// Un-register a post +pub fn unregister_post(r: &mut UserWsRequestHandler) -> Res { + let post_id = r.post_u64("postID")?; + r.update_conn(|c| { c.posts.remove(&post_id); })?; + r.success("ok") } \ No newline at end of file diff --git a/src/controllers/user_ws_controller.rs b/src/controllers/user_ws_controller.rs index 9074296..0c32f54 100644 --- a/src/controllers/user_ws_controller.rs +++ b/src/controllers/user_ws_controller.rs @@ -107,6 +107,7 @@ mod ws_connections_list { use crate::controllers::user_ws_controller::WsSession; use crate::data::conversation::ConvID; + use crate::data::post::PostID; use crate::data::user::UserID; /// This structure contains information about an active connection @@ -118,6 +119,7 @@ mod ws_connections_list { pub session: actix::Addr, pub incognito: bool, pub conversations: HashSet, + pub posts: HashSet, } impl WsConnection { @@ -330,6 +332,7 @@ impl Actor for WsSession { session: ctx.address(), incognito: self.incognito, conversations: HashSet::new(), + posts: HashSet::new(), }) } diff --git a/src/controllers/user_ws_routes.rs b/src/controllers/user_ws_routes.rs index 0c65398..252095f 100644 --- a/src/controllers/user_ws_routes.rs +++ b/src/controllers/user_ws_routes.rs @@ -31,6 +31,8 @@ pub fn get_user_ws_routes() -> Vec { UserWsRoute::new("$main/set_incognito", user_ws_actions::set_incognito), UserWsRoute::new("$main/register_conv", user_ws_actions::register_conv), UserWsRoute::new("$main/unregister_conv", user_ws_actions::unregister_conv), + UserWsRoute::new("$main/register_post", user_ws_actions::register_post), + UserWsRoute::new("$main/unregister_post", user_ws_actions::unregister_post), // Likes controller UserWsRoute::new("likes/update", likes_controller::update)