Skip to content

Commit 8353789

Browse files
Merge pull request #8035 from nextcloud/backport/7894/stable33
[stable33] fix(comments): register event listener for typed comment events
2 parents b7fd93e + 47ad725 commit 8353789

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

lib/AppInfo/Application.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
5858
use OCP\Collaboration\Resources\IProviderManager;
5959
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
6060
use OCP\Comments\CommentsEntityEvent;
61-
use OCP\Comments\CommentsEvent;
61+
use OCP\Comments\Events\BeforeCommentUpdatedEvent;
62+
use OCP\Comments\Events\CommentAddedEvent;
63+
use OCP\Comments\Events\CommentDeletedEvent;
64+
use OCP\Comments\Events\CommentUpdatedEvent;
6265
use OCP\EventDispatcher\IEventDispatcher;
6366
use OCP\Group\Events\GroupDeletedEvent;
6467
use OCP\IConfig;
@@ -146,7 +149,10 @@ public function register(IRegistrationContext $context): void {
146149
$context->registerEventListener(AclCreatedEvent::class, FullTextSearchEventListener::class);
147150
$context->registerEventListener(AclUpdatedEvent::class, FullTextSearchEventListener::class);
148151
$context->registerEventListener(AclDeletedEvent::class, FullTextSearchEventListener::class);
149-
$context->registerEventListener(CommentsEvent::class, CommentEventListener::class);
152+
$context->registerEventListener(CommentAddedEvent::class, CommentEventListener::class);
153+
$context->registerEventListener(BeforeCommentUpdatedEvent::class, CommentEventListener::class);
154+
$context->registerEventListener(CommentUpdatedEvent::class, CommentEventListener::class);
155+
$context->registerEventListener(CommentDeletedEvent::class, CommentEventListener::class);
150156

151157
// Handling cache invalidation for collections
152158
$context->registerEventListener(AclCreatedEvent::class, ResourceListener::class);

tests/unit/Listeners/CommentEventListenerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
use OCA\Deck\Db\CardMapper;
3030
use OCA\Deck\Db\ChangeHelper;
3131
use OCA\Deck\Notification\NotificationHelper;
32-
use OCP\Comments\CommentsEvent;
32+
use OCP\Comments\Events\CommentAddedEvent;
33+
use OCP\Comments\Events\CommentUpdatedEvent;
3334
use OCP\Comments\IComment;
3435
use PHPUnit\Framework\TestCase;
3536

@@ -68,7 +69,7 @@ public function testHandle() {
6869
$this->cardMapper->expects($this->once())
6970
->method('find')
7071
->willReturn($card);
71-
$commentsEvent = new CommentsEvent(CommentsEvent::EVENT_ADD, $comment);
72+
$commentsEvent = new CommentAddedEvent($comment);
7273
$this->activityManager->expects($this->once())
7374
->method('triggerEvent')
7475
->with(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_COMMENT_CREATE, ['comment' => $comment]);
@@ -82,7 +83,7 @@ public function testHandleUpdate() {
8283
$comment = $this->createMock(IComment::class);
8384
$comment->expects($this->any())->method('getId')->willReturn(1);
8485
$comment->expects($this->any())->method('getObjectType')->willReturn('deckCard');
85-
$commentsEvent = new CommentsEvent(CommentsEvent::EVENT_UPDATE, $comment);
86+
$commentsEvent = new CommentUpdatedEvent($comment);
8687
$this->activityManager->expects($this->never())
8788
->method('triggerEvent');
8889
$this->notificationHelper->expects($this->once())
@@ -95,7 +96,7 @@ public function testHandleInvalid() {
9596
$comment = $this->createMock(IComment::class);
9697
$comment->expects($this->any())->method('getId')->willReturn(1);
9798
$comment->expects($this->any())->method('getObjectType')->willReturn('other');
98-
$commentsEvent = new CommentsEvent(CommentsEvent::EVENT_ADD, $comment);
99+
$commentsEvent = new CommentAddedEvent($comment);
99100
$this->activityManager->expects($this->never())
100101
->method('triggerEvent');
101102
$this->commentEventHandler->handle($commentsEvent);

0 commit comments

Comments
 (0)