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
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-03-04 14:23:40 +0300
committerJoas Schilling <coding@schilljs.com>2022-03-15 11:40:30 +0300
commitc92c70358824b2b92f8bda061cd8ea0703b0bad2 (patch)
tree7bb760fcd4fbc95f7d6bd186304fb20677ad58b8 /lib
parent2080e4049a79b41e5c93315b96cc09bf1c62fda5 (diff)
Inject the attendee as well when loaded already
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Chat/Notifier.php42
1 files changed, 24 insertions, 18 deletions
diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php
index b05ff121e..e255dae29 100644
--- a/lib/Chat/Notifier.php
+++ b/lib/Chat/Notifier.php
@@ -93,7 +93,7 @@ class Notifier {
* @param array[] $alreadyNotifiedUsers
* @psalm-param array<int, array{id: string, type: string}> $alreadyNotifiedUsers
* @return string[] Users that were mentioned
- * @psalm-return array<int, array{id: string, type: string}>
+ * @psalm-return array<int, array{id: string, type: string, ?attendee: Attendee}>
*/
public function notifyMentionedUsers(Room $chat, IComment $comment, array $alreadyNotifiedUsers): array {
$usersToNotify = $this->getUsersToNotify($chat, $comment, $alreadyNotifiedUsers);
@@ -105,7 +105,7 @@ class Notifier {
$shouldFlush = $this->notificationManager->defer();
foreach ($usersToNotify as $mentionedUser) {
- if ($this->shouldMentionedUserBeNotified($mentionedUser['id'], $comment, $chat)) {
+ if ($this->shouldMentionedUserBeNotified($mentionedUser['id'], $comment, $chat, $mentionedUser['attendee'] ?? null)) {
$notification->setUser($mentionedUser['id']);
$this->notificationManager->notify($notification);
$alreadyNotifiedUsers[] = $mentionedUser;
@@ -125,7 +125,7 @@ class Notifier {
* @param array $alreadyNotifiedUsers
* @psalm-param array<int, array{id: string, type: string}> $alreadyNotifiedUsers
* @return array
- * @psalm-return array<int, array{id: string, type: string}>
+ * @psalm-return array<int, array{id: string, type: string, ?attendee: Attendee}>
*/
private function getUsersToNotify(Room $chat, IComment $comment, array $alreadyNotifiedUsers): array {
$usersToNotify = $this->getMentionedUsers($comment);
@@ -159,7 +159,7 @@ class Notifier {
* @param array $list
* @psalm-param array<int, array{id: string, type: string}> $list
* @return array
- * @psalm-return array<int, array{id: string, type: string}>
+ * @psalm-return array<int, array{id: string, type: string, ?attendee: Attendee}>
*/
private function addMentionAllToList(Room $chat, array $list): array {
$usersToNotify = array_filter($list, static function (array $user): bool {
@@ -170,18 +170,19 @@ class Notifier {
return $usersToNotify;
}
- $chatParticipants = $this->participantService->getActorsByType($chat, Attendee::ACTOR_USERS);
- foreach ($chatParticipants as $participant) {
- $alreadyAddedToNotify = array_filter($list, static function ($user) use ($participant): bool {
- return $user['id'] === $participant->getActorId();
+ $attendees = $this->participantService->getActorsByType($chat, Attendee::ACTOR_USERS);
+ foreach ($attendees as $attendee) {
+ $alreadyAddedToNotify = array_filter($list, static function ($user) use ($attendee): bool {
+ return $user['id'] === $attendee->getActorId();
});
if (!empty($alreadyAddedToNotify)) {
continue;
}
$usersToNotify[] = [
- 'id' => $participant->getActorId(),
- 'type' => $participant->getActorType()
+ 'id' => $attendee->getActorId(),
+ 'type' => $attendee->getActorType(),
+ 'attendee' => $attendee,
];
}
@@ -238,7 +239,7 @@ class Notifier {
* @param Room $chat
* @param IComment $comment
* @param array[] $alreadyNotifiedUsers
- * @psalm-param array<int, array{id: string, type: string}> $alreadyNotifiedUsers
+ * @psalm-param array<int, array{id: string, type: string, ?attendee: Attendee}> $alreadyNotifiedUsers
*/
public function notifyOtherParticipant(Room $chat, IComment $comment, array $alreadyNotifiedUsers): void {
$participants = $this->participantService->getParticipantsByNotificationLevel($chat, Participant::NOTIFY_ALWAYS);
@@ -427,21 +428,26 @@ class Notifier {
* @param string $userId
* @param IComment $comment
* @param Room $room
+ * @param Attendee|null $attendee
* @return bool
*/
- protected function shouldMentionedUserBeNotified(string $userId, IComment $comment, Room $room): bool {
+ protected function shouldMentionedUserBeNotified(string $userId, IComment $comment, Room $room, ?Attendee $attendee = null): bool {
if ($comment->getActorType() === Attendee::ACTOR_USERS && $userId === $comment->getActorId()) {
// Do not notify the user if they mentioned themselves
return false;
}
- if (!$this->userManager->userExists($userId)) {
- return false;
- }
-
try {
- $participant = $room->getParticipant($userId, false);
- $notificationLevel = $participant->getAttendee()->getNotificationLevel();
+ if (!$attendee instanceof Attendee) {
+ if (!$this->userManager->userExists($userId)) {
+ return false;
+ }
+
+ $participant = $room->getParticipant($userId, false);
+ $attendee = $participant->getAttendee();
+ }
+
+ $notificationLevel = $attendee->getNotificationLevel();
if ($notificationLevel === Participant::NOTIFY_DEFAULT) {
if ($room->getType() === Room::TYPE_ONE_TO_ONE) {
$notificationLevel = Participant::NOTIFY_ALWAYS;