From e5b0c06b2449d9015ed1ce5d0fd027836babc939 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 27 Feb 2024 17:11:23 +0100 Subject: feat(comments): Allow mentions of federated users, groups and teams in the future Signed-off-by: Joas Schilling --- lib/private/Comments/Comment.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/private/Comments') diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 183821e37b1..58a3ac96b1d 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -220,7 +220,7 @@ class Comment implements IComment { * */ public function getMentions(): array { - $ok = preg_match_all("/\B(?getMessage(), $mentions); + $ok = preg_match_all("/\B(?getMessage(), $mentions); if (!$ok || !isset($mentions[0])) { return []; } @@ -230,11 +230,21 @@ class Comment implements IComment { }); $result = []; foreach ($mentionIds as $mentionId) { + // Cut-off the @ and remove wrapping double-quotes $cleanId = trim(substr($mentionId, 1), '"'); + if (str_starts_with($cleanId, 'guest/')) { $result[] = ['type' => 'guest', 'id' => $cleanId]; + } elseif (str_starts_with($cleanId, 'federated_group/')) { + $result[] = ['type' => 'federated_group', 'id' => substr($cleanId, 16)]; } elseif (str_starts_with($cleanId, 'group/')) { $result[] = ['type' => 'group', 'id' => substr($cleanId, 6)]; + } elseif (str_starts_with($cleanId, 'federated_team/')) { + $result[] = ['type' => 'federated_team', 'id' => substr($cleanId, 15)]; + } elseif (str_starts_with($cleanId, 'team/')) { + $result[] = ['type' => 'team', 'id' => substr($cleanId, 5)]; + } elseif (str_starts_with($cleanId, 'federated_user/')) { + $result[] = ['type' => 'federated_user', 'id' => substr($cleanId, 15)]; } else { $result[] = ['type' => 'user', 'id' => $cleanId]; } -- cgit v1.2.3