Merge pull request #16088 from nextcloud/bugfix/noid/allow-longer-comments-to-be-stored-in-the-comments-api

Allow apps to store longer messages in the comments API
This commit is contained in:
Joas Schilling 2019-06-27 10:04:19 +02:00 committed by GitHub
commit 0d3f9be56e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

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

View File

@ -127,11 +127,12 @@ interface IComment {
* MessageTooLongException shall be thrown. * MessageTooLongException shall be thrown.
* *
* @param string $message * @param string $message
* @param int $maxLength
* @return IComment * @return IComment
* @throws MessageTooLongException * @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 * returns an array containing mentions that are included in the comment