2021-02-05 13:24:00 +00:00
|
|
|
//! # User WebSocket actions
|
|
|
|
//!
|
|
|
|
//! This module contains all the base action that can be executed by the WebSocket
|
|
|
|
|
|
|
|
use crate::data::base_request_handler::BaseRequestHandler;
|
|
|
|
use crate::data::error::Res;
|
2021-02-06 09:16:09 +00:00
|
|
|
use crate::data::post::PostAccessLevel;
|
2021-02-05 13:24:00 +00:00
|
|
|
use crate::data::user_ws_request_handler::UserWsRequestHandler;
|
2021-03-04 17:51:52 +00:00
|
|
|
use crate::data::conversation::ConvID;
|
2021-02-05 13:24:00 +00:00
|
|
|
|
|
|
|
/// Update incognito status of the connection
|
|
|
|
pub fn set_incognito(r: &mut UserWsRequestHandler) -> Res {
|
|
|
|
let new_state = r.post_bool("enable")?;
|
|
|
|
r.update_conn(|c| c.incognito = new_state)?;
|
|
|
|
|
|
|
|
r.success("Updated.")
|
2021-02-06 07:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Register a conversation
|
|
|
|
pub fn register_conv(r: &mut UserWsRequestHandler) -> Res {
|
2021-03-04 17:51:52 +00:00
|
|
|
let conv_id = r.post_conv("convID")?.conv_id;
|
2021-02-06 07:55:14 +00:00
|
|
|
r.update_conn(|c| { c.conversations.insert(conv_id); })?;
|
|
|
|
r.success("ok")
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Un-register a conversation
|
|
|
|
pub fn unregister_conv(r: &mut UserWsRequestHandler) -> Res {
|
2021-03-04 17:51:52 +00:00
|
|
|
let conv_id = ConvID::new(r.post_u64("convID")?);
|
2021-02-06 07:55:14 +00:00
|
|
|
r.update_conn(|c| { c.conversations.remove(&conv_id); })?;
|
|
|
|
r.success("ok")
|
2021-02-06 09:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// 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")
|
2021-02-05 13:24:00 +00:00
|
|
|
}
|