From 4265d2ca9d1063f6c5c6ca8005675834373f94e2 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 6 Mar 2021 19:00:04 +0100 Subject: [PATCH] Fix issues --- src/controllers/conversations_controller.rs | 29 +++++++-------------- src/data/new_conversation.rs | 8 +++--- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/controllers/conversations_controller.rs b/src/controllers/conversations_controller.rs index 666a19f..9b93de5 100644 --- a/src/controllers/conversations_controller.rs +++ b/src/controllers/conversations_controller.rs @@ -17,22 +17,19 @@ use crate::data::error::Res; use crate::data::http_request_handler::HttpRequestHandler; use crate::data::new_conversation::NewConversation; use crate::data::new_conversation_message::NewConversationMessage; -use crate::data::user::UserID; use crate::data::user_ws_connection::UserWsConnection; use crate::data::user_ws_message::UserWsMessage; -use crate::helpers::{conversations_helper, events_helper, user_helper}; +use crate::helpers::{conversations_helper, events_helper}; use crate::helpers::events_helper::Event; use crate::routes::RequestResult; use crate::utils::string_utils::remove_html_nodes; use crate::utils::user_data_utils::{delete_user_data_file_if_exists, user_data_path}; +use std::collections::HashSet; /// Create a new conversation pub fn create(r: &mut HttpRequestHandler) -> RequestResult { let name = r.post_string("name")?; - let mut members = r.post_numbers_list("users", 1)? - .iter() - .map(|f| UserID::new(f.clone())) - .collect::>(); + let mut members = r.post_users_id("users")?; // Adapt name let name = match name.as_str() { @@ -40,18 +37,8 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult { s => Some(s.to_string()) }; - // Check if members exists - for user in &members { - if !user_helper::exists(user)? { - r.not_found(format!("User {} not found!", user.id()))?; - } - } - // Add current user ID if required - let curr_user_id = r.user_id()?; - if !members.contains(&curr_user_id) { - members.push(curr_user_id); - } + members.insert(r.user_id()?); let conv = NewConversation { owner_id: r.user_id()?, @@ -204,13 +191,17 @@ pub fn find_private(r: &mut HttpRequestHandler) -> RequestResult { return r.not_found(format!("Not any private conversation was found. The server was not allowed to create a new one...")); } + let mut members = HashSet::new(); + members.insert(r.user_id()?); + members.insert(r.user_id()?); + let new_conv = NewConversation { owner_id: r.user_id()?, name: None, owner_following: true, - members: vec![r.user_id()?, other_user], + members, can_everyone_add_members: true, - color: r.post_color_opt("color")?, + color: None, logo: None, group_id: None, }; diff --git a/src/data/new_conversation.rs b/src/data/new_conversation.rs index bad0c1a..7175faa 100644 --- a/src/data/new_conversation.rs +++ b/src/data/new_conversation.rs @@ -2,8 +2,10 @@ //! //! @author Pierre Huber -use crate::data::user::UserID; +use std::collections::HashSet; + use crate::data::group_id::GroupID; +use crate::data::user::UserID; #[derive(Debug)] pub struct NewConversation { @@ -13,6 +15,6 @@ pub struct NewConversation { pub color: Option, pub logo: Option, pub owner_following: bool, - pub members: Vec, - pub can_everyone_add_members: bool + pub members: HashSet, + pub can_everyone_add_members: bool, } \ No newline at end of file