aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Comments
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-02-27 17:11:23 +0100
committerJoas Schilling <coding@schilljs.com>2024-02-27 17:11:23 +0100
commite5b0c06b2449d9015ed1ce5d0fd027836babc939 (patch)
treea121a85cf2c72bbae4a99107e100b37a9f69c4a1 /lib/private/Comments
parent455a209b9c4f3b95a016ce1c0bcd1bcfa3fc86bf (diff)
downloadnextcloud-server-e5b0c06b2449d9015ed1ce5d0fd027836babc939.tar.gz
nextcloud-server-e5b0c06b2449d9015ed1ce5d0fd027836babc939.zip
feat(comments): Allow mentions of federated users, groups and teams in the future
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Comments')
-rw-r--r--lib/private/Comments/Comment.php12
1 files changed, 11 insertions, 1 deletions
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(?<![^a-z0-9_\-@\.\'\s])@(\"guest\/[a-f0-9]+\"|\"group\/[a-z0-9_\-@\.\' ]+\"|\"[a-z0-9_\-@\.\' ]+\"|[a-z0-9_\-@\.\']+)/i", $this->getMessage(), $mentions);
+ $ok = preg_match_all("/\B(?<![^a-z0-9_\-@\.\'\s])@(\"guest\/[a-f0-9]+\"|\"(?:federated_)?(?:group|team|user){1}\/[a-z0-9_\-@\.\' \/:]+\"|\"[a-z0-9_\-@\.\' ]+\"|[a-z0-9_\-@\.\']+)/i", $this->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];
}