Skip to content

Commit

Permalink
Add the file to the notification subject
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen authored and danxuliu committed Nov 8, 2018
1 parent e13571f commit 86f25fb
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,23 +464,42 @@ protected function parsePasswordRequest(INotification $notification, Room $room,
throw new \InvalidArgumentException('Unknown share');
}

try {
$segments = explode('/', $share->getNode()->getPath(), 4);
if (!isset($segments[3])) {
throw new \OCP\Files\NotFoundException('File not in /user/files/');
}
$file = [
'type' => 'file',
'id' => $share->getNodeId(),
'name' => $share->getNode()->getName(),
'path' => $segments[3],
'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNodeId()]),
];
} catch (\OCP\Files\NotFoundException $e) {
throw new \InvalidArgumentException('Unknown file');
}

if ($share->getShareType() === Share::SHARE_TYPE_EMAIL) {
$sharedWith = $share->getSharedWith();

$notification
->setParsedSubject(str_replace('{email}', $sharedWith, $l->t('{email} requested the password to access a share')))
->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 a share'), [
$l->t('{email} requested the password to access {file}'),
[
'email' => [
'type' => 'email',
'id' => $sharedWith,
'name' => $sharedWith,
]
],
'file' => $file,
]
);
} else {
$notification
->setParsedSubject($l->t('Someone requested the password to access a share'));
->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]);
}

return $notification;
Expand Down

0 comments on commit 86f25fb

Please sign in to comment.