1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Can register / unregister a conversation

This commit is contained in:
2021-02-06 08:55:14 +01:00
parent fad21381ed
commit cf6063feef
5 changed files with 26 additions and 3 deletions

View File

@ -12,4 +12,18 @@ pub fn set_incognito(r: &mut UserWsRequestHandler) -> Res {
r.update_conn(|c| c.incognito = new_state)?;
r.success("Updated.")
}
/// Register a conversation
pub fn register_conv(r: &mut UserWsRequestHandler) -> Res {
let conv_id = r.post_conv_id("convID")?;
r.update_conn(|c| { c.conversations.insert(conv_id); })?;
r.success("ok")
}
/// Un-register a conversation
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")
}

View File

@ -2,7 +2,7 @@
//!
//! Handles the WebSocket offered to the users
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::time::{Duration, Instant};
use actix::{Actor, ActorContext, Addr, AsyncContext, Handler, Running, StreamHandler};
@ -99,12 +99,14 @@ mod ws_tokens_list {
/// WebSocket connections list
mod ws_connections_list {
use std::collections::HashSet;
use std::sync::Arc;
use std::sync::Mutex;
use actix::Addr;
use crate::controllers::user_ws_controller::WsSession;
use crate::data::conversation::ConvID;
use crate::data::user::UserID;
/// This structure contains information about an active connection
@ -115,6 +117,7 @@ mod ws_connections_list {
pub remote_ip: String,
pub session: actix::Addr<WsSession>,
pub incognito: bool,
pub conversations: HashSet<ConvID>,
}
impl WsConnection {
@ -326,6 +329,7 @@ impl Actor for WsSession {
remote_ip: self.remote_ip.clone(),
session: ctx.address(),
incognito: self.incognito,
conversations: HashSet::new(),
})
}

View File

@ -29,6 +29,8 @@ pub fn get_user_ws_routes() -> Vec<UserWsRoute> {
vec![
// Main controller
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),
// Likes controller
UserWsRoute::new("likes/update", likes_controller::update)