1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 13:29:21 +00:00

Can delete a single conversation message

This commit is contained in:
Pierre HUBERT 2020-06-23 14:09:52 +02:00
parent a5c83cc1b4
commit abf9a7fa82
3 changed files with 27 additions and 0 deletions

View File

@ -312,4 +312,17 @@ pub fn update_message(r: &mut HttpRequestHandler) -> RequestResult {
conversations_helper::update_message_content(msg_id, &new_content)?;
r.success("Conversation message content successfully updated")
}
/// Delete a conversation message
pub fn delete_message(r: &mut HttpRequestHandler) -> RequestResult {
let msg_id = r.post_u64("messageID")?;
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::delete_message_by_id(msg_id)?;
r.success("The message has been successfully deleted!")
}

View File

@ -116,6 +116,8 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/conversations/updateMessage", Box::new(conversations_controller::update_message)),
Route::post("/conversations/deleteMessage", Box::new(conversations_controller::delete_message)),
// Virtual directory controller
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),

View File

@ -260,6 +260,13 @@ pub fn get_all_messages(conv_id: u64) -> ResultBoxError<Vec<ConversationMessage>
.exec(db_to_conversation_message)
}
/// Get a single message specified by its ID
pub fn get_single_message(msg_id: u64) -> ResultBoxError<ConversationMessage> {
database::QueryInfo::new(CONV_MESSAGES_TABLE)
.cond_u64("id", msg_id)
.query_row(db_to_conversation_message)
}
/// Send a new conversation message
pub fn send_message(msg: &NewConversationMessage) -> ResultBoxError<()> {
let t = time();
@ -319,6 +326,11 @@ pub fn delete_message(msg: &ConversationMessage) -> ResultBoxError<()> {
Ok(())
}
/// Delete a message with a specific ID
pub fn delete_message_by_id(id: u64) -> ResultBoxError<()> {
delete_message(&get_single_message(id)?)
}
/// Count the number of unread conversation for a specified user
pub fn count_unread_for_user(user_id: UserID) -> ResultBoxError<usize> {
database::QueryInfo::new(CONV_USERS_TABLE)