Skip to content

Commit

Permalink
fix(notification): Render the actions and remove notification on click
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Oct 12, 2023
1 parent dc46119 commit a4f26cc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
10 changes: 0 additions & 10 deletions lib/Federation/CloudFederationProviderTalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,6 @@ private function notifyAboutNewShare(IUser $shareWith, string $shareId, string $
'roomToken' => $roomToken,
]);

$declineAction = $notification->createAction();
$declineAction->setLabel('decline')
->setLink($this->urlGenerator->linkToOCSRouteAbsolute('spreed.Federation.rejectShare', ['apiVersion' => 'v1', 'id' => $shareId]), 'DELETE');
$notification->addAction($declineAction);

$acceptAction = $notification->createAction();
$acceptAction->setLabel('accept')
->setLink($this->urlGenerator->linkToOCSRouteAbsolute('spreed.Federation.acceptShare', ['apiVersion' => 'v1', 'id' => $shareId]), 'POST');
$notification->addAction($acceptAction);

$this->notificationManager->notify($notification);
}

Expand Down
14 changes: 14 additions & 0 deletions lib/Federation/FederationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IConfig;
use OCP\IUser;
use OCP\Notification\IManager;

/**
* Class FederationManager
Expand All @@ -57,6 +58,7 @@ public function __construct(
private ParticipantService $participantService,
private InvitationMapper $invitationMapper,
private BackendNotifier $backendNotifier,
private IManager $notificationManager,
) {
}

Expand Down Expand Up @@ -96,6 +98,14 @@ public function addRemoteRoom(IUser $user, string $remoteId, int $roomType, stri
return $invitation->getId();
}

protected function markNotificationProcessed(string $userId, int $shareId): void {
$notification = $this->notificationManager->createNotification();
$notification->setApp(Application::APP_ID)
->setUser($userId)
->setObject('remote_talk_share', (string) $shareId);
$this->notificationManager->markProcessed($notification);
}

/**
* @throws UnauthorizedException
* @throws DoesNotExistException
Expand Down Expand Up @@ -128,6 +138,8 @@ public function acceptRemoteRoomShare(IUser $user, int $shareId): void {
$this->participantService->addUsers($room, $participant, $user);

$this->invitationMapper->delete($invitation);

$this->markNotificationProcessed($user->getUID(), $shareId);
}

/**
Expand All @@ -151,6 +163,8 @@ public function rejectRemoteRoomShare(IUser $user, int $shareId): void {

$this->invitationMapper->delete($invitation);

$this->markNotificationProcessed($user->getUID(), $shareId);

$this->backendNotifier->sendShareDeclined($room->getRemoteServer(), $invitation->getRemoteId(), $invitation->getAccessToken());
}

Expand Down
24 changes: 20 additions & 4 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function __construct(
protected INotificationManager $notificationManager,
CommentsManager $commentManager,
protected MessageParser $messageParser,
protected IURLGenerator $urlGenerator,
protected IRootFolder $rootFolder,
protected ITimeFactory $timeFactory,
protected Definitions $definitions,
Expand Down Expand Up @@ -331,7 +330,7 @@ protected function parseStoredRecording(
->setParsedLabel($l->t('Share to chat'))
->setPrimary(true)
->setLink(
$this->urlGenerator->linkToOCSRouteAbsolute(
$this->url->linkToOCSRouteAbsolute(
'spreed.Recording.shareToChat',
[
'apiVersion' => 'v1',
Expand All @@ -345,7 +344,7 @@ protected function parseStoredRecording(
$dismissAction = $notification->createAction()
->setParsedLabel($l->t('Dismiss notification'))
->setLink(
$this->urlGenerator->linkToOCSRouteAbsolute(
$this->url->linkToOCSRouteAbsolute(
'spreed.Recording.notificationDismiss',
[
'apiVersion' => 'v1',
Expand Down Expand Up @@ -443,6 +442,23 @@ protected function parseRemoteInvitationMessage(INotification $notification, IL1
}
}

$acceptAction = $notification->createAction();
$acceptAction->setParsedLabel($l->t('Accept'));
$acceptAction->setLink($this->url->linkToOCSRouteAbsolute(
'spreed.Federation.acceptShare',
['apiVersion' => 'v1', 'id' => (int) $notification->getObjectId()]
), IAction::TYPE_POST);
$acceptAction->setPrimary(true);
$notification->addParsedAction($acceptAction);

$declineAction = $notification->createAction();
$declineAction->setParsedLabel($l->t('Decline'));
$declineAction->setLink($this->url->linkToOCSRouteAbsolute(
'spreed.Federation.rejectShare',
['apiVersion' => 'v1', 'id' => (int) $notification->getObjectId()]
), IAction::TYPE_DELETE);
$notification->addParsedAction($declineAction);

$notification->setParsedSubject(str_replace($placeholders, $replacements, $message));
$notification->setRichSubject($message, $rosParameters);

Expand Down Expand Up @@ -780,7 +796,7 @@ protected function parseChatMessage(INotification $notification, Room $room, Par
$action->setLabel($l->t('Dismiss reminder'))
->setParsedLabel($l->t('Dismiss reminder'))
->setLink(
$this->urlGenerator->linkToOCSRouteAbsolute(
$this->url->linkToOCSRouteAbsolute(
'spreed.Chat.deleteReminder',
[
'apiVersion' => 'v1',
Expand Down
4 changes: 0 additions & 4 deletions tests/php/Notification/NotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ class NotifierTest extends TestCase {
protected $commentsManager;
/** @var MessageParser|MockObject */
protected $messageParser;
/** @var IURLGenerator|MockObject */
protected $urlGenerator;
/** @var IRootFolder|MockObject */
protected $rootFolder;
/** @var ITimeFactory|MockObject */
Expand Down Expand Up @@ -115,7 +113,6 @@ public function setUp(): void {
$this->notificationManager = $this->createMock(INotificationManager::class);
$this->commentsManager = $this->createMock(CommentsManager::class);
$this->messageParser = $this->createMock(MessageParser::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->definitions = $this->createMock(Definitions::class);
Expand All @@ -137,7 +134,6 @@ public function setUp(): void {
$this->notificationManager,
$this->commentsManager,
$this->messageParser,
$this->urlGenerator,
$this->rootFolder,
$this->timeFactory,
$this->definitions,
Expand Down

0 comments on commit a4f26cc

Please sign in to comment.