Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/private/Comments/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH): ICo
*
* @param bool $supportMarkdown
* @return array each mention provides a 'type' and an 'id', see example below
* @psalm-return list<array{type: 'guest'|'email'|'federated_group'|'group'|'federated_team'|'team'|'federated_user'|'user', id: non-empty-lowercase-string}>
* @psalm-return list<array{type: 'guest'|'email'|'federated_group'|'group'|'federated_team'|'team'|'federated_user'|'matrix'|'user', id: non-empty-lowercase-string}>
* @since 36.0.0 Type 'matrix' is supported
* @since 33.0.1 Parameter $supportMarkdown was added to decide if mentions inside markdown code blocks should be ignored (default to true)
* @since 30.0.2 Type 'email' is supported
* @since 29.0.0 Types 'federated_group', 'federated_team', 'team' and 'federated_user' are supported
Expand All @@ -213,7 +214,7 @@ public function getMentions(bool $supportMarkdown = true): array {
$message = preg_replace('/`[^`\n]*`/', '', $message);
}

$ok = preg_match_all("/\B(?<![^a-z0-9_\-@\.\'\s])@(\"(guest|email)\/[a-f0-9]+\"|\"(?:federated_)?(?:group|team|user){1}\/[a-z0-9_\-@\.\' \/:]+\"|\"[a-z0-9_\-@\.\' ]+\"|[a-z0-9_\-@\.\']+)/i", $message, $mentions);
$ok = preg_match_all("/\B(?<![^a-z0-9_\-@\.\'\s])@(\"(guest|email)\/[a-f0-9]+\"|\"(?:federated_)?(?:group|team|user){1}\/[a-z0-9_\-@\.\' \/:]+\"|\"matrix\/@[a-z0-9_\-\.=\/+]+:[a-z0-9\-\.:\[\]]+\"|\"[a-z0-9_\-@\.\' ]+\"|[a-z0-9_\-@\.\']+)/i", $message, $mentions);
if (!$ok || !isset($mentions[0])) {
return [];
}
Expand Down Expand Up @@ -253,6 +254,10 @@ public function getMentions(bool $supportMarkdown = true): array {
/** @var non-empty-lowercase-string $cleanId */
$cleanId = substr($cleanId, 15);
$result[] = ['type' => 'federated_user', 'id' => $cleanId];
} elseif (str_starts_with($cleanId, 'matrix/')) {
/** @var non-empty-lowercase-string $cleanId */
$cleanId = substr($cleanId, 7);
$result[] = ['type' => 'matrix', 'id' => $cleanId];
} else {
$result[] = ['type' => 'user', 'id' => $cleanId];
}
Expand Down
3 changes: 2 additions & 1 deletion lib/public/Comments/IComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH);
*
* @param bool $supportMarkdown
* @return array each mention provides a 'type' and an 'id', see example below
* @psalm-return list<array{type: 'guest'|'email'|'federated_group'|'group'|'federated_team'|'team'|'federated_user'|'user', id: non-empty-lowercase-string}>
* @psalm-return list<array{type: 'guest'|'email'|'federated_group'|'group'|'federated_team'|'team'|'federated_user'|'matrix'|'user', id: non-empty-lowercase-string}>
* @since 36.0.0 Type 'matrix' is supported
* @since 33.0.1 Parameter $supportMarkdown was added to decide if mentions inside markdown code blocks should be ignored (default to true)
* @since 30.0.2 Type 'email' is supported
* @since 29.0.0 Types 'federated_group', 'federated_team', 'team' and 'federated_user' are supported
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/Comments/CommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ public static function mentionsProvider(): array {
"Mention @alice but not in unclosed tilde code block\n~~~\n@bob",
[['type' => 'user', 'id' => 'alice']],
],
[
'Matrix users @"matrix/@bob:example.org" and @"matrix/@carol.c=1/x+y:[2001:db8::1]:8448" but not @"matrix/@dave" or @"matrix/eve:example.org"',
[['type' => 'matrix', 'id' => '@carol.c=1/x+y:[2001:db8::1]:8448'], ['type' => 'matrix', 'id' => '@bob:example.org']],
],
];
}

Expand Down
Loading