Update ICommentsManager with reaction methods

Fix psalm errors
Reorder methods and remove return null
Use best pattern on docblock

Goals: update https://github.com/ChristophWurst/nextcloud_composer/ with reaction methods.
The script
https://github.com/ChristophWurst/nextcloud_composer/blob/master/build.sh
only get lib/public classes

Signed-off-by: Vitor Mattos <vitor@php.rio>
pull/30888/head
Vitor Mattos 2022-01-27 13:07:48 +07:00
parent d635d58d19
commit 8ec7c5c8ae
No known key found for this signature in database
GPG Key ID: B7AB4B76A7CA7318
3 changed files with 107 additions and 34 deletions

@ -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
@ -996,15 +996,47 @@ class Manager implements ICommentsManager {
return $this->get($messageId);
}
/**
* 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 {
@ -1046,39 +1078,10 @@ 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
*/

@ -29,6 +29,7 @@
namespace OCP\Comments;
use OCP\IUser;
use OCP\PreConditionNotMetException;
/**
* Interface ICommentsManager
@ -300,6 +301,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
*

@ -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) {
}