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
diff options
context:
space:
mode:
authorIvan Sein <ivan@struktur.de>2018-08-02 12:41:03 +0300
committerGitHub <noreply@github.com>2018-08-02 12:41:03 +0300
commitcd5cd449f93d555128b37b1141a8a7a9ccfae032 (patch)
tree103c4672e2600991acfc9bf32b000d4d1a287495
parent8005b579bfef5e8e2011363f008bd4012aa66245 (diff)
parentb74f91ba81e7d7078d5f5823035c70735983faa8 (diff)
Merge pull request #1029 from nextcloud/feature/noid/always-notify-in-one2one-rooms
Always notify in one2one rooms
-rw-r--r--lib/Chat/ChatManager.php4
-rw-r--r--lib/Chat/Notifier.php48
-rw-r--r--lib/Notification/Notifier.php13
-rw-r--r--tests/php/Notification/NotifierTest.php2
4 files changed, 63 insertions, 4 deletions
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php
index 8bc6ca0ca..ed9178d5f 100644
--- a/lib/Chat/ChatManager.php
+++ b/lib/Chat/ChatManager.php
@@ -27,7 +27,6 @@ use OCA\Spreed\Room;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
-use OCP\IDBConnection;
use OCP\IUser;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
@@ -118,6 +117,9 @@ class ChatManager {
$notifiedUsers = $this->notifier->notifyMentionedUsers($chat, $comment);
if (!empty($notifiedUsers)) {
$chat->markUsersAsMentioned($notifiedUsers, $creationDateTime);
+ } else if ($chat->getType() === Room::ONE_TO_ONE_CALL) {
+ // User was not mentioned, send a normal notification
+ $this->notifier->notifyOtherParticipant($chat, $comment);
}
$this->dispatcher->dispatch(self::class . '::sendMessage', new GenericEvent($chat, [
diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php
index bb2967491..6f574ddd8 100644
--- a/lib/Chat/Notifier.php
+++ b/lib/Chat/Notifier.php
@@ -26,6 +26,7 @@ namespace OCA\Spreed\Chat;
use OCA\Spreed\Exceptions\ParticipantNotFoundException;
use OCA\Spreed\Exceptions\RoomNotFoundException;
use OCA\Spreed\Manager;
+use OCA\Spreed\Participant;
use OCA\Spreed\Room;
use OCP\Comments\IComment;
use OCP\Notification\IManager as INotificationManager;
@@ -96,6 +97,53 @@ class Notifier {
}
/**
+ * Notifies the user mentioned in the comment.
+ *
+ * The comment must be a chat message comment. That is, its "objectId" must
+ * be the room ID.
+ *
+ * Not every user mentioned in the message is notified, but only those that
+ * are able to participate in the room.
+ *
+ * @param Room $chat
+ * @param IComment $comment
+ */
+ public function notifyOtherParticipant(Room $chat, IComment $comment) {
+ $participants = $chat->getParticipants();
+
+ foreach ($participants['users'] as $userId => $participant) {
+ if ($userId === $comment->getActorId()) {
+ // Do not notify the author
+ continue;
+ }
+
+ if ($participant['sessionId'] && $participant['sessionId'] !== '0') {
+ // User is online
+ continue;
+ }
+
+ $notification = $this->notificationManager->createNotification();
+ $notification
+ ->setApp('spreed')
+ ->setObject('chat', $chat->getToken())
+ ->setUser($userId)
+ ->setSubject('chat', [
+ 'userType' => $comment->getActorType(),
+ 'userId' => $comment->getActorId(),
+ ])
+ ->setDateTime($comment->getCreationDateTime());
+
+ if (strlen($comment->getMessage()) > 64) {
+ $notification->setMessage(substr($comment->getMessage(), 0, 64), ['ellipsisEnd']);
+ } else {
+ $notification->setMessage($comment->getMessage());
+ }
+
+ $this->notificationManager->notify($notification);
+ }
+ }
+
+ /**
* Removes all the pending notifications for the room with the given ID.
*
* @param Room $chat
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index b930233aa..927f643c0 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -97,7 +97,7 @@ class Notifier implements INotifier {
if ($subject === 'call') {
return $this->parseCall($notification, $room, $l);
}
- if ($subject === 'mention') {
+ if ($subject === 'mention' || $subject === 'chat') {
return $this->parseMention($notification, $room, $l);
}
@@ -157,7 +157,16 @@ class Notifier implements INotifier {
}
$notification->setParsedMessage($parsedMessage);
- if ($room->getType() === Room::ONE_TO_ONE_CALL) {
+ if ($notification->getSubject() === 'chat') {
+ $notification
+ ->setParsedSubject(str_replace('{user}', $user->getDisplayName(), $l->t('{user} sent you a private message')))
+ ->setRichSubject(
+ $l->t('{user} sent you a private message'), [
+ 'user' => $richSubjectUser
+ ]
+ );
+
+ } else if ($room->getType() === Room::ONE_TO_ONE_CALL) {
$notification
->setParsedSubject(
$l->t('%s mentioned you in a private conversation', [$user->getDisplayName()])
diff --git a/tests/php/Notification/NotifierTest.php b/tests/php/Notification/NotifierTest.php
index 9733cb9e3..07a923c46 100644
--- a/tests/php/Notification/NotifierTest.php
+++ b/tests/php/Notification/NotifierTest.php
@@ -451,7 +451,7 @@ class NotifierTest extends \Test\TestCase {
$notification->expects($this->once())
->method('getApp')
->willReturn('spreed');
- $notification->expects($this->once())
+ $notification->expects($this->exactly(2))
->method('getSubject')
->willReturn('mention');
$notification->expects($this->once())