mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Can create group conversation
This commit is contained in:
@ -45,6 +45,7 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
can_everyone_add_members: r.post_bool_opt("canEveryoneAddMembers", true),
|
||||
color: r.post_color_opt("color")?,
|
||||
group_id: None,
|
||||
group_min_membership_level: None,
|
||||
logo: None,
|
||||
};
|
||||
|
||||
@ -146,7 +147,7 @@ pub fn add_member(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.bad_request("This user is already a member of this conversation!".to_string())?;
|
||||
}
|
||||
|
||||
conversations_helper::add_member(conv.id, &user_to_add, true, false, r.user_id_ref()?)?;
|
||||
conversations_helper::add_member(conv.id, &user_to_add, true, false, Some(r.user_id_ref()?))?;
|
||||
|
||||
r.success("The user was added to the conversation!")
|
||||
}
|
||||
@ -194,7 +195,7 @@ pub fn remove_member(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.bad_request("This user is not a member of this conversation!".to_string())?;
|
||||
}
|
||||
|
||||
conversations_helper::remove_member(&user_to_remove, conv.id, r.user_id_ref()?)?;
|
||||
conversations_helper::remove_member(&user_to_remove, conv.id, Some(r.user_id_ref()?))?;
|
||||
|
||||
r.ok()
|
||||
}
|
||||
@ -225,6 +226,7 @@ pub fn find_private(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
color: None,
|
||||
logo: None,
|
||||
group_id: None,
|
||||
group_min_membership_level: None,
|
||||
};
|
||||
let conv_id = conversations_helper::create(&new_conv)?;
|
||||
list.push(conv_id);
|
||||
|
@ -8,20 +8,35 @@ use crate::api_data::advanced_group_api::AdvancedGroupApi;
|
||||
use crate::api_data::group_api::GroupApi;
|
||||
use crate::api_data::group_member_api::GroupMemberAPI;
|
||||
use crate::api_data::res_change_group_logo::ResChangeGroupLogo;
|
||||
use crate::api_data::res_create_conversation_for_group::ResCreateConversationForGroup;
|
||||
use crate::api_data::res_create_group::GroupCreationResult;
|
||||
use crate::constants::{DEFAULT_GROUP_LOGO, PATH_GROUPS_LOGOS};
|
||||
use crate::data::base_request_handler::BaseRequestHandler;
|
||||
use crate::data::error::Res;
|
||||
use crate::data::group::{Group, GroupAccessLevel, GroupPostsCreationLevel, GroupRegistrationLevel, GroupVisibilityLevel};
|
||||
use crate::data::group_id::GroupID;
|
||||
use crate::data::group_member::{GroupMember, GroupMembershipLevel};
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::data::new_group::NewGroup;
|
||||
use crate::data::notification::NotifEventType;
|
||||
use crate::helpers::{groups_helper, notifications_helper, virtual_directory_helper};
|
||||
use crate::helpers::{conversations_helper, groups_helper, notifications_helper, virtual_directory_helper};
|
||||
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
||||
use crate::routes::RequestResult;
|
||||
use crate::utils::date_utils::time;
|
||||
|
||||
impl HttpRequestHandler {
|
||||
/// Get membership level for a conversation
|
||||
pub fn post_group_membership_level_for_conversation(&mut self, name: &str) -> Res<GroupMembershipLevel> {
|
||||
let level = GroupMembershipLevel::from_api(&self.post_string(name)?);
|
||||
|
||||
if !level.is_at_least_member() {
|
||||
self.bad_request("Specified membership level is not enough!".to_string())?;
|
||||
}
|
||||
|
||||
Ok(level)
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new group
|
||||
pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let new_group = NewGroup {
|
||||
@ -153,6 +168,17 @@ pub fn delete_logo(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.set_response(ResChangeGroupLogo::new(DEFAULT_GROUP_LOGO))
|
||||
}
|
||||
|
||||
/// Create a new group's conversation
|
||||
pub fn create_conversation(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let group = r.post_group_id_with_access("group_id", GroupAccessLevel::ADMIN_ACCESS)?;
|
||||
let min_membership_level = r.post_group_membership_level_for_conversation("min_membership_level")?;
|
||||
let name = r.post_string("name")?;
|
||||
|
||||
let conv_id = conversations_helper::create_conversation_for_group(group, min_membership_level, &name)?;
|
||||
|
||||
r.set_response(ResCreateConversationForGroup::new(conv_id))
|
||||
}
|
||||
|
||||
/// Get the list of members of a group
|
||||
pub fn get_members(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let group_id = r.post_group_id("id")?;
|
||||
|
Reference in New Issue
Block a user