Merge pull request #761 from nextcloud/bugfix/721/activity-fix

Fix information in activity emails
This commit is contained in:
Julius Härtl
2018-12-04 13:46:16 +01:00
committed by GitHub
5 changed files with 45 additions and 11 deletions
+10 -5
View File
@@ -322,11 +322,13 @@ class ActivityManager {
// case self::SUBJECT_BOARD_UPDATE_COLOR // case self::SUBJECT_BOARD_UPDATE_COLOR
break; break;
case self::SUBJECT_CARD_COMMENT_CREATE: case self::SUBJECT_CARD_COMMENT_CREATE:
/** @var IComment $entity */ $subjectParams = $this->findDetailsForCard($entity->getId());
$subjectParams = [ if (array_key_exists('comment', $additionalParams)) {
'comment' => $entity->getMessage() /** @var IComment $entity */
]; $comment = $additionalParams['comment'];
$message = '{comment}'; $subjectParams['comment'] = $comment->getId();
unset($additionalParams['comment']);
}
break; break;
case self::SUBJECT_STACK_CREATE: case self::SUBJECT_STACK_CREATE:
@@ -375,6 +377,9 @@ class ActivityManager {
$subjectParams['stackBefore'] = $this->stackMapper->find($additionalParams['before']); $subjectParams['stackBefore'] = $this->stackMapper->find($additionalParams['before']);
} }
$subjectParams['author'] = $this->userId;
$event = $this->manager->generateEvent(); $event = $this->manager->generateEvent();
$event->setApp('deck') $event->setApp('deck')
->setType('deck') ->setType('deck')
+10 -2
View File
@@ -23,8 +23,10 @@
namespace OCA\Deck\Activity; namespace OCA\Deck\Activity;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Notification\NotificationHelper;
use OCP\Comments\CommentsEvent; use OCP\Comments\CommentsEvent;
use OCP\Comments\IComment;
use \OCP\Comments\ICommentsEventHandler; use \OCP\Comments\ICommentsEventHandler;
class CommentEventHandler implements ICommentsEventHandler { class CommentEventHandler implements ICommentsEventHandler {
@@ -35,9 +37,13 @@ class CommentEventHandler implements ICommentsEventHandler {
/** @var NotificationHelper */ /** @var NotificationHelper */
private $notificationHelper; private $notificationHelper;
public function __construct(ActivityManager $activityManager, NotificationHelper $notificationHelper) { /** @var CardMapper */
private $cardMapper;
public function __construct(ActivityManager $activityManager, NotificationHelper $notificationHelper, CardMapper $cardMapper) {
$this->notificationHelper = $notificationHelper; $this->notificationHelper = $notificationHelper;
$this->activityManager = $activityManager; $this->activityManager = $activityManager;
$this->cardMapper = $cardMapper;
} }
/** /**
@@ -71,8 +77,10 @@ class CommentEventHandler implements ICommentsEventHandler {
* @param CommentsEvent $event * @param CommentsEvent $event
*/ */
private function activityHandler(CommentsEvent $event) { private function activityHandler(CommentsEvent $event) {
/** @var IComment $comment */
$comment = $event->getComment(); $comment = $event->getComment();
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $comment, ActivityManager::SUBJECT_CARD_COMMENT_CREATE, ['comment' => $comment->getId()]); $card = $this->cardMapper->find($comment->getObjectId());
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_COMMENT_CREATE, ['comment' => $comment]);
} }
+13 -1
View File
@@ -81,6 +81,11 @@ class DeckProvider implements IProvider {
*/ */
$author = $event->getAuthor(); $author = $event->getAuthor();
// get author if
if ($author === '' && array_key_exists('author', $subjectParams)) {
$author = $subjectParams['author'];
unset($subjectParams['author']);
}
$user = $this->userManager->get($author); $user = $this->userManager->get($author);
$params = [ $params = [
'user' => [ 'user' => [
@@ -90,6 +95,9 @@ class DeckProvider implements IProvider {
], ],
]; ];
if ($event->getObjectType() === ActivityManager::DECK_OBJECT_BOARD) { if ($event->getObjectType() === ActivityManager::DECK_OBJECT_BOARD) {
if ($event->getObjectName() === '') {
$event->setObject($event->getObjectType(), $event->getObjectId(), $subjectParams['board']['title']);
}
$board = [ $board = [
'type' => 'highlight', 'type' => 'highlight',
'id' => $event->getObjectId(), 'id' => $event->getObjectId(),
@@ -100,6 +108,9 @@ class DeckProvider implements IProvider {
} }
if ($event->getObjectType() === ActivityManager::DECK_OBJECT_CARD) { if ($event->getObjectType() === ActivityManager::DECK_OBJECT_CARD) {
if ($event->getObjectName() === '') {
$event->setObject($event->getObjectType(), $event->getObjectId(), $subjectParams['card']['title']);
}
$card = [ $card = [
'type' => 'highlight', 'type' => 'highlight',
'id' => $event->getObjectId(), 'id' => $event->getObjectId(),
@@ -149,6 +160,7 @@ class DeckProvider implements IProvider {
$event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) $event->setParsedSubject(str_replace($placeholders, $replacements, $subject))
->setRichSubject($subject, $parameters); ->setRichSubject($subject, $parameters);
$event->setSubject($subject, $parameters);
} }
private function getIcon(IEvent $event) { private function getIcon(IEvent $event) {
@@ -301,6 +313,6 @@ class DeckProvider implements IProvider {
} }
public function deckUrl($endpoint) { public function deckUrl($endpoint) {
return $this->urlGenerator->linkToRoute('deck.page.index') . '#!' . $endpoint; return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#!' . $endpoint;
} }
} }
@@ -53,13 +53,17 @@ class CommentEventHandlerTest extends TestCase {
private $activityManager; private $activityManager;
/** @var NotificationHelper */ /** @var NotificationHelper */
private $notificationHelper; private $notificationHelper;
/** @var CardMapper */
private $cardMapper;
public function setUp() { public function setUp() {
$this->activityManager = $this->createMock(ActivityManager::class); $this->activityManager = $this->createMock(ActivityManager::class);
$this->notificationHelper = $this->createMock(NotificationHelper::class); $this->notificationHelper = $this->createMock(NotificationHelper::class);
$this->cardMapper = $this->createMock(CardMapper::class);
$this->commentEventHandler = new CommentEventHandler( $this->commentEventHandler = new CommentEventHandler(
$this->activityManager, $this->activityManager,
$this->notificationHelper $this->notificationHelper,
$this->cardMapper
); );
} }
@@ -67,10 +71,15 @@ class CommentEventHandlerTest extends TestCase {
$comment = $this->createMock(IComment::class); $comment = $this->createMock(IComment::class);
$comment->expects($this->any())->method('getId')->willReturn(1); $comment->expects($this->any())->method('getId')->willReturn(1);
$comment->expects($this->any())->method('getObjectType')->willReturn('deckCard'); $comment->expects($this->any())->method('getObjectType')->willReturn('deckCard');
$comment->expects($this->any())->method('getMessage')->willReturn('Hello world');
$card = $this->createMock(Card::class);
$this->cardMapper->expects($this->once())
->method('find')
->willReturn($card);
$commentsEvent = new CommentsEvent(CommentsEvent::EVENT_ADD, $comment); $commentsEvent = new CommentsEvent(CommentsEvent::EVENT_ADD, $comment);
$this->activityManager->expects($this->once()) $this->activityManager->expects($this->once())
->method('triggerEvent') ->method('triggerEvent')
->with(ActivityManager::DECK_OBJECT_CARD, $comment, ActivityManager::SUBJECT_CARD_COMMENT_CREATE, ['comment' => 1]); ->with(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_COMMENT_CREATE, ['comment' => $comment]);
$this->notificationHelper->expects($this->once()) $this->notificationHelper->expects($this->once())
->method('sendMention') ->method('sendMention')
->with($comment); ->with($comment);
+1 -1
View File
@@ -139,7 +139,7 @@ class DeckProviderTest extends TestCase {
public function testDeckUrl() { public function testDeckUrl() {
$this->urlGenerator->expects($this->once()) $this->urlGenerator->expects($this->once())
->method('linkToRoute') ->method('linkToRouteAbsolute')
->with('deck.page.index') ->with('deck.page.index')
->willReturn('http://localhost/index.php/apps/deck/'); ->willReturn('http://localhost/index.php/apps/deck/');
$this->assertEquals( $this->assertEquals(