diff --git a/lang/en/message.php b/lang/en/message.php index 2691e989842..3d7f5a8a33d 100644 --- a/lang/en/message.php +++ b/lang/en/message.php @@ -44,6 +44,7 @@ $string['editmessages'] = 'Edit messages'; $string['emailtagline'] = 'This is a copy of a message sent to you at "{$a->sitename}". Go to {$a->url} to reply.'; $string['enabled'] = 'Enabled'; $string['errorcallingprocessor'] = 'Error calling defined output'; +$string['errormessagetoolong'] = 'The message is longer than the maximum allowed.'; $string['errortranslatingdefault'] = 'Error translating default setting provided by plugin, using system defaults instead.'; $string['eventnotificationviewed'] = 'Notification viewed'; $string['eventnotificationsent'] = 'Notification sent'; diff --git a/message/classes/api.php b/message/classes/api.php index 25246a0c7c0..bad2477c79f 100644 --- a/message/classes/api.php +++ b/message/classes/api.php @@ -46,6 +46,11 @@ class api { */ const MESSAGE_ACTION_DELETED = 2; + /** + * The max message length. + */ + const MESSAGE_MAX_LENGTH = 4096; + /** * Handles searching for messages in the message area. * diff --git a/message/externallib.php b/message/externallib.php index eed848ddd14..e5cd57365ed 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -126,6 +126,12 @@ class core_message_external extends external_api { $errormessage = get_string('touserdoesntexist', 'message', $message['touserid']); } + // Check message length. + if ($success && strlen($message['text']) > \core_message\api::MESSAGE_MAX_LENGTH) { + $success = false; + $errormessage = get_string('errormessagetoolong', 'message'); + } + //check that the touser is not blocking the current user if ($success and !empty($blocklist[$message['touserid']]) and !$canreadallmessages) { $success = false; diff --git a/message/templates/message_area_response.mustache b/message/templates/message_area_response.mustache index de3cfb6b914..5bcbd7369c4 100644 --- a/message/templates/message_area_response.mustache +++ b/message/templates/message_area_response.mustache @@ -22,7 +22,8 @@ data-max-rows="5" role="textbox" aria-label="{{#str}} writeamessage, message {{/str}}" - placeholder="{{#str}} writeamessage, message {{/str}}"> + placeholder="{{#str}} writeamessage, message {{/str}}" + maxlength="4096">