зеркало из https://github.com/nextcloud/spreed.git
Adjust the text of past-notifications and add actions
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Родитель
c3c735e7ed
Коммит
771bb4ec53
|
@ -38,6 +38,7 @@ use OCP\IUser;
|
|||
use OCP\IUserManager;
|
||||
use OCP\L10N\IFactory;
|
||||
use OCP\Notification\AlreadyProcessedException;
|
||||
use OCP\Notification\IAction;
|
||||
use OCP\Notification\IManager as INotificationManager;
|
||||
use OCP\Notification\INotification;
|
||||
use OCP\Notification\INotifier;
|
||||
|
@ -311,6 +312,7 @@ class Notifier implements INotifier {
|
|||
* @param IL10N $l
|
||||
* @return INotification
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws AlreadyProcessedException
|
||||
*/
|
||||
protected function parseInvitation(INotification $notification, Room $room, IL10N $l): INotification {
|
||||
if ($notification->getObjectType() !== 'room') {
|
||||
|
@ -322,17 +324,20 @@ class Notifier implements INotifier {
|
|||
|
||||
$user = $this->userManager->get($uid);
|
||||
if (!$user instanceof IUser) {
|
||||
throw new \InvalidArgumentException('Calling user does not exist anymore');
|
||||
throw new AlreadyProcessedException();
|
||||
}
|
||||
|
||||
$roomName = $room->getDisplayName($notification->getUser());
|
||||
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
|
||||
$subject = $l->t('{user} invited you to a private conversation');
|
||||
if ($room->hasSessionsInCall()) {
|
||||
$notification = $this->addActionButton($notification, $l->t('Join call'));
|
||||
}
|
||||
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
$l->t('%s invited you to a private conversation', [$user->getDisplayName()])
|
||||
)
|
||||
->setParsedSubject(str_replace('{user}', $user->getDisplayName(), $subject))
|
||||
->setRichSubject(
|
||||
$l->t('{user} invited you to a private conversation'), [
|
||||
$subject, [
|
||||
'user' => [
|
||||
'type' => 'user',
|
||||
'id' => $uid,
|
||||
|
@ -348,12 +353,15 @@ class Notifier implements INotifier {
|
|||
);
|
||||
|
||||
} else if (\in_array($room->getType(), [Room::GROUP_CALL, Room::PUBLIC_CALL], true)) {
|
||||
$subject = $l->t('{user} invited you to a group conversation: {call}');
|
||||
if ($room->hasSessionsInCall()) {
|
||||
$notification = $this->addActionButton($notification, $l->t('Join call'));
|
||||
}
|
||||
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
$l->t('%s invited you to a group conversation: %s', [$user->getDisplayName(), $roomName])
|
||||
)
|
||||
->setParsedSubject(str_replace(['{user}', '{call}'], [$user->getDisplayName(), $roomName], $subject))
|
||||
->setRichSubject(
|
||||
$l->t('{user} invited you to a group conversation: {call}'), [
|
||||
$subject, [
|
||||
'user' => [
|
||||
'type' => 'user',
|
||||
'id' => $uid,
|
||||
|
@ -368,7 +376,7 @@ class Notifier implements INotifier {
|
|||
]
|
||||
);
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Unknown room type');
|
||||
throw new AlreadyProcessedException();
|
||||
}
|
||||
|
||||
return $notification;
|
||||
|
@ -380,6 +388,7 @@ class Notifier implements INotifier {
|
|||
* @param IL10N $l
|
||||
* @return INotification
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws AlreadyProcessedException
|
||||
*/
|
||||
protected function parseCall(INotification $notification, Room $room, IL10N $l): INotification {
|
||||
if ($notification->getObjectType() !== 'call') {
|
||||
|
@ -392,12 +401,17 @@ class Notifier implements INotifier {
|
|||
$calleeId = $parameters['callee'];
|
||||
$user = $this->userManager->get($calleeId);
|
||||
if ($user instanceof IUser) {
|
||||
if ($room->hasSessionsInCall()) {
|
||||
$notification = $this->addActionButton($notification, $l->t('Answer call'));
|
||||
$subject = $l->t('{user} wants to talk with you');
|
||||
} else {
|
||||
$subject = $l->t('You missed a call from {user}');
|
||||
}
|
||||
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
str_replace('{user}', $user->getDisplayName(), $l->t('{user} wants to talk with you'))
|
||||
)
|
||||
->setParsedSubject(str_replace('{user}', $user->getDisplayName(), $subject))
|
||||
->setRichSubject(
|
||||
$l->t('{user} wants to talk with you'), [
|
||||
$subject, [
|
||||
'user' => [
|
||||
'type' => 'user',
|
||||
'id' => $calleeId,
|
||||
|
@ -412,16 +426,21 @@ class Notifier implements INotifier {
|
|||
]
|
||||
);
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Calling user does not exist anymore');
|
||||
throw new AlreadyProcessedException();
|
||||
}
|
||||
|
||||
} else if (\in_array($room->getType(), [Room::GROUP_CALL, Room::PUBLIC_CALL], true)) {
|
||||
if ($room->hasSessionsInCall()) {
|
||||
$notification = $this->addActionButton($notification, $l->t('Join call'));
|
||||
$subject = $l->t('A group call has started in {call}');
|
||||
} else {
|
||||
$subject = $l->t('You missed a group call in {call}');
|
||||
}
|
||||
|
||||
$notification
|
||||
->setParsedSubject(
|
||||
str_replace('{call}', $roomName, $l->t('A group call has started in {call}'))
|
||||
)
|
||||
->setParsedSubject(str_replace('{call}', $roomName, $subject))
|
||||
->setRichSubject(
|
||||
$l->t('A group call has started in {call}'), [
|
||||
$subject, [
|
||||
'call' => [
|
||||
'type' => 'call',
|
||||
'id' => $room->getId(),
|
||||
|
@ -432,7 +451,7 @@ class Notifier implements INotifier {
|
|||
);
|
||||
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Unknown room type');
|
||||
throw new AlreadyProcessedException();
|
||||
}
|
||||
|
||||
return $notification;
|
||||
|
@ -444,6 +463,7 @@ class Notifier implements INotifier {
|
|||
* @param IL10N $l
|
||||
* @return INotification
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws AlreadyProcessedException
|
||||
*/
|
||||
protected function parsePasswordRequest(INotification $notification, Room $room, IL10N $l): INotification {
|
||||
if ($notification->getObjectType() !== 'call') {
|
||||
|
@ -453,7 +473,7 @@ class Notifier implements INotifier {
|
|||
try {
|
||||
$share = $this->shareManager->getShareByToken($room->getObjectId());
|
||||
} catch (ShareNotFound $e) {
|
||||
throw new \InvalidArgumentException('Unknown share');
|
||||
throw new AlreadyProcessedException();
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -463,17 +483,25 @@ class Notifier implements INotifier {
|
|||
'name' => $share->getNode()->getName(),
|
||||
];
|
||||
} catch (\OCP\Files\NotFoundException $e) {
|
||||
throw new \InvalidArgumentException('Unknown file');
|
||||
throw new AlreadyProcessedException();
|
||||
}
|
||||
|
||||
$callIsActive = $room->hasSessionsInCall();
|
||||
if ($callIsActive) {
|
||||
$notification = $this->addActionButton($notification, $l->t('Answer call'));
|
||||
}
|
||||
|
||||
if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
|
||||
$sharedWith = $share->getSharedWith();
|
||||
if ($callIsActive) {
|
||||
$subject = $l->t('{email} is requesting the password to access {file}');
|
||||
} else {
|
||||
$subject = $l->t('{email} tried to requested the password to access {file}');
|
||||
}
|
||||
|
||||
$notification
|
||||
->setParsedSubject(str_replace(['{email}', '{file}'], [$sharedWith, $file['name']], $l->t('{email} requested the password to access {file}')))
|
||||
->setRichSubject(
|
||||
$l->t('{email} requested the password to access {file}'),
|
||||
[
|
||||
->setParsedSubject(str_replace(['{email}', '{file}'], [$sharedWith, $file['name']], $subject))
|
||||
->setRichSubject($subject, [
|
||||
'email' => [
|
||||
'type' => 'email',
|
||||
'id' => $sharedWith,
|
||||
|
@ -483,11 +511,31 @@ class Notifier implements INotifier {
|
|||
]
|
||||
);
|
||||
} else {
|
||||
$notification
|
||||
->setParsedSubject(str_replace('{file}', $file['name'], $l->t('Someone requested the password to access {file}')))
|
||||
->setRichSubject($l->t('Someone requested the password to access {file}'), ['file' => $file]);
|
||||
if ($callIsActive) {
|
||||
$subject = $l->t('Someone is requesting the password to access {file}');
|
||||
} else {
|
||||
$subject = $l->t('Someone tried to requested the password to access {file}');
|
||||
}
|
||||
|
||||
$notification
|
||||
->setParsedSubject(str_replace('{file}', $file['name'], $subject))
|
||||
->setRichSubject($subject, ['file' => $file]);
|
||||
}
|
||||
|
||||
$notification = $this->addActionButton($notification, $l->t('Answer call'));
|
||||
|
||||
return $notification;
|
||||
}
|
||||
|
||||
protected function addActionButton(INotification $notification, string $label): INotification {
|
||||
$action = $notification->createAction();
|
||||
$action->setLabel($label)
|
||||
->setParsedLabel($label)
|
||||
->setLink($notification->getLink(), IAction::TYPE_WEB)
|
||||
->setPrimary(true);
|
||||
|
||||
$notification->addParsedAction($action);
|
||||
|
||||
return $notification;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -712,7 +712,7 @@ class NotifierTest extends \Test\TestCase {
|
|||
'Invalid room' => [AlreadyProcessedException::class, 'spreed', false, false, null, null, null],
|
||||
['Unknown subject', 'spreed', false, true, 'invalid-subject', null, null],
|
||||
['Unknown object type', 'spreed', false, true, 'invitation', null, 'invalid-object-type'],
|
||||
['Calling user does not exist anymore', 'spreed', false, true, 'invitation', ['admin'], 'room'],
|
||||
'Calling user does not exist anymore' => [AlreadyProcessedException::class, 'spreed', false, true, 'invitation', ['admin'], 'room'],
|
||||
['Unknown object type', 'spreed', false, true, 'mention', null, 'invalid-object-type'],
|
||||
];
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче