1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Can register for post events

This commit is contained in:
Pierre HUBERT 2021-02-06 10:16:09 +01:00
parent 0ce59fc5ad
commit e2acb3813e
3 changed files with 20 additions and 0 deletions

View File

@ -4,6 +4,7 @@
use crate::data::base_request_handler::BaseRequestHandler; use crate::data::base_request_handler::BaseRequestHandler;
use crate::data::error::Res; use crate::data::error::Res;
use crate::data::post::PostAccessLevel;
use crate::data::user_ws_request_handler::UserWsRequestHandler; use crate::data::user_ws_request_handler::UserWsRequestHandler;
/// Update incognito status of the connection /// Update incognito status of the connection
@ -27,3 +28,17 @@ pub fn unregister_conv(r: &mut UserWsRequestHandler) -> Res {
r.update_conn(|c| { c.conversations.remove(&conv_id); })?; r.update_conn(|c| { c.conversations.remove(&conv_id); })?;
r.success("ok") 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")
}

View File

@ -107,6 +107,7 @@ mod ws_connections_list {
use crate::controllers::user_ws_controller::WsSession; use crate::controllers::user_ws_controller::WsSession;
use crate::data::conversation::ConvID; use crate::data::conversation::ConvID;
use crate::data::post::PostID;
use crate::data::user::UserID; use crate::data::user::UserID;
/// This structure contains information about an active connection /// This structure contains information about an active connection
@ -118,6 +119,7 @@ mod ws_connections_list {
pub session: actix::Addr<WsSession>, pub session: actix::Addr<WsSession>,
pub incognito: bool, pub incognito: bool,
pub conversations: HashSet<ConvID>, pub conversations: HashSet<ConvID>,
pub posts: HashSet<PostID>,
} }
impl WsConnection { impl WsConnection {
@ -330,6 +332,7 @@ impl Actor for WsSession {
session: ctx.address(), session: ctx.address(),
incognito: self.incognito, incognito: self.incognito,
conversations: HashSet::new(), conversations: HashSet::new(),
posts: HashSet::new(),
}) })
} }

View File

@ -31,6 +31,8 @@ pub fn get_user_ws_routes() -> Vec<UserWsRoute> {
UserWsRoute::new("$main/set_incognito", user_ws_actions::set_incognito), UserWsRoute::new("$main/set_incognito", user_ws_actions::set_incognito),
UserWsRoute::new("$main/register_conv", user_ws_actions::register_conv), UserWsRoute::new("$main/register_conv", user_ws_actions::register_conv),
UserWsRoute::new("$main/unregister_conv", user_ws_actions::unregister_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 // Likes controller
UserWsRoute::new("likes/update", likes_controller::update) UserWsRoute::new("likes/update", likes_controller::update)