Skip to content

Commit

Permalink
do more later
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover authored Apr 23, 2024
1 parent ab3faa0 commit 7abe085
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ once_cell = "1.19.0"
ammonia = "4.0.0"
kuchikiki = "0.8.2"
js-sys = "0.3.69"
uuid = { version = "1.8.0", features = ["v4", "fast-rng"] }
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn handle_socket(socket: WebSocket, _who: SocketAddr, state: Arc<AppState>
let mut rx = state.tx.subscribe();

// Now send the "joined" message to all subscribers.
let msg = format!("user {0} connected.", user.lock().unwrap().name);
let msg = format!("user with id {0} connected.", user.lock().unwrap().id);
tracing::debug!("{msg}");

let msg_vec = (*MESSAGES.lock().unwrap().clone()).to_vec();
Expand Down Expand Up @@ -176,10 +176,11 @@ async fn handle_socket(socket: WebSocket, _who: SocketAddr, state: Arc<AppState>
}
}
},
MessageTypes::UserJoin(mut request) => {
/*let _ = state.tx.send(
serde_json::to_string(&(UserJoin { userjoin: user.lock().unwrap().name.clone() })).expect("")
);*/
MessageTypes::UserJoin(request) => {
user_recv.lock().unwrap().name = request.user;
let _ = state.tx.send(
serde_json::to_string(&(UserJoin { userjoin: user_recv.lock().unwrap().name.clone() })).expect("")
);
continue;
}
_ => {
Expand Down
4 changes: 2 additions & 2 deletions src/message/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pub struct RetrieveMessages {
// User related messages
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UserJoin {
pub userjoin: String
pub user: String
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UserLeft {
pub userleft: String
pub user: String
}

// Moderation related messages
Expand Down
19 changes: 18 additions & 1 deletion src/user/model.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
use std::error::Error;
use rustrict::{Censor, Type};
use serde::{Serialize, Deserialize};
use uuid::Uuid

/// What am I?
/// A class meant to hold all the values the server uses to compute messages.
/// *Do not send me. Ever.*
#[derive(Clone)]
pub struct User {
pub name: String,
pub id: i32,
pub glass: GlassModeration
pub glass: GlassModeration,
//pub sendable_user: SendableUser
}

/// What am I?
/// A stripped down version of the `User` struct so that you can send something to the other clients.
#[derive(Serialize, Deserialize, Clone)]
pub struct SendableUser {
pub name: String,
pub id: i32,
pub uuid: Uuid
}

impl User {
Expand All @@ -18,6 +33,8 @@ impl User {
}
}

/// What am I?
/// A struct meant to hold all the values and functions for the cauto-mod/censoring of Arcs.
#[derive(Clone, Default)]
pub struct GlassModeration {
reports: i32,
Expand Down

0 comments on commit 7abe085

Please sign in to comment.