-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathNotifier.php
More file actions
82 lines (71 loc) · 2.27 KB
/
Notifier.php
File metadata and controls
82 lines (71 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Nextcloud - google
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Julien Veyssier <eneiluj@posteo.net>
* @copyright Julien Veyssier 2020
*/
namespace OCA\Google\Notification;
use InvalidArgumentException;
use OCA\Google\AppInfo\Application;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
class Notifier implements INotifier {
public function __construct(
private IFactory $factory,
private IURLGenerator $url,
) {
}
/**
* Identifier of the notifier, only use [a-z0-9_]
*
* @return string
* @since 17.0.0
*/
public function getID(): string {
return 'integration_google';
}
/**
* Human readable name describing the notifier
*
* @return string
* @since 17.0.0
*/
public function getName(): string {
return $this->factory->get('integration_google')->t('Google');
}
/**
* @param INotification $notification
* @param string $languageCode The code of the language that should be used to prepare the notification
* @return INotification
* @throws InvalidArgumentException When the notification was not prepared by a notifier
* @since 9.0.0
*/
public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== 'integration_google') {
// Not my app => throw
throw new InvalidArgumentException();
}
$l = $this->factory->get('integration_google', $languageCode);
switch ($notification->getSubject()) {
case 'import_drive_finished':
/** @var array{nbImported?:string, targetPath: string} $p */
$p = $notification->getSubjectParameters();
$nbImported = (int)($p['nbImported'] ?? 0);
$targetPath = $p['targetPath'];
$content = $l->n('%n file was imported from Google Drive.', '%n files were imported from Google Drive.', $nbImported);
$notification->setParsedSubject($content)
->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')))
->setLink($this->url->linkToRouteAbsolute('files.view.index', ['dir' => $targetPath]));
return $notification;
default:
// Unknown subject => Unknown notification => throw
throw new InvalidArgumentException();
}
}
}