-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotifier.php
More file actions
66 lines (53 loc) · 1.96 KB
/
Notifier.php
File metadata and controls
66 lines (53 loc) · 1.96 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
<?php
/**
* SPDX-FileCopyrightText: 2026 LibreCode coop and LibreCode contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
declare(strict_types=1);
namespace OCA\ProfileFields\Notification;
use OCA\ProfileFields\AppInfo\Application;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCP\Notification\UnknownNotificationException;
class Notifier implements INotifier {
public function __construct(
private IFactory $factory,
private IURLGenerator $urlGenerator,
) {
}
#[\Override]
public function getID(): string {
return Application::APP_ID;
}
#[\Override]
public function getName(): string {
return $this->factory->get(Application::APP_ID)->t('Profile fields');
}
#[\Override]
public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== Application::APP_ID) {
throw new UnknownNotificationException();
}
$l10n = $this->factory->get(Application::APP_ID, $languageCode);
if ($notification->getSubject() === 'profile_field_updated') {
$notification->setParsedSubject($l10n->t('Profile field updated'));
} elseif ($notification->getParsedSubject() === '') {
$notification->setParsedSubject($notification->getSubject());
}
if ($notification->getMessage() === 'profile_field_updated_message') {
// TRANSLATORS %1$s is the actor user ID, %2$s is the affected user ID, %3$s is the profile field label.
$notification->setParsedMessage($l10n->t(
'%1$s changed profile field "%3$s" for user %2$s.',
$notification->getMessageParameters(),
));
} elseif ($notification->getMessage() !== '' && $notification->getParsedMessage() === '') {
$notification->setParsedMessage($notification->getMessage());
}
if ($notification->getIcon() === '') {
$notification->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath(Application::APP_ID, 'app.svg')));
}
return $notification;
}
}