Skip to content

Commit

Permalink
fix(federation): Don't notify users with active sessions
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Jul 12, 2024
1 parent 61d622c commit b530704
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Federation/CloudFederationProviderTalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ private function messagePosted(int $remoteAttendeeId, array $notification): arra
}

try {
$participant = $this->participantService->getParticipant($room, $invite->getUserId(), false);
$participant = $this->participantService->getParticipantWithActiveSession($room, $invite->getUserId());
} catch (ParticipantNotFoundException) {
// Not accepted the invite yet
return [];
Expand Down
6 changes: 6 additions & 0 deletions lib/Notification/FederationChatNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\Message;
use OCA\Talk\Model\ProxyCacheMessage;
use OCA\Talk\Model\Session;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\AppFramework\Services\IAppConfig;
Expand Down Expand Up @@ -61,6 +62,11 @@ public function handleChatMessage(Room $room, Participant $participant, ProxyCac
return;
}

if ($participant->getSession() instanceof Session) {
// User has an active session
return;
}

// Also notify default participants in one-to-one chats or when the admin default is "always"
$defaultLevel = $this->appConfig->getAppValueInt('default_group_notification', Participant::NOTIFY_MENTION);
if ($participant->getAttendee()->getNotificationLevel() === Participant::NOTIFY_MENTION
Expand Down
31 changes: 31 additions & 0 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,37 @@ public function getParticipant(Room $room, ?string $userId, $sessionId = null):
return $participant;
}

/**
* Get a participant with an active session if there is one, otherwise without session
*
* @param Room $room
* @param string $userId
* @return Participant
* @throws ParticipantNotFoundException When the user is not a participant
*/
public function getParticipantWithActiveSession(Room $room, string $userId): Participant {
if ($userId === '') {
throw new ParticipantNotFoundException('Not a user');
}

$query = $this->connection->getQueryBuilder();
$helper = new SelectHelper();
$helper->selectAttendeesTable($query);
$helper->selectSessionsTable($query);
$query->from('talk_attendees', 'a')
->leftJoin('a', 'talk_sessions', 's', $query->expr()->andX(
$query->expr()->eq('a.id', 's.attendee_id'),
$query->expr()->eq('s.state', $query->createNamedParameter(Session::STATE_ACTIVE, IQueryBuilder::PARAM_INT))
))
->where($query->expr()->eq('a.actor_type', $query->createNamedParameter(Attendee::ACTOR_USERS)))
->andWhere($query->expr()->eq('a.actor_id', $query->createNamedParameter($userId)))
->andWhere($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId())))
->setMaxResults(1);


return $this->getParticipantFromQuery($query, $room);
}

/**
* @param Room $room
* @param string|null $sessionId
Expand Down

0 comments on commit b530704

Please sign in to comment.