diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-09-23 16:10:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-23 16:10:25 +0200 |
commit | 643e216a2523fb2e32b85a6f680fe7441a4e848e (patch) | |
tree | 4b405f4c738f6a237685e9edd15a6f79c1250f79 /lib | |
parent | 40b404c5665529ebd661ab032efe24d40ab12df6 (diff) | |
parent | 5193579e4f085fc8837a641522ed02570b9b02da (diff) | |
download | nextcloud-server-643e216a2523fb2e32b85a6f680fe7441a4e848e.tar.gz nextcloud-server-643e216a2523fb2e32b85a6f680fe7441a4e848e.zip |
Merge pull request #48274 from nextcloud/feat/noid/priority-notifications
feat(prioritynotifications): Allow some apps to mark notifications as priority
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Notification/Notification.php | 32 | ||||
-rw-r--r-- | lib/public/Notification/INotification.php | 12 |
2 files changed, 44 insertions, 0 deletions
diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php index 1c624b50d44..f8f1e247854 100644 --- a/lib/private/Notification/Notification.php +++ b/lib/private/Notification/Notification.php @@ -16,6 +16,14 @@ use OCP\RichObjectStrings\IRichTextFormatter; use OCP\RichObjectStrings\IValidator; class Notification implements INotification { + /** + * A very small and privileged list of apps that are allowed to push during DND. + */ + public const PRIORITY_NOTIFICATION_APPS = [ + 'spreed', + 'twofactor_nextcloud_notification', + ]; + protected string $app = ''; protected string $user = ''; protected \DateTime $dateTime; @@ -33,6 +41,7 @@ class Notification implements INotification { protected array $messageRichParameters = []; protected string $link = ''; protected string $icon = ''; + protected bool $priorityNotification = false; protected array $actions = []; protected array $actionsParsed = []; protected bool $hasPrimaryAction = false; @@ -333,6 +342,25 @@ class Notification implements INotification { /** * {@inheritDoc} */ + public function setPriorityNotification(bool $priorityNotification): INotification { + if ($priorityNotification && !in_array($this->getApp(), self::PRIORITY_NOTIFICATION_APPS, true)) { + throw new InvalidValueException('priorityNotification'); + } + + $this->priorityNotification = $priorityNotification; + return $this; + } + + /** + * {@inheritDoc} + */ + public function isPriorityNotification(): bool { + return $this->priorityNotification; + } + + /** + * {@inheritDoc} + */ public function createAction(): IAction { return new Action(); } @@ -434,6 +462,10 @@ class Notification implements INotification { } protected function isValidCommon(): bool { + if ($this->isPriorityNotification() && !in_array($this->getApp(), self::PRIORITY_NOTIFICATION_APPS, true)) { + return false; + } + return $this->getApp() !== '' && diff --git a/lib/public/Notification/INotification.php b/lib/public/Notification/INotification.php index 4a35ee59087..6083cca4f9a 100644 --- a/lib/public/Notification/INotification.php +++ b/lib/public/Notification/INotification.php @@ -264,6 +264,18 @@ interface INotification { public function getIcon(): string; /** + * @return $this + * @throws InvalidValueException if the app is not allowed to send priority notifications + * @since 31.0.0 + */ + public function setPriorityNotification(bool $priorityNotification): INotification; + + /** + * @since 31.0.0 + */ + public function isPriorityNotification(): bool; + + /** * @return IAction * @since 9.0.0 */ |