Add backend support for comments
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -41,6 +41,7 @@ use OCP\Activity\IEvent;
|
|||||||
use OCP\Activity\IManager;
|
use OCP\Activity\IManager;
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||||
|
use OCP\Comments\IComment;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
|
|
||||||
@@ -98,6 +99,8 @@ class ActivityManager {
|
|||||||
const SUBJECT_LABEL_ASSIGN = 'label_assign';
|
const SUBJECT_LABEL_ASSIGN = 'label_assign';
|
||||||
const SUBJECT_LABEL_UNASSING = 'label_unassign';
|
const SUBJECT_LABEL_UNASSING = 'label_unassign';
|
||||||
|
|
||||||
|
const SUBJECT_CARD_COMMENT_CREATE = 'card_comment_create';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IManager $manager,
|
IManager $manager,
|
||||||
PermissionService $permissionsService,
|
PermissionService $permissionsService,
|
||||||
@@ -227,6 +230,9 @@ class ActivityManager {
|
|||||||
case self::SUBJECT_ATTACHMENT_RESTORE:
|
case self::SUBJECT_ATTACHMENT_RESTORE:
|
||||||
$subject = $ownActivity ? $this->l10n->t('You have restored the attachment {attachment} to {card}') : $this->l10n->t('{user} has restored the attachment {attachment} to {card}');
|
$subject = $ownActivity ? $this->l10n->t('You have restored the attachment {attachment} to {card}') : $this->l10n->t('{user} has restored the attachment {attachment} to {card}');
|
||||||
break;
|
break;
|
||||||
|
case self::SUBJECT_CARD_COMMENT_CREATE:
|
||||||
|
$subject = $ownActivity ? $this->l10n->t('You have commented on {card}') : $this->l10n->t('{user} has commented on {card}');
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -315,6 +321,13 @@ class ActivityManager {
|
|||||||
// Not defined as there is no activity for
|
// Not defined as there is no activity for
|
||||||
// case self::SUBJECT_BOARD_UPDATE_COLOR
|
// case self::SUBJECT_BOARD_UPDATE_COLOR
|
||||||
break;
|
break;
|
||||||
|
case self::SUBJECT_CARD_COMMENT_CREATE:
|
||||||
|
/** @var IComment $entity */
|
||||||
|
$subjectParams = [
|
||||||
|
'comment' => $entity->getMessage()
|
||||||
|
];
|
||||||
|
$message = $entity->getMessage();
|
||||||
|
break;
|
||||||
|
|
||||||
case self::SUBJECT_STACK_CREATE:
|
case self::SUBJECT_STACK_CREATE:
|
||||||
case self::SUBJECT_STACK_UPDATE:
|
case self::SUBJECT_STACK_UPDATE:
|
||||||
@@ -409,6 +422,9 @@ class ActivityManager {
|
|||||||
*/
|
*/
|
||||||
private function findObjectForEntity($objectType, $entity) {
|
private function findObjectForEntity($objectType, $entity) {
|
||||||
$className = \get_class($entity);
|
$className = \get_class($entity);
|
||||||
|
if ($entity instanceof IComment) {
|
||||||
|
$className = IComment::class;
|
||||||
|
}
|
||||||
$objectId = null;
|
$objectId = null;
|
||||||
if ($objectType === self::DECK_OBJECT_CARD) {
|
if ($objectType === self::DECK_OBJECT_CARD) {
|
||||||
switch ($className) {
|
switch ($className) {
|
||||||
@@ -420,6 +436,9 @@ class ActivityManager {
|
|||||||
case AssignedUsers::class:
|
case AssignedUsers::class:
|
||||||
$objectId = $entity->getCardId();
|
$objectId = $entity->getCardId();
|
||||||
break;
|
break;
|
||||||
|
case IComment::class:
|
||||||
|
$objectId = $entity->getObjectId();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new InvalidArgumentException('No entity relation present for '. $className . ' to ' . $objectType);
|
throw new InvalidArgumentException('No entity relation present for '. $className . ' to ' . $objectType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use cogpowered\FineDiff\Diff;
|
|||||||
use OCA\Deck\Db\Acl;
|
use OCA\Deck\Db\Acl;
|
||||||
use OCP\Activity\IEvent;
|
use OCP\Activity\IEvent;
|
||||||
use OCP\Activity\IProvider;
|
use OCP\Activity\IProvider;
|
||||||
|
use OCP\Comments\IComment;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
|
||||||
@@ -106,7 +107,7 @@ class DeckProvider implements IProvider {
|
|||||||
'type' => 'user',
|
'type' => 'user',
|
||||||
'id' => $author,
|
'id' => $author,
|
||||||
'name' => $user !== null ? $user->getDisplayName() : $author
|
'name' => $user !== null ? $user->getDisplayName() : $author
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$params = $this->parseParamForBoard('board', $subjectParams, $params);
|
$params = $this->parseParamForBoard('board', $subjectParams, $params);
|
||||||
@@ -117,6 +118,7 @@ class DeckProvider implements IProvider {
|
|||||||
$params = $this->parseParamForAssignedUser($subjectParams, $params);
|
$params = $this->parseParamForAssignedUser($subjectParams, $params);
|
||||||
$params = $this->parseParamForAcl($subjectParams, $params);
|
$params = $this->parseParamForAcl($subjectParams, $params);
|
||||||
$params = $this->parseParamForChanges($subjectParams, $params, $event);
|
$params = $this->parseParamForChanges($subjectParams, $params, $event);
|
||||||
|
$params = $this->parseParamForComment($subjectParams, $params, $event);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$subject = $this->activityManager->getActivityFormat($subjectIdentifier, $subjectParams, $ownActivity);
|
$subject = $this->activityManager->getActivityFormat($subjectIdentifier, $subjectParams, $ownActivity);
|
||||||
@@ -147,6 +149,9 @@ class DeckProvider implements IProvider {
|
|||||||
if (strpos($event->getSubject(), 'attachment_') !== false) {
|
if (strpos($event->getSubject(), 'attachment_') !== false) {
|
||||||
$event->setIcon($this->urlGenerator->imagePath('core', 'places/files.svg'));
|
$event->setIcon($this->urlGenerator->imagePath('core', 'places/files.svg'));
|
||||||
}
|
}
|
||||||
|
if (strpos($event->getSubject(), 'comment_') !== false) {
|
||||||
|
$event->setIcon($this->urlGenerator->imagePath('core', 'actions/comment.svg'));
|
||||||
|
}
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +232,16 @@ class DeckProvider implements IProvider {
|
|||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function parseParamForComment($subjectParams, $params, IEvent $event) {
|
||||||
|
if (array_key_exists('comment', $subjectParams)) {
|
||||||
|
/** @var IComment $comment */
|
||||||
|
$comment = \OC::$server->getCommentsManager()->get((int) $subjectParams['comment']);
|
||||||
|
$event->setParsedMessage($comment->getMessage());
|
||||||
|
}
|
||||||
|
$params['comment'] = $subjectParams['comment'];
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add diff to message if the subject parameter 'diff' is set, otherwise
|
* Add diff to message if the subject parameter 'diff' is set, otherwise
|
||||||
* the changed values are added to before/after
|
* the changed values are added to before/after
|
||||||
|
|||||||
@@ -23,12 +23,15 @@
|
|||||||
|
|
||||||
namespace OCA\Deck\AppInfo;
|
namespace OCA\Deck\AppInfo;
|
||||||
|
|
||||||
|
use OCA\Deck\Activity\CommentEventHandler;
|
||||||
use OCA\Deck\Db\Acl;
|
use OCA\Deck\Db\Acl;
|
||||||
use OCA\Deck\Db\AclMapper;
|
use OCA\Deck\Db\AclMapper;
|
||||||
use OCA\Deck\Db\AssignedUsersMapper;
|
use OCA\Deck\Db\AssignedUsersMapper;
|
||||||
|
use OCA\Deck\Db\CardMapper;
|
||||||
use OCA\Deck\Notification\Notifier;
|
use OCA\Deck\Notification\Notifier;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
use OCA\Deck\Middleware\SharingMiddleware;
|
use OCA\Deck\Middleware\SharingMiddleware;
|
||||||
|
use OCP\Comments\CommentsEntityEvent;
|
||||||
use OCP\IGroup;
|
use OCP\IGroup;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
@@ -120,6 +123,27 @@ class Application extends App {
|
|||||||
}, function() {
|
}, function() {
|
||||||
return ['id' => 'deck', 'name' => 'Deck'];
|
return ['id' => 'deck', 'name' => 'Deck'];
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerCommentsEntity() {
|
||||||
|
$this->getContainer()->getServer()->getEventDispatcher()->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) {
|
||||||
|
$event->addEntityCollection('deckCard', function($name) {
|
||||||
|
/** @var CardMapper */
|
||||||
|
$service = $this->getContainer()->query(CardMapper::class);
|
||||||
|
try {
|
||||||
|
$card = $service->find((int) $name);
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$this->registerCommentsEventHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerCommentsEventHandler() {
|
||||||
|
$this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () {
|
||||||
|
return $this->getContainer()->query(CommentEventHandler::class);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class Card extends RelationalEntity {
|
|||||||
protected $duedate;
|
protected $duedate;
|
||||||
protected $notified = false;
|
protected $notified = false;
|
||||||
protected $deletedAt = 0;
|
protected $deletedAt = 0;
|
||||||
|
protected $commentsUnread = 0;
|
||||||
|
|
||||||
private $databaseType = 'sqlite';
|
private $databaseType = 'sqlite';
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ class Card extends RelationalEntity {
|
|||||||
$this->addRelation('attachments');
|
$this->addRelation('attachments');
|
||||||
$this->addRelation('attachmentCount');
|
$this->addRelation('attachmentCount');
|
||||||
$this->addRelation('participants');
|
$this->addRelation('participants');
|
||||||
|
$this->addRelation('commentsUnread');
|
||||||
$this->addResolvable('owner');
|
$this->addResolvable('owner');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,11 @@ class CardService {
|
|||||||
$card->setAssignedUsers($this->assignedUsersMapper->find($cardId));
|
$card->setAssignedUsers($this->assignedUsersMapper->find($cardId));
|
||||||
$card->setLabels($this->labelMapper->findAssignedLabelsForCard($cardId));
|
$card->setLabels($this->labelMapper->findAssignedLabelsForCard($cardId));
|
||||||
$card->setAttachmentCount($this->attachmentService->count($cardId));
|
$card->setAttachmentCount($this->attachmentService->count($cardId));
|
||||||
|
/** @var ICommentsManager commentsManager */
|
||||||
|
$this->commentsManager = \OC::$server->getCommentsManager();
|
||||||
|
$lastRead = $this->commentsManager->getReadMark('deckCard', (string)$card->getId(), \OC::$server->getUserSession()->getUser());
|
||||||
|
$count = $this->commentsManager->getNumberOfCommentsForObject('deckCard', (string)$card->getId(), $lastRead);
|
||||||
|
$card->setCommentsUnread($count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchDeleted($boardId) {
|
public function fetchDeleted($boardId) {
|
||||||
@@ -114,6 +119,7 @@ class CardService {
|
|||||||
$attachments = $this->attachmentService->findAll($cardId, true);
|
$attachments = $this->attachmentService->findAll($cardId, true);
|
||||||
$card->setAssignedUsers($assignedUsers);
|
$card->setAssignedUsers($assignedUsers);
|
||||||
$card->setAttachments($attachments);
|
$card->setAttachments($attachments);
|
||||||
|
$this->enrich($card);
|
||||||
return $card;
|
return $card;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ use OCA\Deck\Db\Stack;
|
|||||||
use OCA\Deck\Db\StackMapper;
|
use OCA\Deck\Db\StackMapper;
|
||||||
use OCA\Deck\StatusException;
|
use OCA\Deck\StatusException;
|
||||||
use OCA\Deck\BadRequestException;
|
use OCA\Deck\BadRequestException;
|
||||||
|
use OCP\Comments\ICommentsManager;
|
||||||
|
|
||||||
|
|
||||||
class StackService {
|
class StackService {
|
||||||
|
|||||||
Reference in New Issue
Block a user