Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] fix(federation): Don't send notifications for most system messages in… #12371

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/Federation/CloudFederationProviderTalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
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;
Expand Down Expand Up @@ -96,6 +97,7 @@ public function __construct(
private ProxyCacheMessageService $pcmService,
private FederationChatNotifier $federationChatNotifier,
private UserConverter $userConverter,
private ITimeFactory $timeFactory,
ICacheFactory $cacheFactory,
) {
$this->proxyCacheMessages = $cacheFactory->isAvailable() ? $cacheFactory->createDistributed(CachePrefix::FEDERATED_PCM) : null;
Expand Down Expand Up @@ -402,7 +404,11 @@ private function messagePosted(int $remoteAttendeeId, array $notification): arra
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']]));
Expand Down
16 changes: 13 additions & 3 deletions lib/Notification/FederationChatNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ public function handleChatMessage(Room $room, Participant $participant, ProxyCac
}
} 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);
}
}
}

Expand Down Expand Up @@ -128,6 +130,14 @@ protected function isMentionedAll(Room $room, ProxyCacheMessage $message): bool
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
*/
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/features/federation/chat.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions tests/php/Federation/FederationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public function setUp(): void {
$this->proxyCacheMessageService,
$this->federationChatNotifier,
$this->userConverter,
$this->timeFactory,
$this->cacheFactory,
);
}
Expand Down
Loading