diff options
author | Joas Schilling <coding@schilljs.com> | 2018-10-08 18:15:51 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2018-10-08 18:15:51 +0300 |
commit | 947cc2b4c449002979bec33c0800878a10dd3227 (patch) | |
tree | 833ed2afd3206f0161b2ec6e07db35c3496c5416 /lib/Notification/Notifier.php | |
parent | 6790f90796ef573e419c55aa55e21b3ae636f788 (diff) |
Fix subject when notified about ordinary chat message
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification/Notifier.php')
-rw-r--r-- | lib/Notification/Notifier.php | 136 |
1 files changed, 54 insertions, 82 deletions
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 35a07aa25..9d5a36dbd 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -189,96 +189,68 @@ class Notifier implements INotifier { $notification->setParsedMessage(str_replace($placeholders, $replacements, $richMessage)); $notification->setRichMessage($richMessage, $richMessageParameters); - if ($notification->getSubject() === 'chat') { - $notification - ->setParsedSubject(str_replace('{user}', $user->getDisplayName(), $l->t('{user} sent you a private message'))) - ->setRichSubject( - $l->t('{user} sent you a private message'), [ - 'user' => $richSubjectUser, - 'call' => $richSubjectCall, - ] - ); + $richSubjectParameters = [ + 'user' => $richSubjectUser, + 'call' => $richSubjectCall, + ]; + if ($notification->getSubject() === 'chat') { + if ($room->getType() === Room::ONE_TO_ONE_CALL) { + $subject = $l->t('{user} sent you a private message'); + } else { + if ($richSubjectUser) { + if ($room->getName() !== '') { + $subject = $l->t('{user} sent a message in conversation {call}'); + } else { + $subject = $l->t('{user} sent a message in a conversation'); + } + } else if (!$isGuest) { + if ($room->getName() !== '') { + $subject = $l->t('A deleted user sent a message in conversation {call}'); + } else { + $subject = $l->t('A deleted user sent a message in a conversation'); + } + } else if ($room->getName() !== '') { + $subject = $l->t('A guest sent a message in conversation {call}'); + } else { + $subject = $l->t('A guest sent a message in a conversation'); + } + } } else if ($room->getType() === Room::ONE_TO_ONE_CALL) { - $notification - ->setParsedSubject( - $l->t('%s mentioned you in a private conversation', [$user->getDisplayName()]) - ) - ->setRichSubject( - $l->t('{user} mentioned you in a private conversation'), [ - 'user' => $richSubjectUser, - 'call' => $richSubjectCall, - ] - ); - - } else if (\in_array($room->getType(), [Room::GROUP_CALL, Room::PUBLIC_CALL], true)) { - if ($richSubjectUser && $room->getName() !== '') { - $notification - ->setParsedSubject( - $l->t('%s mentioned you in a group conversation: %s', [$user->getDisplayName(), $room->getName()]) - ) - ->setRichSubject( - $l->t('{user} mentioned you in a group conversation: {call}'), [ - 'user' => $richSubjectUser, - 'call' => $richSubjectCall, - ] - ); - } else if ($richSubjectUser) { - $notification - ->setParsedSubject( - $l->t('%s mentioned you in a group conversation', [$user->getDisplayName()]) - ) - ->setRichSubject( - $l->t('{user} mentioned you in a group conversation'), [ - 'user' => $richSubjectUser, - 'call' => $richSubjectCall, - ] - ); - } else if (!$isGuest && $room->getName() !== '') { - $notification - ->setParsedSubject( - $l->t('You were mentioned in a group conversation by a deleted user: %s', [$room->getName()]) - ) - ->setRichSubject( - $l->t('You were mentioned in a group conversation by a deleted user: {call}'), [ - 'call' => $richSubjectCall, - ] - ); + $subject = $l->t('{user} mentioned you in a private conversation'); + } else { + if ($richSubjectUser) { + if ($room->getName() !== '') { + $subject = $l->t('{user} mentioned you in conversation {call}'); + } else { + $subject = $l->t('{user} mentioned you in a conversation'); + } } else if (!$isGuest) { - $notification - ->setParsedSubject( - $l->t('You were mentioned in a group conversation by a deleted user') - ) - ->setRichSubject( - $l->t('You were mentioned in a group conversation by a deleted user'), [ - 'call' => $richSubjectCall, - ] - ); + if ($room->getName() !== '') { + $subject = $l->t('A deleted user mentioned you in conversation {call}'); + } else { + $subject = $l->t('A deleted user mentioned you in a conversation'); + } } else if ($room->getName() !== '') { - $notification - ->setParsedSubject( - $l->t('A guest mentioned you in a group conversation: %s', [$room->getName()]) - ) - ->setRichSubject( - $l->t('A guest mentioned you in a group conversation: {call}'), [ - 'call' => $richSubjectCall, - ] - ); + $subject = $l->t('A guest mentioned you in conversation {call}'); } else { - $notification - ->setParsedSubject( - $l->t('A guest mentioned you in a group conversation') - ) - ->setRichSubject( - $l->t('A guest mentioned you in a group conversation'), [ - 'call' => $richSubjectCall, - ] - ); + $subject = $l->t('A guest mentioned you in a conversation'); } - } else { - throw new \InvalidArgumentException('Unknown room type'); } + if ($richSubjectParameters['user'] === null) { + unset($richSubjectParameters['user']); + } + + $placeholders = $replacements = []; + foreach ($richSubjectParameters as $placeholder => $parameter) { + $placeholders[] = '{' . $placeholder . '}'; + $replacements[] = $parameter['name']; + } + + $notification->setParsedSubject(str_replace($placeholders, $replacements, $subject)) + ->setRichSubject($subject, $richSubjectParameters); + return $notification; } |