mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 00:32:29 -04:00
Merge pull request #48274 from nextcloud/feat/noid/priority-notifications
feat(prioritynotifications): Allow some apps to mark notifications as priority
This commit is contained in:
commit
643e216a25
2 changed files with 44 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
@ -330,6 +339,25 @@ class Notification implements INotification {
|
|||
return $this->icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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}
|
||||
*/
|
||||
|
|
@ -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() !== ''
|
||||
&&
|
||||
|
|
|
|||
|
|
@ -263,6 +263,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue