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/Chat
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-07-15 10:04:35 +0300
committerJoas Schilling <coding@schilljs.com>2019-07-30 10:33:41 +0300
commite3e3e8e741f5bc94510b2002031e2777e64a42ba (patch)
treef1295b81f24eb558c966123a991bfae53120259d /lib/Chat
parenta1b17d282f5c9d886ad9320aa4178d16a153e9ea (diff)
Add a mention-alike notification for replies
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Chat')
-rw-r--r--lib/Chat/ChatManager.php13
-rw-r--r--lib/Chat/Notifier.php48
2 files changed, 51 insertions, 10 deletions
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php
index b7ce645fd..36550ef4a 100644
--- a/lib/Chat/ChatManager.php
+++ b/lib/Chat/ChatManager.php
@@ -166,13 +166,18 @@ class ChatManager {
// Update last_message
$chat->setLastMessage($comment);
- $mentionedUsers = $this->notifier->notifyMentionedUsers($chat, $comment);
- if (!empty($mentionedUsers)) {
- $chat->markUsersAsMentioned($mentionedUsers, (int) $comment->getId());
+ $alreadyNotifiedUsers = [];
+ if ($replyTo instanceof IComment) {
+ $alreadyNotifiedUsers = $this->notifier->notifyReplyToAuthor($chat, $comment, $replyTo);
+ }
+
+ $alreadyNotifiedUsers = $this->notifier->notifyMentionedUsers($chat, $comment, $alreadyNotifiedUsers);
+ if (!empty($alreadyNotifiedUsers)) {
+ $chat->markUsersAsMentioned($alreadyNotifiedUsers, (int) $comment->getId());
}
// User was not mentioned, send a normal notification
- $this->notifier->notifyOtherParticipant($chat, $comment, $mentionedUsers);
+ $this->notifier->notifyOtherParticipant($chat, $comment, $alreadyNotifiedUsers);
$this->dispatcher->dispatch(self::class . '::sendMessage', new GenericEvent($chat, [
'comment' => $comment,
diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php
index 4f44d034b..8b744bee0 100644
--- a/lib/Chat/Notifier.php
+++ b/lib/Chat/Notifier.php
@@ -76,9 +76,10 @@ class Notifier {
*
* @param Room $chat
* @param IComment $comment
+ * @param string[] $alreadyNotifiedUsers
* @return string[] Users that were mentioned
*/
- public function notifyMentionedUsers(Room $chat, IComment $comment): array {
+ public function notifyMentionedUsers(Room $chat, IComment $comment, array $alreadyNotifiedUsers): array {
$mentionedUserIds = $this->getMentionedUserIds($comment);
if (empty($mentionedUserIds)) {
return [];
@@ -92,13 +93,48 @@ class Notifier {
$notification = $this->createNotification($chat, $comment, 'mention');
foreach ($mentionedUserIds as $mentionedUserId) {
+ if (in_array($mentionedUserId, $alreadyNotifiedUsers, true)) {
+ continue;
+ }
+
if ($this->shouldUserBeNotified($mentionedUserId, $comment)) {
$notification->setUser($mentionedUserId);
$this->notificationManager->notify($notification);
+ $alreadyNotifiedUsers[] = $mentionedUserId;
}
}
- return $mentionedUserIds;
+ return $alreadyNotifiedUsers;
+ }
+
+ /**
+ * Notifies the author that wrote the comment which was replied to
+ *
+ * The comment must be a chat message comment. That is, its "objectId" must
+ * be the room ID.
+ *
+ * The author of the message is notified only if he is still able to participate in the room
+ *
+ * @param Room $chat
+ * @param IComment $comment
+ * @param IComment $replyTo
+ * @return string[] Users that were mentioned
+ */
+ public function notifyReplyToAuthor(Room $chat, IComment $comment, IComment $replyTo): array {
+ if ($replyTo->getActorType() !== 'users') {
+ // No reply notification when the replyTo-author was not a user
+ return [];
+ }
+
+ if (!$this->shouldUserBeNotified($replyTo->getActorId(), $comment)) {
+ return [];
+ }
+
+ $notification = $this->createNotification($chat, $comment, 'reply');
+ $notification->setUser($replyTo->getActorId());
+ $this->notificationManager->notify($notification);
+
+ return [$replyTo->getActorId()];
}
/**
@@ -112,9 +148,9 @@ class Notifier {
*
* @param Room $chat
* @param IComment $comment
- * @param string[] $mentionedUsers
+ * @param string[] $alreadyNotifiedUsers
*/
- public function notifyOtherParticipant(Room $chat, IComment $comment, array $mentionedUsers): void {
+ public function notifyOtherParticipant(Room $chat, IComment $comment, array $alreadyNotifiedUsers): void {
$participants = $chat->getParticipantsByNotificationLevel(Participant::NOTIFY_ALWAYS);
$notification = $this->createNotification($chat, $comment, 'chat');
@@ -128,7 +164,7 @@ class Notifier {
continue;
}
- if (\in_array($participant->getUser(), $mentionedUsers, true)) {
+ if (\in_array($participant->getUser(), $alreadyNotifiedUsers, true)) {
continue;
}
@@ -154,7 +190,7 @@ class Notifier {
continue;
}
- if (\in_array($participant->getUser(), $mentionedUsers, true)) {
+ if (\in_array($participant->getUser(), $alreadyNotifiedUsers, true)) {
continue;
}