mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 16:35:17 +00:00
Can remove a member from a conversation
This commit is contained in:
@ -135,7 +135,7 @@ pub fn add_member(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
if conv.get_membership(&user_to_add).is_some() {
|
||||
r.bad_request("This user is already a member of this group!".to_string())?;
|
||||
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()?)?;
|
||||
@ -143,6 +143,30 @@ pub fn add_member(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.success("The user was added to the conversation!")
|
||||
}
|
||||
|
||||
/// Remove a member from a conversation
|
||||
pub fn remove_member(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let conv_membership = r.post_conv("convID")?;
|
||||
let conv = conversations_helper::get_single(conv_membership.conv_id)?;
|
||||
|
||||
let user_to_add = r.post_user_id("userID")?;
|
||||
|
||||
if conv.is_managed() {
|
||||
r.bad_request("This conversation is managed, you can not manually change its members!".to_string())?;
|
||||
}
|
||||
|
||||
if !conv.can_user_remove_members(r.user_id_ref()?) {
|
||||
r.forbidden("You are not allowed to remove members from this conversation!".to_string())?;
|
||||
}
|
||||
|
||||
if conv.get_membership(&user_to_add).is_none() {
|
||||
r.bad_request("This user is not a member of this conversation!".to_string())?;
|
||||
}
|
||||
|
||||
conversations_helper::remove_member(&user_to_add, conv.id, r.user_id_ref()?)?;
|
||||
|
||||
r.ok()
|
||||
}
|
||||
|
||||
/// Find a private conversation
|
||||
pub fn find_private(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let other_user = r.post_user_id("otherUser")?;
|
||||
|
Reference in New Issue
Block a user