diff --git a/api/add_comment.php b/api/add_comment.php index 06538b7..6fecce9 100644 --- a/api/add_comment.php +++ b/api/add_comment.php @@ -177,9 +177,16 @@ try { $ticketTitle = $ticket['title'] ?? "Ticket #{$ticketId}"; $ticketVisibility = $ticket['visibility'] ?? 'public'; - // @mention notifications — resolve usernames → Matrix IDs via Synapse Admin API - if (!empty($mentionedUsers)) { - $mentionedUsernames = array_column($mentionedUsers, 'username'); + // @mention notifications — resolve usernames → Matrix IDs via Synapse Admin API. + // Only notify mentioned users who actually have access to this ticket; + // otherwise a mention would DM them the ticket's title and comment text + // even though canUserAccessTicket() would deny them the ticket itself. + $accessibleMentionedUsers = array_filter( + $mentionedUsers, + fn($u) => $ticketModel->canUserAccessTicket($ticket, $u) + ); + if (!empty($accessibleMentionedUsers)) { + $mentionedUsernames = array_column($accessibleMentionedUsers, 'username'); $mentionedMatrixIds = SynapseHelper::resolveUsernames($mentionedUsernames); if (!empty($mentionedMatrixIds)) { NotificationHelper::sendMentionNotification($ticketId, $ticketTitle, $commentText, $authorDisplay, $mentionedMatrixIds); diff --git a/models/CommentModel.php b/models/CommentModel.php index 419f26b..57b816e 100644 --- a/models/CommentModel.php +++ b/models/CommentModel.php @@ -38,7 +38,7 @@ class CommentModel } $placeholders = str_repeat('?,', count($usernames) - 1) . '?'; - $sql = "SELECT user_id, username, display_name FROM users WHERE username IN ($placeholders)"; + $sql = "SELECT user_id, username, display_name, is_admin, `groups` FROM users WHERE username IN ($placeholders)"; $stmt = $this->conn->prepare($sql); $types = str_repeat('s', count($usernames));