Skip to content

Commit

Permalink
feat: Initial implementation of reactions notifications in federated …
Browse files Browse the repository at this point in the history
…convos

Signed-off-by: skalidindi53 <[email protected]>
  • Loading branch information
skalidindi53 committed Sep 27, 2024
1 parent ab396ab commit b4a6ad2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/Federation/Proxy/TalkV1/Notifier/MessageSentListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public function handle(Event $event): void {
$chatMessage = $this->messageParser->createMessage($event->getRoom(), null, $event->getComment(), $l);
$this->messageParser->parseMessage($chatMessage);

$messageType = $chatMessage->getMessageType();

// Handle reaction events
if ($messageType === ChatManager::VERB_REACTION) {
$this->createReactionNotification($event->getRoom(), $event->getComment(), $chatMessage->getVerb(), $chatMessage->getMessageParameters());

Check failure on line 64 in lib/Federation/Proxy/TalkV1/Notifier/MessageSentListener.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedMethod

lib/Federation/Proxy/TalkV1/Notifier/MessageSentListener.php:64:11: UndefinedMethod: Method OCA\Talk\Federation\Proxy\TalkV1\Notifier\MessageSentListener::createReactionNotification does not exist (see https://psalm.dev/022)

Check failure on line 64 in lib/Federation/Proxy/TalkV1/Notifier/MessageSentListener.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedMethod

lib/Federation/Proxy/TalkV1/Notifier/MessageSentListener.php:64:93: UndefinedMethod: Method OCA\Talk\Model\Message::getVerb does not exist (see https://psalm.dev/022)
return;
}

$systemMessage = $chatMessage->getMessageType() === ChatManager::VERB_SYSTEM ? $chatMessage->getMessageRaw() : '';
if ($systemMessage !== 'message_edited'
&& $systemMessage !== 'message_deleted'
Expand Down Expand Up @@ -124,4 +132,26 @@ public function handle(Event $event): void {
}
}
}

// /**
// * Creates a notification for the given chat message comment and mentioned
// * user ID.
// */
// private function createReactionNotification(Room $chat, IComment $comment, string $subject, array $subjectData = [], ?IComment $reaction = null): INotification {
// $subjectData['userType'] = $reaction ? $reaction->getActorType() : $comment->getActorType();
// $subjectData['userId'] = $reaction ? $reaction->getActorId() : $comment->getActorId();

// $notification = $this->notificationManager->createNotification();
// $notification
// ->setApp('spreed')
// ->setObject('chat', $chat->getToken())
// ->setSubject($subject, $subjectData)
// ->setMessage($comment->getVerb(), [
// 'commentId' => $comment->getId(),
// ])
// ->setDateTime($reaction ? $reaction->getCreationDateTime() : $comment->getCreationDateTime());

// return $notification;
// }

}
41 changes: 41 additions & 0 deletions tests/integration/features/federation/chat.feature
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,44 @@ Feature: federation/chat
| actorType | actorId | actorDisplayName | reaction |
| users | participant1 | participant1-displayname | 🚀 |
| federated_users | participant2@{$REMOTE_URL} | participant2-displayname | 🚀 |

# Scenario: Verifying Notifications for Local Participants

# Given the following "spreed" app config is set
# | federation_enabled | yes |
# And user "participant1" creates room "room" (v4)
# | roomType | 2 |
# | roomName | room |
# And user "participant1" adds federated_user "participant3" to room "room" with 200 (v4)
# And user "participant1" adds user "participant2" 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 |
# | LOCAL::room | room | 2 | LOCAL | room |

# # Enable Notifications for Local User
# And user "participant2" sets notifications to all for room "room" (v4)

# #fed user
# #And user "participant3" sets notifications to all for room "room" (v4)
# And user "participant3" sets notifications to all for room "LOCAL::room" (v4)

# # Sending a Message
# When user "participant1" sends message "Message 1" to room "room" with 201

# And user "participant1" react with "🚀" on message "Message 1" to room "room" with 201
# | actorType | actorId | actorDisplayName | reaction |
# | users | participant1 | participant1-displayname | 🚀 |

# # Verification for Message Notification
# Then user "participant2" has the following notifications
# | app | object_type | object_id | subject | message |
# | spreed | chat | room/Message 1 | participant1-displayname sent a message in conversation room | Message 1 |
# | spreed | room | room | participant1-displayname invited you to a group conversation: room | |

# Then user "participant3" has the following notifications
# | app | object_type | object_id | subject | message |
# | spreed | chat | LOCAL::room/Message 1 | participant1-displayname sent a message in conversation room | Message 1 |
# #| spreed | room | LOCAL::room | participant1-displayname invited you to a group conversation: room | |

0 comments on commit b4a6ad2

Please sign in to comment.