Skip to content

Commit

Permalink
Merge pull request #66 from owncloud/backport-65
Browse files Browse the repository at this point in the history
[9.0] Make sure that the notification API can deliver the full message
  • Loading branch information
nickvergessen committed Mar 23, 2016
2 parents aaf4ebf + a8ed2ca commit 0c0a33c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
27 changes: 2 additions & 25 deletions lib/notificationsnotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public function prepare(INotification $notification, $languageCode) {
}

$announcement = $this->manager->getAnnouncement($notification->getObjectId(), false);
$params[] = $this->prepareMessage($announcement['subject']);
$params[] = str_replace("\n", ' ', $announcement['subject']);

$notification->setParsedMessage($this->prepareMessage($announcement['message']))
$notification->setParsedMessage($announcement['message'])
->setParsedSubject(
(string) $l->t('%1$s announced “%2$s”', $params)
);
Expand All @@ -88,27 +88,4 @@ public function prepare(INotification $notification, $languageCode) {
throw new \InvalidArgumentException();
}
}

/**
* Prepare message for notification usage
*
* + Replace line breaks with spaces
* + Trim on word end after 100 chars or hard 120 chars
*
* @param string $message
* @return string
*/
protected function prepareMessage($message) {
$message = str_replace("\n", ' ', $message);

if (isset($message[120])) {
$findSpace = strpos($message, ' ', 100);
if ($findSpace !== false && $findSpace < 120) {
return substr($message, 0, $findSpace) . '';
}
return substr($message, 0, 120) . '';
}

return $message;
}
}
5 changes: 1 addition & 4 deletions tests/lib/NotificationsNotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,11 @@ protected function getUserMock() {
}

public function dataPrepare() {
$subject = "subject\nsubject subject subject subject subject subject subject subject subject subject subject subject subject subject subject subject subject subject";
$subjectTrim = 'subject subject subject subject subject subject subject subject subject subject subject subject subject…';
$message = "message\nmessage message message message message message message message message message message messagemessagemessagemessagemessagemessagemessage";
$messageTrim = 'message message message message message message message message message message message message messagemessagemessagemes…';
return [
['author', 'subject', 'message', 42, null, 'author announced “subject”', 'message'],
['author1', 'subject', 'message', 42, $this->getUserMock(), 'Author announced “subject”', 'message'],
['author2', $subject, $message, 21, null, 'author2 announced “' . $subjectTrim . '', $messageTrim],
['author2', "subject\nsubject", $message, 21, null, 'author2 announced “subject subject', $message],
];
}

Expand Down

0 comments on commit 0c0a33c

Please sign in to comment.