1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-25 23:09:22 +00:00

Fix issues

This commit is contained in:
Pierre HUBERT 2021-03-06 19:00:04 +01:00
parent bb6fa6954f
commit 4265d2ca9d
2 changed files with 15 additions and 22 deletions

View File

@ -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::<Vec<UserID>>();
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,
};

View File

@ -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<String>,
pub logo: Option<String>,
pub owner_following: bool,
pub members: Vec<UserID>,
pub can_everyone_add_members: bool
pub members: HashSet<UserID>,
pub can_everyone_add_members: bool,
}