1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-12-28 14:38:52 +00:00

Can change conversation name

This commit is contained in:
Pierre HUBERT 2020-06-15 14:30:01 +02:00
parent 0f856e93cb
commit 8a2b618648
3 changed files with 37 additions and 0 deletions

View File

@ -98,5 +98,25 @@ pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult {
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!")
}

View File

@ -167,6 +167,14 @@ pub fn set_members(conv_id: u64, new_list: &Vec<UserID>, can_delete: bool) -> Re
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
fn db_to_conversation_info(row: &database::RowResult) -> ResultBoxError<Conversation> {
let conv_id = row.get_u64("id")?;

View File

@ -574,6 +574,15 @@ impl UpdateInfo {
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
pub fn set_legacy_bool(mut self, name: &str, val: bool) -> UpdateInfo {
let num = match val {