diff options
author | Joas Schilling <coding@schilljs.com> | 2024-03-15 15:45:10 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-03-15 15:45:31 +0100 |
commit | fc53de1c21587f2d388adca6dd015c6dc9c283a5 (patch) | |
tree | e69f2e627c956e17951e6590ad76f6af1e9ee4f8 | |
parent | 7736524344560a378922c573f04485bc84eef4ce (diff) |
fix(federation): Don't trigger notifications for own messages
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/Notification/FederationChatNotifier.php | 5 | ||||
-rw-r--r-- | tests/integration/features/federation/chat.feature | 35 |
2 files changed, 40 insertions, 0 deletions
diff --git a/lib/Notification/FederationChatNotifier.php b/lib/Notification/FederationChatNotifier.php index 08b6fc094..69e6671e0 100644 --- a/lib/Notification/FederationChatNotifier.php +++ b/lib/Notification/FederationChatNotifier.php @@ -48,6 +48,11 @@ class FederationChatNotifier { * @param array{remoteServerUrl: string, sharedSecret: string, remoteToken: string, messageData: array{remoteMessageId: int, actorType: string, actorId: string, actorDisplayName: string, messageType: string, systemMessage: string, expirationDatetime: string, message: string, messageParameter: string, creationDatetime: string, metaData: string}, unreadInfo: array{unreadMessages: int, unreadMention: bool, unreadMentionDirect: bool, lastReadMessage: int}} $inboundNotification */ public function handleChatMessage(Room $room, Participant $participant, ProxyCacheMessage $message, array $inboundNotification): void { + if ($participant->getAttendee()->getActorType() === $inboundNotification['messageData']['actorType'] + && $participant->getAttendee()->getActorId() === $inboundNotification['messageData']['actorId']) { + return; + } + /** @var array{silent?: bool, last_edited_time?: int, last_edited_by_type?: string, last_edited_by_id?: string, replyToActorType?: string, replyToActorId?: string} $metaData */ $metaData = json_decode($inboundNotification['messageData']['metaData'] ?? '', true, flags: JSON_THROW_ON_ERROR); diff --git a/tests/integration/features/federation/chat.feature b/tests/integration/features/federation/chat.feature index b56078ce2..30b1a25ba 100644 --- a/tests/integration/features/federation/chat.feature +++ b/tests/integration/features/federation/chat.feature @@ -281,6 +281,41 @@ Feature: federation/chat | app | object_type | object_id | subject | message | | spreed | chat | room/Hi @"federated_user/participant2@{$REMOTE_URL}" bye | participant3-displayname mentioned you in conversation room | Hi @participant2-displayname bye | + Scenario: Mentioning and replying to self does not do notifications + Given the following "spreed" app config is set + | federation_enabled | yes | + Given 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 | + Then user "participant2" is participant of the following rooms (v4) + | id | type | + | room | 3 | + And user "participant1" adds federated_user "participant3" to room "room" with 200 (v4) + And user "participant3" has the following invitations (v1) + | remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName | + | LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname | + And user "participant3" accepts invite to room "room" of server "LOCAL" with 200 (v1) + | id | name | type | remoteServer | remoteToken | + | room | room | 3 | LOCAL | room | + Then user "participant3" is participant of the following rooms (v4) + | id | type | + | room | 3 | + # Join and leave to clear the invite notification + Given user "participant2" joins room "LOCAL::room" with 200 (v4) + Given user "participant2" leaves room "LOCAL::room" with 200 (v4) + When user "participant2" sends message 'Hi @"federated_user/participant2@{$REMOTE_URL}" bye' to room "LOCAL::room" with 201 + And user "participant2" sends message "Message 1" to room "LOCAL::room" with 201 + When user "participant2" sends reply "Message 1-1" on message "Message 1" to room "LOCAL::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 | |