mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-12-27 22:18:51 +00:00
Can update group conversation settings
This commit is contained in:
parent
42d43ef9d8
commit
8372e37937
@ -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)?;
|
||||
|
||||
|
@ -183,6 +183,16 @@ pub fn set_settings(settings: NewConversationSettings) -> Res {
|
||||
.exec()
|
||||
}
|
||||
|
||||
/// Change minimal membership level to join a group conversation
|
||||
pub fn set_min_group_conversation_membership_level(conv_id: ConvID, level: GroupMembershipLevel) -> Res {
|
||||
database::UpdateInfo::new(CONV_LIST_TABLE)
|
||||
.cond_conv_id("id", conv_id)
|
||||
.set_u32("min_group_membership_level", level.to_db())
|
||||
.exec()?;
|
||||
|
||||
update_members_list_for_group_conversation(conv_id)
|
||||
}
|
||||
|
||||
/// Search for private conversation between two users
|
||||
pub fn find_private(user_1: &UserID, user_2: &UserID) -> ResultBoxError<Vec<ConvID>> {
|
||||
database::QueryInfo::new(CONV_MEMBERS_TABLE)
|
||||
|
@ -228,6 +228,7 @@ pub fn get_routes() -> Vec<Route> {
|
||||
Route::post("/groups/upload_logo", Box::new(groups_controller::upload_logo)),
|
||||
Route::post("/groups/delete_logo", Box::new(groups_controller::delete_logo)),
|
||||
Route::post("/groups/create_conversation", Box::new(groups_controller::create_conversation)),
|
||||
Route::post("/groups/update_conversation", Box::new(groups_controller::update_conversation)),
|
||||
Route::post("/groups/delete_conversation", Box::new(groups_controller::delete_conversation)),
|
||||
Route::post("/groups/get_members", Box::new(groups_controller::get_members)),
|
||||
Route::post("/groups/invite", Box::new(groups_controller::invite_user)),
|
||||
|
Loading…
Reference in New Issue
Block a user