From 2d6ac6ad742e76343c9d1696cacbca78c8ac1fe7 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 3 Nov 2025 10:48:43 -0500 Subject: [PATCH 1/2] chore: Update docblock for getMentions method Updated the docblock for the getMentions method to clarify its return value and sorting behavior. Signed-off-by: Josh --- lib/public/Comments/IComment.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php index cdfcf188761be..dfe3bacb1a687 100644 --- a/lib/public/Comments/IComment.php +++ b/lib/public/Comments/IComment.php @@ -121,13 +121,19 @@ public function getMessage(); public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH); /** - * returns an array containing mentions that are included in the comment + * Returns all mentions from the comment message. * - * @return array each mention provides a 'type' and an 'id', see example below + * Parses the message, returning an array of mentions. + * Mentions are sorted by descending length of their id before being returned. + * + * Supported mention types: 'user', 'group', 'team', 'guest', 'email', 'federated_group', 'federated_team', 'federated_user'. + * + * @return array Each mention is an associative array with 'type' and 'id' keys, sorted by descending length. * @psalm-return list * @since 30.0.2 Type 'email' is supported * @since 29.0.0 Types 'federated_group', 'federated_team', 'team' and 'federated_user' are supported * @since 23.0.0 Type 'group' is supported + * @since 21.0.1 Sort returned results by * @since 17.0.0 Type 'guest' is supported * @since 11.0.0 */ From 2f2abb09a1e4ea3f3832f3931b3ddc70c8415b08 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 3 Nov 2025 10:52:07 -0500 Subject: [PATCH 2/2] fix(Comments): sort by id (not type+id) in getMentions Updated the getMentions method to inherit documentation and change sorting logic. Signed-off-by: Josh --- lib/private/Comments/Comment.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 7190f252c8232..90d4bbddd72e7 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -182,15 +182,7 @@ public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH): ICo } /** - * returns an array containing mentions that are included in the comment - * - * @return array each mention provides a 'type' and an 'id', see example below - * @psalm-return list - * @since 30.0.2 Type 'email' is supported - * @since 29.0.0 Types 'federated_group', 'federated_team', 'team' and 'federated_user' are supported - * @since 23.0.0 Type 'group' is supported - * @since 17.0.0 Type 'guest' is supported - * @since 11.0.0 + * @inheritDoc */ public function getMentions(): array { $ok = preg_match_all("/\B(?getMessage(), $mentions); @@ -198,9 +190,6 @@ public function getMentions(): array { return []; } $mentionIds = array_unique($mentions[0]); - usort($mentionIds, static function ($mentionId1, $mentionId2) { - return mb_strlen($mentionId2) <=> mb_strlen($mentionId1); - }); $result = []; foreach ($mentionIds as $mentionId) { // Cut-off the @ and remove wrapping double-quotes @@ -237,6 +226,10 @@ public function getMentions(): array { $result[] = ['type' => 'user', 'id' => $cleanId]; } } + // Return sorted by id (descending length) + usort($result, static function ($mention1, $mention2) { + return mb_strlen($mention2['id']) <=> mb_strlen($mention1['id']); + }); return $result; }