mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-30 01:06:27 +00:00
Can update conversation message content
This commit is contained in:
parent
21e68d2c9e
commit
a5c83cc1b4
@ -299,3 +299,17 @@ pub fn delete_conversation(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
|
|
||||||
r.success("The conversation has been deleted")
|
r.success("The conversation has been deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update a single conversation message
|
||||||
|
pub fn update_message(r: &mut HttpRequestHandler) -> RequestResult {
|
||||||
|
let msg_id = r.post_u64("messageID")?;
|
||||||
|
let new_content = r.post_string_opt("content", 3, true)?;
|
||||||
|
|
||||||
|
if !conversations_helper::is_message_owner(r.user_id()?, msg_id)? {
|
||||||
|
r.forbidden("You are not the owner of this message!".to_string())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
conversations_helper::update_message_content(msg_id, &new_content)?;
|
||||||
|
|
||||||
|
r.success("Conversation message content successfully updated")
|
||||||
|
}
|
@ -114,6 +114,8 @@ pub fn get_routes() -> Vec<Route> {
|
|||||||
|
|
||||||
Route::post("/conversations/delete", Box::new(conversations_controller::delete_conversation)),
|
Route::post("/conversations/delete", Box::new(conversations_controller::delete_conversation)),
|
||||||
|
|
||||||
|
Route::post("/conversations/updateMessage", Box::new(conversations_controller::update_message)),
|
||||||
|
|
||||||
|
|
||||||
// Virtual directory controller
|
// Virtual directory controller
|
||||||
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
|
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
|
||||||
|
@ -293,6 +293,14 @@ pub fn send_message(msg: &NewConversationMessage) -> ResultBoxError<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update message content
|
||||||
|
pub fn update_message_content(msg_id: u64, new_content: &str) -> ResultBoxError<()> {
|
||||||
|
database::UpdateInfo::new(CONV_MESSAGES_TABLE)
|
||||||
|
.cond_u64("id", msg_id)
|
||||||
|
.set_str("message", new_content)
|
||||||
|
.exec()
|
||||||
|
}
|
||||||
|
|
||||||
/// Remove a message from a conversation
|
/// Remove a message from a conversation
|
||||||
pub fn delete_message(msg: &ConversationMessage) -> ResultBoxError<()> {
|
pub fn delete_message(msg: &ConversationMessage) -> ResultBoxError<()> {
|
||||||
|
|
||||||
@ -394,6 +402,15 @@ pub fn delete_member(user_id: UserID, conv_id: u64) -> ResultBoxError<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check out whether a user is the owner of a message or not
|
||||||
|
pub fn is_message_owner(user_id: UserID, message_id: u64) -> ResultBoxError<bool> {
|
||||||
|
database::QueryInfo::new(CONV_MESSAGES_TABLE)
|
||||||
|
.cond_u64("id", message_id)
|
||||||
|
.cond_user_id("user_id", user_id)
|
||||||
|
.exec_count()
|
||||||
|
.map(|r| r > 0)
|
||||||
|
}
|
||||||
|
|
||||||
/// 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")?;
|
||||||
|
@ -651,6 +651,12 @@ impl UpdateInfo {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set a new string
|
||||||
|
pub fn set_str(mut self, name: &str, val: &str) -> Self {
|
||||||
|
self.set.insert(name.to_string(), Value::from(val));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set an new optional string
|
/// Set an new optional string
|
||||||
///
|
///
|
||||||
/// None => Empty string
|
/// None => Empty string
|
||||||
|
Loading…
Reference in New Issue
Block a user