Allow apps to store longer messages in the comments API

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/16088/head
Joas Schilling 5 years ago
parent bc276cdd83
commit d2c8a11c07
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
  1. 7
      lib/private/Comments/Comment.php
  2. 5
      lib/public/Comments/IComment.php

@ -188,17 +188,18 @@ class Comment implements IComment {
* sets the message of the comment and returns itself
*
* @param string $message
* @param int $maxLength
* @return IComment
* @throws MessageTooLongException
* @since 9.0.0
*/
public function setMessage($message) {
public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH) {
if(!is_string($message)) {
throw new \InvalidArgumentException('String expected.');
}
$message = trim($message);
if(mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) {
throw new MessageTooLongException('Comment message must not exceed ' . IComment::MAX_MESSAGE_LENGTH . ' characters');
if ($maxLength && mb_strlen($message, 'UTF-8') > $maxLength) {
throw new MessageTooLongException('Comment message must not exceed ' . $maxLength. ' characters');
}
$this->data['message'] = $message;
return $this;

@ -127,11 +127,12 @@ interface IComment {
* MessageTooLongException shall be thrown.
*
* @param string $message
* @param int $maxLength
* @return IComment
* @throws MessageTooLongException
* @since 9.0.0
* @since 9.0.0 - $maxLength added in 16.0.2
*/
public function setMessage($message);
public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH);
/**
* returns an array containing mentions that are included in the comment

Loading…
Cancel
Save