diff options
-rw-r--r-- | lib/private/Comments/Manager.php | 71 | ||||
-rw-r--r-- | lib/public/Comments/ICommentsManager.php | 53 | ||||
-rw-r--r-- | tests/lib/Comments/FakeManager.php | 17 |
3 files changed, 107 insertions, 34 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index 554a2485965..7c312b18f7d 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -969,7 +969,7 @@ class Manager implements ICommentsManager { * Throws PreConditionNotMetException when the system haven't the minimum requirements to * use reactions * - * @param integer $parentId + * @param int $parentId * @param string $actorType * @param string $actorId * @param string $reaction @@ -997,14 +997,46 @@ class Manager implements ICommentsManager { } /** + * Retrieve all reactions of a message + * + * Throws PreConditionNotMetException when the system haven't the minimum requirements to + * use reactions + * + * @param int $parentId + * @return IComment[] + * @throws PreConditionNotMetException + * @since 24.0.0 + */ + public function retrieveAllReactions(int $parentId): array { + $this->throwIfNotSupportReactions(); + $qb = $this->dbConn->getQueryBuilder(); + $result = $qb + ->select('message_id') + ->from('reactions') + ->where($qb->expr()->eq('parent_id', $qb->createNamedParameter($parentId))) + ->executeQuery(); + + $commentIds = []; + while ($data = $result->fetch()) { + $commentIds[] = $data['message_id']; + } + + return $this->getCommentsById($commentIds); + } + + /** * Retrieve all reactions with specific reaction of a message * - * @param integer $parentId + * Throws PreConditionNotMetException when the system haven't the minimum requirements to + * use reactions + * + * @param int $parentId * @param string $reaction * @return IComment[] + * @throws PreConditionNotMetException * @since 24.0.0 */ - public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $reaction): ?array { + public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $reaction): array { $this->throwIfNotSupportReactions(); $qb = $this->dbConn->getQueryBuilder(); $result = $qb @@ -1029,7 +1061,7 @@ class Manager implements ICommentsManager { /** * Support reactions * - * @return boolean + * @return bool * @since 24.0.0 */ public function supportReactions(): bool { @@ -1047,38 +1079,9 @@ class Manager implements ICommentsManager { } /** - * Retrieve all reactions of a message - * - * Throws PreConditionNotMetException when the system haven't the minimum requirements to - * use reactions - * - * @param integer $parentId - * @param string $reaction - * @throws PreConditionNotMetException - * @return IComment[] - * @since 24.0.0 - */ - public function retrieveAllReactions(int $parentId): array { - $this->throwIfNotSupportReactions(); - $qb = $this->dbConn->getQueryBuilder(); - $result = $qb - ->select('message_id') - ->from('reactions') - ->where($qb->expr()->eq('parent_id', $qb->createNamedParameter($parentId))) - ->executeQuery(); - - $commentIds = []; - while ($data = $result->fetch()) { - $commentIds[] = $data['message_id']; - } - - return $this->getCommentsById($commentIds); - } - - /** * Get all comments on list * - * @param integer[] $commentIds + * @param int[] $commentIds * @return IComment[] * @since 24.0.0 */ diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php index 178401056c7..c34bd4718cc 100644 --- a/lib/public/Comments/ICommentsManager.php +++ b/lib/public/Comments/ICommentsManager.php @@ -29,6 +29,7 @@ namespace OCP\Comments; use OCP\IUser; +use OCP\PreConditionNotMetException; /** * Interface ICommentsManager @@ -301,6 +302,58 @@ interface ICommentsManager { public function delete($id); /** + * Get comment related with user reaction + * + * Throws PreConditionNotMetException when the system haven't the minimum requirements to + * use reactions + * + * @param int $parentId + * @param string $actorType + * @param string $actorId + * @param string $reaction + * @return IComment + * @throws NotFoundException + * @throws PreConditionNotMetException + * @since 24.0.0 + */ + public function getReactionComment(int $parentId, string $actorType, string $actorId, string $reaction): IComment; + + /** + * Retrieve all reactions of a message + * + * Throws PreConditionNotMetException when the system haven't the minimum requirements to + * use reactions + * + * @param int $parentId + * @return IComment[] + * @throws PreConditionNotMetException + * @since 24.0.0 + */ + public function retrieveAllReactions(int $parentId): array; + + /** + * Retrieve all reactions with specific reaction of a message + * + * Throws PreConditionNotMetException when the system haven't the minimum requirements to + * use reactions + * + * @param int $parentId + * @param string $reaction + * @return IComment[] + * @throws PreConditionNotMetException + * @since 24.0.0 + */ + public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $reaction): array; + + /** + * Support reactions + * + * @return bool + * @since 24.0.0 + */ + public function supportReactions(): bool; + + /** * saves the comment permanently * * if the supplied comment has an empty ID, a new entry comment will be diff --git a/tests/lib/Comments/FakeManager.php b/tests/lib/Comments/FakeManager.php index fbd13bd5193..5406df96a96 100644 --- a/tests/lib/Comments/FakeManager.php +++ b/tests/lib/Comments/FakeManager.php @@ -2,6 +2,7 @@ namespace Test\Comments; +use OC\Comments\Comment; use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; use OCP\IUser; @@ -61,6 +62,22 @@ class FakeManager implements ICommentsManager { public function delete($id) { } + public function getReactionComment(int $parentId, string $actorType, string $actorId, string $reaction): IComment { + return new Comment(); + } + + public function retrieveAllReactions(int $parentId): array { + return []; + } + + public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $reaction): array { + return []; + } + + public function supportReactions(): bool { + return false; + } + public function save(IComment $comment) { } |