Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2020-07-28 15:43:41 +0300
committerGitHub <noreply@github.com>2020-07-28 15:43:41 +0300
commit51dc317f43af93215ba8a626bf5fc3be4f9ce1d7 (patch)
tree4572a46897a834c9214eb7c89de7fcad201dad1b /lib
parenta44671aef1f0d9407a91c9f0349bc538b8f51b2f (diff)
parentb8503d0196922a59d26a5794df244e48ecbcde44 (diff)
Merge pull request #3743 from nextcloud/techdebt/noid/deferrable-notification-apps
Defer sending the notifications when we interact multiple times
Diffstat (limited to 'lib')
-rw-r--r--lib/Chat/ChatManager.php7
-rw-r--r--lib/Chat/Notifier.php14
-rw-r--r--lib/Controller/PageController.php5
-rw-r--r--lib/Notification/Listener.php21
4 files changed, 42 insertions, 5 deletions
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php
index 26d24ba4c..080c364f5 100644
--- a/lib/Chat/ChatManager.php
+++ b/lib/Chat/ChatManager.php
@@ -34,6 +34,7 @@ use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
+use OCP\Notification\IManager as INotificationManager;
/**
* Basic polling chat manager.
@@ -64,10 +65,12 @@ class ChatManager {
public function __construct(CommentsManager $commentsManager,
IEventDispatcher $dispatcher,
+ INotificationManager $notificationManager,
Notifier $notifier,
ITimeFactory $timeFactory) {
$this->commentsManager = $commentsManager;
$this->dispatcher = $dispatcher;
+ $this->notificationManager = $notificationManager;
$this->notifier = $notifier;
$this->timeFactory = $timeFactory;
}
@@ -174,6 +177,7 @@ class ChatManager {
$event = new ChatParticipantEvent($chat, $comment, $participant);
$this->dispatcher->dispatch(self::EVENT_BEFORE_MESSAGE_SEND, $event);
+ $shouldFlush = $this->notificationManager->defer();
try {
$this->commentsManager->save($comment);
@@ -196,6 +200,9 @@ class ChatManager {
$this->dispatcher->dispatch(self::EVENT_AFTER_MESSAGE_SEND, $event);
} catch (NotFoundException $e) {
}
+ if ($shouldFlush) {
+ $this->notificationManager->flush();
+ }
return $comment;
}
diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php
index f381a55bb..d4130ef17 100644
--- a/lib/Chat/Notifier.php
+++ b/lib/Chat/Notifier.php
@@ -95,6 +95,7 @@ class Notifier {
}
$notification = $this->createNotification($chat, $comment, 'mention');
+ $shouldFlush = $this->notificationManager->defer();
foreach ($mentionedUserIds as $mentionedUserId) {
if (in_array($mentionedUserId, $alreadyNotifiedUsers, true)) {
continue;
@@ -107,6 +108,10 @@ class Notifier {
}
}
+ if ($shouldFlush) {
+ $this->notificationManager->flush();
+ }
+
return $alreadyNotifiedUsers;
}
@@ -187,6 +192,7 @@ class Notifier {
*/
public function removePendingNotificationsForRoom(Room $chat): void {
$notification = $this->notificationManager->createNotification();
+ $shouldFlush = $this->notificationManager->defer();
// @todo this should be in the Notifications\Hooks
$notification->setApp('spreed');
@@ -199,6 +205,10 @@ class Notifier {
$notification->setObject('call', $chat->getToken());
$this->notificationManager->markProcessed($notification);
+
+ if ($shouldFlush) {
+ $this->notificationManager->flush();
+ }
}
/**
@@ -212,6 +222,7 @@ class Notifier {
return;
}
+ $shouldFlush = $this->notificationManager->defer();
$notification = $this->notificationManager->createNotification();
$notification
@@ -220,6 +231,9 @@ class Notifier {
->setUser($userId);
$this->notificationManager->markProcessed($notification);
+ if ($shouldFlush) {
+ $this->notificationManager->flush();
+ }
}
/**
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index d3246e1d0..58acd72b0 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -187,6 +187,7 @@ class PageController extends Controller {
try {
$room = $this->manager->getRoomByToken($token);
$notification = $this->notificationManager->createNotification();
+ $shouldFlush = $this->notificationManager->defer();
try {
$notification->setApp('spreed')
->setUser($this->userId)
@@ -198,6 +199,10 @@ class PageController extends Controller {
$this->logger->logException($e, ['app' => 'spreed']);
}
+ if ($shouldFlush) {
+ $this->notificationManager->flush();
+ }
+
// If the room is not a public room, check if the user is in the participants
if ($room->getType() !== Room::PUBLIC_CALL) {
$this->manager->getRoomForParticipant($room->getId(), $this->userId);
diff --git a/lib/Notification/Listener.php b/lib/Notification/Listener.php
index ec832633d..9ae172c73 100644
--- a/lib/Notification/Listener.php
+++ b/lib/Notification/Listener.php
@@ -28,9 +28,7 @@ use OCA\Talk\Events\JoinRoomUserEvent;
use OCA\Talk\Events\RoomEvent;
use OCA\Talk\Room;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
-use OCP\Notification\IApp;
use OCP\Notification\IManager;
use OCP\ILogger;
use OCP\IUser;
@@ -121,6 +119,7 @@ class Listener {
$actorId = $actor->getUID();
$notification = $this->notificationManager->createNotification();
+ $shouldFlush = $this->notificationManager->defer();
$dateTime = $this->timeFactory->getDateTime();
try {
$notification->setApp('spreed')
@@ -131,6 +130,9 @@ class Listener {
]);
} catch (\InvalidArgumentException $e) {
$this->logger->logException($e, ['app' => 'spreed']);
+ if ($shouldFlush) {
+ $this->notificationManager->flush();
+ }
return;
}
@@ -147,6 +149,10 @@ class Listener {
$this->logger->logException($e, ['app' => 'spreed']);
}
}
+
+ if ($shouldFlush) {
+ $this->notificationManager->flush();
+ }
}
/**
@@ -206,8 +212,8 @@ class Listener {
$actor = $this->userSession->getUser();
$actorId = $actor instanceof IUser ? $actor->getUID() :'';
- $this->dispatcher->dispatch(IApp::class . '::defer', new Event());
$notification = $this->notificationManager->createNotification();
+ $shouldFlush = $this->notificationManager->defer();
$dateTime = $this->timeFactory->getDateTime();
try {
// Remove all old notifications for this room
@@ -224,7 +230,9 @@ class Listener {
->setDateTime($dateTime);
} catch (\InvalidArgumentException $e) {
$this->logger->logException($e, ['app' => 'spreed']);
- $this->dispatcher->dispatch(IApp::class . '::flush', new Event());
+ if ($shouldFlush) {
+ $this->notificationManager->flush();
+ }
return;
}
@@ -241,7 +249,10 @@ class Listener {
$this->logger->logException($e, ['app' => 'spreed']);
}
}
- $this->dispatcher->dispatch(IApp::class . '::flush', new Event());
+
+ if ($shouldFlush) {
+ $this->notificationManager->flush();
+ }
}
/**