diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index c239958b08060..a5f7526580183 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -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 + * @psalm-return list + * @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 @@ -213,7 +214,7 @@ public function getMentions(bool $supportMarkdown = true): array { $message = preg_replace('/`[^`\n]*`/', '', $message); } - $ok = preg_match_all("/\B(? '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]; } diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php index be43ace5df25d..8decb76d56fc6 100644 --- a/lib/public/Comments/IComment.php +++ b/lib/public/Comments/IComment.php @@ -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 + * @psalm-return list + * @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 diff --git a/tests/lib/Comments/CommentTest.php b/tests/lib/Comments/CommentTest.php index 011ae43ccfb78..26f0c8f4020f5 100644 --- a/tests/lib/Comments/CommentTest.php +++ b/tests/lib/Comments/CommentTest.php @@ -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']], + ], ]; }