Skip to content

Commit

Permalink
Merge pull request #12112 from nextcloud/bugfix/noid/update-notificat…
Browse files Browse the repository at this point in the history
…ion-handling

fix(notifications): Update the notification handling
  • Loading branch information
nickvergessen authored Apr 15, 2024
2 parents 0a09e11 + 02f2d82 commit a59363e
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
use OCP\Notification\UnknownNotificationException;
use OCP\RichObjectStrings\Definitions;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as IShareManager;
Expand Down Expand Up @@ -189,12 +190,13 @@ protected function getParticipant(Room $room, string $userId): Participant {
* @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
* @throws AlreadyProcessedException
* @throws UnknownNotificationException
* @since 9.0.0
*/
public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== Application::APP_ID) {
throw new \InvalidArgumentException('Incorrect app');
throw new UnknownNotificationException('Incorrect app');
}

$userId = $notification->getUser();
Expand Down Expand Up @@ -278,7 +280,7 @@ public function prepare(INotification $notification, string $languageCode): INot
}

$this->notificationManager->markProcessed($notification);
throw new \InvalidArgumentException('Unknown subject');
throw new UnknownNotificationException('Unknown subject');
}

protected function shortenJsonEncodedMultibyteSave(string $subject, int $dataLength): string {
Expand Down Expand Up @@ -471,11 +473,11 @@ protected function parseRemoteInvitationMessage(INotification $notification, IL1
* @param IL10N $l
* @return INotification
* @throws AlreadyProcessedException
* @throws \InvalidArgumentException
* @throws UnknownNotificationException
*/
protected function parseChatMessage(INotification $notification, Room $room, Participant $participant, IL10N $l): INotification {
if ($notification->getObjectType() !== 'chat' && $notification->getObjectType() !== 'reminder') {
throw new \InvalidArgumentException('Unknown object type');
throw new UnknownNotificationException('Unknown object type');
}

$messageParameters = $notification->getMessageParameters();
Expand Down Expand Up @@ -911,12 +913,12 @@ protected function getRoomType(Room $room): string {
* @param Room $room
* @param IL10N $l
* @return INotification
* @throws \InvalidArgumentException
* @throws AlreadyProcessedException
* @throws UnknownNotificationException
*/
protected function parseInvitation(INotification $notification, Room $room, IL10N $l): INotification {
if ($notification->getObjectType() !== 'room') {
throw new \InvalidArgumentException('Unknown object type');
throw new UnknownNotificationException('Unknown object type');
}

$parameters = $notification->getSubjectParameters();
Expand Down Expand Up @@ -992,12 +994,12 @@ protected function parseInvitation(INotification $notification, Room $room, IL10
* @param Room $room
* @param IL10N $l
* @return INotification
* @throws \InvalidArgumentException
* @throws AlreadyProcessedException
* @throws UnknownNotificationException
*/
protected function parseCall(INotification $notification, Room $room, IL10N $l): INotification {
if ($notification->getObjectType() !== 'call') {
throw new \InvalidArgumentException('Unknown object type');
throw new UnknownNotificationException('Unknown object type');
}

$roomName = $room->getDisplayName($notification->getUser());
Expand Down Expand Up @@ -1069,12 +1071,12 @@ protected function parseCall(INotification $notification, Room $room, IL10N $l):
* @param Room $room
* @param IL10N $l
* @return INotification
* @throws \InvalidArgumentException
* @throws AlreadyProcessedException
* @throws UnknownNotificationException
*/
protected function parsePasswordRequest(INotification $notification, Room $room, IL10N $l): INotification {
if ($notification->getObjectType() !== 'call') {
throw new \InvalidArgumentException('Unknown object type');
throw new UnknownNotificationException('Unknown object type');
}

try {
Expand Down Expand Up @@ -1151,6 +1153,9 @@ protected function addActionButton(INotification $notification, string $labelKey
return $notification;
}

/**
* @throws UnknownNotificationException
*/
protected function parseHostedSignalingServer(INotification $notification, IL10N $l): INotification {
$action = $notification->createAction();
$action->setLabel('open_settings')
Expand Down Expand Up @@ -1183,7 +1188,7 @@ protected function parseHostedSignalingServer(INotification $notification, IL10N
];
break;
default:
throw new \InvalidArgumentException('Unknown subject');
throw new UnknownNotificationException('Unknown subject');
}

return $notification
Expand Down

0 comments on commit a59363e

Please sign in to comment.