Skip to content

Commit 5193579

Browse files
committed
feat(prioritynotifications): Allow some apps to mark notifications as priority
They will be still send as push during DND. Apps are currently limited to: - twofactor_nextcloud_notification to help with login - spreed which will only set it for pushes in manually picked conversations Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 4ba3d4a commit 5193579

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

lib/private/Notification/Notification.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
use OCP\RichObjectStrings\IValidator;
1717

1818
class Notification implements INotification {
19+
/**
20+
* A very small and privileged list of apps that are allowed to push during DND.
21+
*/
22+
public const PRIORITY_NOTIFICATION_APPS = [
23+
'spreed',
24+
'twofactor_nextcloud_notification',
25+
];
26+
1927
protected string $app = '';
2028
protected string $user = '';
2129
protected \DateTime $dateTime;
@@ -33,6 +41,7 @@ class Notification implements INotification {
3341
protected array $messageRichParameters = [];
3442
protected string $link = '';
3543
protected string $icon = '';
44+
protected bool $priorityNotification = false;
3645
protected array $actions = [];
3746
protected array $actionsParsed = [];
3847
protected bool $hasPrimaryAction = false;
@@ -330,6 +339,25 @@ public function getIcon(): string {
330339
return $this->icon;
331340
}
332341

342+
/**
343+
* {@inheritDoc}
344+
*/
345+
public function setPriorityNotification(bool $priorityNotification): INotification {
346+
if ($priorityNotification && !in_array($this->getApp(), self::PRIORITY_NOTIFICATION_APPS, true)) {
347+
throw new InvalidValueException('priorityNotification');
348+
}
349+
350+
$this->priorityNotification = $priorityNotification;
351+
return $this;
352+
}
353+
354+
/**
355+
* {@inheritDoc}
356+
*/
357+
public function isPriorityNotification(): bool {
358+
return $this->priorityNotification;
359+
}
360+
333361
/**
334362
* {@inheritDoc}
335363
*/
@@ -434,6 +462,10 @@ public function isValidParsed(): bool {
434462
}
435463

436464
protected function isValidCommon(): bool {
465+
if ($this->isPriorityNotification() && !in_array($this->getApp(), self::PRIORITY_NOTIFICATION_APPS, true)) {
466+
return false;
467+
}
468+
437469
return
438470
$this->getApp() !== ''
439471
&&

lib/public/Notification/INotification.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ public function setIcon(string $icon): INotification;
263263
*/
264264
public function getIcon(): string;
265265

266+
/**
267+
* @return $this
268+
* @throws InvalidValueException if the app is not allowed to send priority notifications
269+
* @since 31.0.0
270+
*/
271+
public function setPriorityNotification(bool $priorityNotification): INotification;
272+
273+
/**
274+
* @since 31.0.0
275+
*/
276+
public function isPriorityNotification(): bool;
277+
266278
/**
267279
* @return IAction
268280
* @since 9.0.0

0 commit comments

Comments
 (0)