From bd30a7ac21bf63cfc117f1fe7798d82978a879ee Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Oct 2024 12:34:18 +0200 Subject: [PATCH 1/3] feat(comments): Support mentioning emails Signed-off-by: Joas Schilling --- lib/private/Comments/Comment.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 1090cf6707849..11b7fb03dc14f 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -202,7 +202,7 @@ public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH): ICo * */ public function getMentions(): array { - $ok = preg_match_all("/\B(?getMessage(), $mentions); + $ok = preg_match_all("/\B(?getMessage(), $mentions); if (!$ok || !isset($mentions[0])) { return []; } @@ -217,6 +217,10 @@ public function getMentions(): array { if (str_starts_with($cleanId, 'guest/')) { $result[] = ['type' => 'guest', 'id' => $cleanId]; + } elseif (str_starts_with($cleanId, 'email/')) { + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 6); + $result[] = ['type' => 'email', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'federated_group/')) { $result[] = ['type' => 'federated_group', 'id' => substr($cleanId, 16)]; } elseif (str_starts_with($cleanId, 'group/')) { From 570428e4e694114529b99e137290870b208751de Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Oct 2024 12:37:14 +0200 Subject: [PATCH 2/3] fix(comments): Document supported types and provide psalm typing Signed-off-by: Joas Schilling --- lib/private/Comments/Comment.php | 40 +++++++++++++++++--------------- lib/public/Comments/IComment.php | 19 ++++----------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 11b7fb03dc14f..c240a5411560e 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -185,21 +185,12 @@ 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 - * - * The return array looks like: - * [ - * [ - * 'type' => 'user', - * 'id' => 'citizen4' - * ], - * [ - * 'type' => 'group', - * 'id' => 'media' - * ], - * … - * ] - * */ public function getMentions(): array { $ok = preg_match_all("/\B(?getMessage(), $mentions); @@ -213,6 +204,7 @@ public function getMentions(): array { $result = []; foreach ($mentionIds as $mentionId) { // Cut-off the @ and remove wrapping double-quotes + /** @var non-empty-lowercase-string $cleanId */ $cleanId = trim(substr($mentionId, 1), '"'); if (str_starts_with($cleanId, 'guest/')) { @@ -222,15 +214,25 @@ public function getMentions(): array { $cleanId = substr($cleanId, 6); $result[] = ['type' => 'email', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'federated_group/')) { - $result[] = ['type' => 'federated_group', 'id' => substr($cleanId, 16)]; + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 16); + $result[] = ['type' => 'federated_group', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'group/')) { - $result[] = ['type' => 'group', 'id' => substr($cleanId, 6)]; + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 6); + $result[] = ['type' => 'group', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'federated_team/')) { - $result[] = ['type' => 'federated_team', 'id' => substr($cleanId, 15)]; + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 15); + $result[] = ['type' => 'federated_team', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'team/')) { - $result[] = ['type' => 'team', 'id' => substr($cleanId, 5)]; + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 5); + $result[] = ['type' => 'team', 'id' => $cleanId]; } elseif (str_starts_with($cleanId, 'federated_user/')) { - $result[] = ['type' => 'federated_user', 'id' => substr($cleanId, 15)]; + /** @var non-empty-lowercase-string $cleanId */ + $cleanId = substr($cleanId, 15); + $result[] = ['type' => 'federated_user', 'id' => $cleanId]; } else { $result[] = ['type' => 'user', 'id' => $cleanId]; } diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php index e37a3ee9757b4..cdfcf188761be 100644 --- a/lib/public/Comments/IComment.php +++ b/lib/public/Comments/IComment.php @@ -124,21 +124,12 @@ public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH); * 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 - * - * The return array looks like: - * [ - * [ - * 'type' => 'user', - * 'id' => 'citizen4' - * ], - * [ - * 'type' => 'group', - * 'id' => 'media' - * ], - * … - * ] - * */ public function getMentions(); From 498c3dc5666c74a6c0a2b41032aa5c9dfe680f5d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Oct 2024 07:39:41 +0200 Subject: [PATCH 3/3] fix(comments): Add test for email mention Signed-off-by: Joas Schilling --- tests/lib/Comments/CommentTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/lib/Comments/CommentTest.php b/tests/lib/Comments/CommentTest.php index feaa268a09e0c..2313c192297bb 100644 --- a/tests/lib/Comments/CommentTest.php +++ b/tests/lib/Comments/CommentTest.php @@ -196,6 +196,12 @@ public function mentionsProvider(): array { ['type' => 'federated_team', 'id' => 'Former Cirle'], ], ], + [ + 'Emails are supported since 30.0.2 right? @"email/aa23d315de327cfc330f0401ea061005b2b0cdd45ec8346f12664dd1f34cb886"', + [ + ['type' => 'email', 'id' => 'aa23d315de327cfc330f0401ea061005b2b0cdd45ec8346f12664dd1f34cb886'], + ], + ], ]; }