diff options
author | Joas Schilling <coding@schilljs.com> | 2024-05-10 16:42:20 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-05-13 15:53:19 +0200 |
commit | 9b2a09c6e4c0bf1ecbc41851f3cc951d147fec51 (patch) | |
tree | 01b8b0b6e43152e5ba147c104795c2fe57c44ae2 | |
parent | 133a7ca0287059e92ba6dfd8d79ccee3d2299bf7 (diff) |
fix(federation): Don't send notifications for most system messages in federation
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/Federation/CloudFederationProviderTalk.php | 8 | ||||
-rw-r--r-- | lib/Notification/FederationChatNotifier.php | 16 | ||||
-rw-r--r-- | tests/integration/features/federation/chat.feature | 23 | ||||
-rw-r--r-- | tests/php/Federation/FederationTest.php | 1 |
4 files changed, 44 insertions, 4 deletions
diff --git a/lib/Federation/CloudFederationProviderTalk.php b/lib/Federation/CloudFederationProviderTalk.php index 2ab2e71c2..c49a64c20 100644 --- a/lib/Federation/CloudFederationProviderTalk.php +++ b/lib/Federation/CloudFederationProviderTalk.php @@ -36,6 +36,7 @@ use OCA\Talk\Service\RoomService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; use OCP\AppFramework\Services\IAppConfig; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\DB\Exception as DBException; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\Exceptions\ActionNotSupportedException; @@ -79,6 +80,7 @@ class CloudFederationProviderTalk implements ICloudFederationProvider { private ProxyCacheMessageService $pcmService, private FederationChatNotifier $federationChatNotifier, private UserConverter $userConverter, + private ITimeFactory $timeFactory, ICacheFactory $cacheFactory, ) { $this->proxyCacheMessages = $cacheFactory->isAvailable() ? $cacheFactory->createDistributed(CachePrefix::FEDERATED_PCM) : null; @@ -385,7 +387,11 @@ class CloudFederationProviderTalk implements ICloudFederationProvider { if ($notification['messageData']['remoteMessageId'] > $lastMessageId) { $lastMessageId = (int) $notification['messageData']['remoteMessageId']; } - $this->roomService->setLastMessageInfo($room, $lastMessageId, new \DateTime()); + + if ($notification['messageData']['systemMessage'] !== 'message_edited' + && $notification['messageData']['systemMessage'] !== 'message_deleted') { + $this->roomService->setLastMessageInfo($room, $lastMessageId, $this->timeFactory->getDateTime()); + } if ($this->proxyCacheMessages instanceof ICache) { $cacheKey = sha1(json_encode([$notification['remoteServerUrl'], $notification['remoteToken']])); diff --git a/lib/Notification/FederationChatNotifier.php b/lib/Notification/FederationChatNotifier.php index 8f4c76693..e22978362 100644 --- a/lib/Notification/FederationChatNotifier.php +++ b/lib/Notification/FederationChatNotifier.php @@ -63,9 +63,11 @@ class FederationChatNotifier { } } elseif ($participant->getAttendee()->getNotificationLevel() === Participant::NOTIFY_ALWAYS || ($defaultLevel === Participant::NOTIFY_ALWAYS && $participant->getAttendee()->getNotificationLevel() === Participant::NOTIFY_DEFAULT)) { - $notification = $this->createNotification($room, $message, 'chat'); - $notification->setUser($participant->getAttendee()->getActorId()); - $this->notificationManager->notify($notification); + if ($this->isUserMessageOrRelevantSystemMessage($message->getSystemMessage())) { + $notification = $this->createNotification($room, $message, 'chat'); + $notification->setUser($participant->getAttendee()->getActorId()); + $this->notificationManager->notify($notification); + } } } @@ -111,6 +113,14 @@ class FederationChatNotifier { return false; } + protected function isUserMessageOrRelevantSystemMessage(?string $systemMessage): bool { + return $systemMessage === null + || $systemMessage === '' + || $systemMessage === 'object_shared' + || $systemMessage === 'poll_closed' + || $systemMessage === 'file_shared'; + } + /** * Creates a notification for the given proxy message and mentioned users */ diff --git a/tests/integration/features/federation/chat.feature b/tests/integration/features/federation/chat.feature index de9aee824..616e91ec7 100644 --- a/tests/integration/features/federation/chat.feature +++ b/tests/integration/features/federation/chat.feature @@ -371,6 +371,29 @@ Feature: federation/chat Then user "participant2" has the following notifications | app | object_type | object_id | subject | message | + Scenario: System messages don't trigger notifications + Given the following "spreed" app config is set + | federation_enabled | yes | + And user "participant1" creates room "room" (v4) + | roomType | 3 | + | roomName | room | + And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4) + And user "participant2" has the following invitations (v1) + | remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName | + | LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname | + And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1) + | id | name | type | remoteServer | remoteToken | + | room | room | 3 | LOCAL | room | + And user "participant2" is participant of the following rooms (v4) + | id | type | + | room | 3 | + And user "participant1" sends message "Message 1" to room "room" with 201 + When user "participant2" sets notifications to all for room "LOCAL::room" (v4) + And user "participant1" sets description for room "room" to "the description" with 200 (v4) + And user "participant1" react with "🚀" on message "Message 1" to room "room" with 201 + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | message | + Scenario: Reaction on federated chat messages Given the following "spreed" app config is set | federation_enabled | yes | diff --git a/tests/php/Federation/FederationTest.php b/tests/php/Federation/FederationTest.php index d96f8af8b..9d3019250 100644 --- a/tests/php/Federation/FederationTest.php +++ b/tests/php/Federation/FederationTest.php @@ -135,6 +135,7 @@ class FederationTest extends TestCase { $this->proxyCacheMessageService, $this->federationChatNotifier, $this->userConverter, + $this->timeFactory, $this->cacheFactory, ); } |