mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Can update group conversation settings
This commit is contained in:
@ -23,6 +23,7 @@ use crate::helpers::{conversations_helper, groups_helper, notifications_helper,
|
||||
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
||||
use crate::routes::RequestResult;
|
||||
use crate::utils::date_utils::time;
|
||||
use crate::data::conversation::Conversation;
|
||||
|
||||
impl HttpRequestHandler {
|
||||
/// Get membership level for a conversation
|
||||
@ -35,6 +36,18 @@ impl HttpRequestHandler {
|
||||
|
||||
Ok(level)
|
||||
}
|
||||
|
||||
/// Get a group conversation referenced in the request, for which current user is an admin
|
||||
fn post_group_conv_admin(&mut self, name: &str) -> Res<Conversation> {
|
||||
let conv_membership = self.post_conv_admin(name)?;
|
||||
let conv = conversations_helper::get_single(conv_membership.conv_id)?;
|
||||
|
||||
if !conv.is_linked_to_group() {
|
||||
self.bad_request("This conversation is not linked to a group, it can not be deleted this way!".to_string())?;
|
||||
}
|
||||
|
||||
Ok(conv)
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new group
|
||||
@ -179,14 +192,19 @@ pub fn create_conversation(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.set_response(ResCreateConversationForGroup::new(conv_id))
|
||||
}
|
||||
|
||||
/// Update a group's conversation settings
|
||||
pub fn update_conversation(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let conv = r.post_group_conv_admin("conv_id")?;
|
||||
let min_level = r.post_group_membership_level_for_conversation("min_membership_level")?;
|
||||
|
||||
conversations_helper::set_min_group_conversation_membership_level(conv.id, min_level)?;
|
||||
|
||||
r.ok()
|
||||
}
|
||||
|
||||
/// Delete a group's conversation
|
||||
pub fn delete_conversation(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let conv_membership = r.post_conv_admin("conv_id")?;
|
||||
let conv = conversations_helper::get_single(conv_membership.conv_id)?;
|
||||
|
||||
if !conv.is_linked_to_group() {
|
||||
r.bad_request("This conversation is not linked to a group, it can not deleted this way!".to_string())?;
|
||||
}
|
||||
let conv = r.post_group_conv_admin("conv_id")?;
|
||||
|
||||
conversations_helper::delete_conversation(&conv)?;
|
||||
|
||||
|
Reference in New Issue
Block a user