diff options
author | Joas Schilling <coding@schilljs.com> | 2020-06-26 10:35:04 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-06-26 10:35:04 +0300 |
commit | 5900f65ac76c767b541a8004ce332028eff71a55 (patch) | |
tree | cc1db49e5700671d9e0d195237c226f9c1eb7bca /lib/Notification | |
parent | 3d78b4e18d8f28bdaac8fdd40a6082667b12035b (diff) |
Circumvent long messages breaking the activity app by accident
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification')
-rw-r--r-- | lib/Notification/Notifier.php | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 1ba377184..c3113e413 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -248,6 +248,14 @@ class Notifier implements INotifier { throw new \InvalidArgumentException('Unknown subject'); } + protected function shortenJsonEncodedMultibyteSave(string $subject, int $dataLength): string { + $temp = mb_substr($subject, 0, $dataLength); + while (strlen(json_encode($temp)) > $dataLength) { + $temp = mb_substr($temp, 0, -5); + } + return $temp; + } + /** * @param INotification $notification * @param Room $room @@ -327,10 +335,14 @@ class Notifier implements INotifier { ]; if ($this->notificationManager->isPreparingPushNotification()) { + $shortenMessage = $this->shortenJsonEncodedMultibyteSave($parsedMessage, 100); + if ($shortenMessage !== $parsedMessage) { + $shortenMessage .= '…'; + } $richSubjectParameters['message'] = [ 'type' => 'highlight', 'id' => $message->getComment()->getId(), - 'name' => $parsedMessage, + 'name' => $shortenMessage, ]; if ($room->getType() === Room::ONE_TO_ONE_CALL) { $subject = $l->t('{user}: {message}'); |