mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Enforce messages text len policy
This commit is contained in:
@ -9,7 +9,7 @@ use crate::api_data::list_unread_conversations_api::UnreadConversationAPI;
|
||||
use crate::api_data::res_count_unread_conversations::ResultCountUnreadConversations;
|
||||
use crate::api_data::res_create_conversation::ResCreateConversation;
|
||||
use crate::api_data::res_find_private_conversations::ResFindPrivateConversations;
|
||||
use crate::constants::MIN_CONVERSATION_MESSAGE_LENGTH;
|
||||
use crate::constants::{MAX_CONVERSATION_MESSAGE_LENGTH, MIN_CONVERSATION_MESSAGE_LENGTH};
|
||||
use crate::controllers::user_ws_controller;
|
||||
use crate::data::base_request_handler::BaseRequestHandler;
|
||||
use crate::data::conversation::{ConversationMemberSetting, NewConversationSettings};
|
||||
@ -264,8 +264,15 @@ pub fn send_message(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
};
|
||||
|
||||
// Get message, if there is no image
|
||||
let message = if let None = file {
|
||||
Some(r.post_string_without_html("message", MIN_CONVERSATION_MESSAGE_LENGTH, true)?)
|
||||
let msg = r.post_string_without_html("message", MIN_CONVERSATION_MESSAGE_LENGTH, true)?;
|
||||
|
||||
if msg.len() > MAX_CONVERSATION_MESSAGE_LENGTH {
|
||||
r.bad_request("Message is too long!".to_string())?;
|
||||
}
|
||||
|
||||
Some(msg)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@ -312,12 +319,22 @@ pub fn delete_conversation(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
/// 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)?;
|
||||
let new_content = r.post_string_opt("content", MIN_CONVERSATION_MESSAGE_LENGTH, true)?;
|
||||
|
||||
if !conversations_helper::is_message_owner(&r.user_id()?, msg_id)? {
|
||||
let msg = conversations_helper::get_single_message(msg_id)?;
|
||||
|
||||
if msg.user_id != r.user_id_opt() {
|
||||
r.forbidden("You are not the owner of this message!".to_string())?;
|
||||
}
|
||||
|
||||
if msg.file.is_some() {
|
||||
r.bad_request("Can not have both text and file in the same message!".to_string())?;
|
||||
}
|
||||
|
||||
if new_content.len() > MAX_CONVERSATION_MESSAGE_LENGTH {
|
||||
r.bad_request("New message is too long!".to_string())?;
|
||||
}
|
||||
|
||||
conversations_helper::update_message_content(msg_id, &new_content)?;
|
||||
|
||||
r.success("Conversation message content successfully updated")
|
||||
|
Reference in New Issue
Block a user