Add backend support for comments

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-10-04 17:29:28 +02:00
parent 10c09927e2
commit d3027acd37
6 changed files with 68 additions and 1 deletions

View File

@@ -41,6 +41,7 @@ use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\Comments\IComment;
use OCP\IL10N;
use OCP\IUser;
@@ -98,6 +99,8 @@ class ActivityManager {
const SUBJECT_LABEL_ASSIGN = 'label_assign';
const SUBJECT_LABEL_UNASSING = 'label_unassign';
const SUBJECT_CARD_COMMENT_CREATE = 'card_comment_create';
public function __construct(
IManager $manager,
PermissionService $permissionsService,
@@ -227,6 +230,9 @@ class ActivityManager {
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}');
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:
break;
}
@@ -315,6 +321,13 @@ class ActivityManager {
// Not defined as there is no activity for
// case self::SUBJECT_BOARD_UPDATE_COLOR
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_UPDATE:
@@ -409,6 +422,9 @@ class ActivityManager {
*/
private function findObjectForEntity($objectType, $entity) {
$className = \get_class($entity);
if ($entity instanceof IComment) {
$className = IComment::class;
}
$objectId = null;
if ($objectType === self::DECK_OBJECT_CARD) {
switch ($className) {
@@ -420,6 +436,9 @@ class ActivityManager {
case AssignedUsers::class:
$objectId = $entity->getCardId();
break;
case IComment::class:
$objectId = $entity->getObjectId();
break;
default:
throw new InvalidArgumentException('No entity relation present for '. $className . ' to ' . $objectType);
}

View File

@@ -28,6 +28,7 @@ use cogpowered\FineDiff\Diff;
use OCA\Deck\Db\Acl;
use OCP\Activity\IEvent;
use OCP\Activity\IProvider;
use OCP\Comments\IComment;
use OCP\IURLGenerator;
use OCP\IUserManager;
@@ -106,7 +107,7 @@ class DeckProvider implements IProvider {
'type' => 'user',
'id' => $author,
'name' => $user !== null ? $user->getDisplayName() : $author
]
],
];
$params = $this->parseParamForBoard('board', $subjectParams, $params);
@@ -117,6 +118,7 @@ class DeckProvider implements IProvider {
$params = $this->parseParamForAssignedUser($subjectParams, $params);
$params = $this->parseParamForAcl($subjectParams, $params);
$params = $this->parseParamForChanges($subjectParams, $params, $event);
$params = $this->parseParamForComment($subjectParams, $params, $event);
try {
$subject = $this->activityManager->getActivityFormat($subjectIdentifier, $subjectParams, $ownActivity);
@@ -147,6 +149,9 @@ class DeckProvider implements IProvider {
if (strpos($event->getSubject(), 'attachment_') !== false) {
$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;
}
@@ -227,6 +232,16 @@ class DeckProvider implements IProvider {
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
* the changed values are added to before/after