mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-29 16:56:28 +00:00
Can change conversation name
This commit is contained in:
parent
0f856e93cb
commit
8a2b618648
@ -98,5 +98,25 @@ pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
conversations_helper::set_members(conv_id, &members, is_moderator)?;
|
conversations_helper::set_members(conv_id, &members, is_moderator)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change moderator settings
|
||||||
|
if r.has_post_parameter("name") || r.has_post_parameter("canEveryoneAddMembers") {
|
||||||
|
if !is_moderator {
|
||||||
|
r.forbidden("You are not allowed to perform changes on this conversation!".to_string())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change conversation name
|
||||||
|
if r.has_post_parameter("name") {
|
||||||
|
let name = r.post_string_opt("name", 0, true)?;
|
||||||
|
let name = if name.eq("false") || name.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
// TODO : remove HTML nodes
|
||||||
|
Some(name)
|
||||||
|
};
|
||||||
|
|
||||||
|
conversations_helper::set_name(conv_id, name)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
r.success("Conversation information successfully updated!")
|
r.success("Conversation information successfully updated!")
|
||||||
}
|
}
|
@ -167,6 +167,14 @@ pub fn set_members(conv_id: u64, new_list: &Vec<UserID>, can_delete: bool) -> Re
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set a new name to the conversation
|
||||||
|
pub fn set_name(conv_id: u64, name: Option<String>) -> ResultBoxError<()> {
|
||||||
|
database::UpdateInfo::new(CONV_LIST_TABLE)
|
||||||
|
.cond_u64("id", conv_id)
|
||||||
|
.set_opt_str("name", name)
|
||||||
|
.exec()
|
||||||
|
}
|
||||||
|
|
||||||
/// Turn a database entry into a ConversationInfo object
|
/// Turn a database entry into a ConversationInfo object
|
||||||
fn db_to_conversation_info(row: &database::RowResult) -> ResultBoxError<Conversation> {
|
fn db_to_conversation_info(row: &database::RowResult) -> ResultBoxError<Conversation> {
|
||||||
let conv_id = row.get_u64("id")?;
|
let conv_id = row.get_u64("id")?;
|
||||||
|
@ -574,6 +574,15 @@ impl UpdateInfo {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set an new optional string
|
||||||
|
///
|
||||||
|
/// None => Empty string
|
||||||
|
/// Some => The string
|
||||||
|
pub fn set_opt_str(mut self, name: &str, val: Option<String>) -> UpdateInfo {
|
||||||
|
self.set.insert(name.to_string(), Value::from(val.unwrap_or(String::new())));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set a new legacy boolean
|
/// Set a new legacy boolean
|
||||||
pub fn set_legacy_bool(mut self, name: &str, val: bool) -> UpdateInfo {
|
pub fn set_legacy_bool(mut self, name: &str, val: bool) -> UpdateInfo {
|
||||||
let num = match val {
|
let num = match val {
|
||||||
|
Loading…
Reference in New Issue
Block a user