summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2023-10-12 09:47:39 +0200
committerGitHub <noreply@github.com>2023-10-12 09:47:39 +0200
commita3009bbeeda07ffd56162a728ab9a947a9c9f12d (patch)
tree960d69926ed2f44f3b8aa10a6c1adb7d2c795f3f
parent9d80ef30c37a93ac5fc6c0a18f75abcf53c7212d (diff)
parenta4f26ccc40a2b808f01ecd6b4e2cc19bed8279d3 (diff)
Merge pull request #10685 from nextcloud/bugfix/5723/fix-remote-share-notifications
fix(notification): Render the actions and remove notification on click
-rw-r--r--lib/Federation/CloudFederationProviderTalk.php10
-rw-r--r--lib/Federation/FederationManager.php14
-rw-r--r--lib/Notification/Notifier.php24
-rw-r--r--tests/php/Notification/NotifierTest.php4
4 files changed, 34 insertions, 18 deletions
diff --git a/lib/Federation/CloudFederationProviderTalk.php b/lib/Federation/CloudFederationProviderTalk.php
index 7e2d6816e..6132c610b 100644
--- a/lib/Federation/CloudFederationProviderTalk.php
+++ b/lib/Federation/CloudFederationProviderTalk.php
@@ -290,16 +290,6 @@ class CloudFederationProviderTalk implements ICloudFederationProvider {
'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);
}
diff --git a/lib/Federation/FederationManager.php b/lib/Federation/FederationManager.php
index cce938d52..6f73e8008 100644
--- a/lib/Federation/FederationManager.php
+++ b/lib/Federation/FederationManager.php
@@ -38,6 +38,7 @@ use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IConfig;
use OCP\IUser;
+use OCP\Notification\IManager;
/**
* Class FederationManager
@@ -57,6 +58,7 @@ class FederationManager {
private ParticipantService $participantService,
private InvitationMapper $invitationMapper,
private BackendNotifier $backendNotifier,
+ private IManager $notificationManager,
) {
}
@@ -96,6 +98,14 @@ class FederationManager {
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
@@ -128,6 +138,8 @@ class FederationManager {
$this->participantService->addUsers($room, $participant, $user);
$this->invitationMapper->delete($invitation);
+
+ $this->markNotificationProcessed($user->getUID(), $shareId);
}
/**
@@ -151,6 +163,8 @@ class FederationManager {
$this->invitationMapper->delete($invitation);
+ $this->markNotificationProcessed($user->getUID(), $shareId);
+
$this->backendNotifier->sendShareDeclined($room->getRemoteServer(), $invitation->getRemoteId(), $invitation->getAccessToken());
}
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index 2595b1bc7..ba36f16a0 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -84,7 +84,6 @@ class Notifier implements INotifier {
protected INotificationManager $notificationManager,
CommentsManager $commentManager,
protected MessageParser $messageParser,
- protected IURLGenerator $urlGenerator,
protected IRootFolder $rootFolder,
protected ITimeFactory $timeFactory,
protected Definitions $definitions,
@@ -331,7 +330,7 @@ class Notifier implements INotifier {
->setParsedLabel($l->t('Share to chat'))
->setPrimary(true)
->setLink(
- $this->urlGenerator->linkToOCSRouteAbsolute(
+ $this->url->linkToOCSRouteAbsolute(
'spreed.Recording.shareToChat',
[
'apiVersion' => 'v1',
@@ -345,7 +344,7 @@ class Notifier implements INotifier {
$dismissAction = $notification->createAction()
->setParsedLabel($l->t('Dismiss notification'))
->setLink(
- $this->urlGenerator->linkToOCSRouteAbsolute(
+ $this->url->linkToOCSRouteAbsolute(
'spreed.Recording.notificationDismiss',
[
'apiVersion' => 'v1',
@@ -443,6 +442,23 @@ class Notifier implements INotifier {
}
}
+ $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);
@@ -780,7 +796,7 @@ class Notifier implements INotifier {
$action->setLabel($l->t('Dismiss reminder'))
->setParsedLabel($l->t('Dismiss reminder'))
->setLink(
- $this->urlGenerator->linkToOCSRouteAbsolute(
+ $this->url->linkToOCSRouteAbsolute(
'spreed.Chat.deleteReminder',
[
'apiVersion' => 'v1',
diff --git a/tests/php/Notification/NotifierTest.php b/tests/php/Notification/NotifierTest.php
index be589b3df..7f2b362d4 100644
--- a/tests/php/Notification/NotifierTest.php
+++ b/tests/php/Notification/NotifierTest.php
@@ -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 */
@@ -115,7 +113,6 @@ class NotifierTest extends TestCase {
$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);
@@ -137,7 +134,6 @@ class NotifierTest extends TestCase {
$this->notificationManager,
$this->commentsManager,
$this->messageParser,
- $this->urlGenerator,
$this->rootFolder,
$this->timeFactory,
$this->definitions,