Skip to content

Commit 05284b6

Browse files
committed
fix(ContextChat): Listen for new db-level change events
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent a5c4c53 commit 05284b6

4 files changed

Lines changed: 44 additions & 5 deletions

File tree

lib/ContextChat/ContextChatProvider.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use OCA\Bookmarks\Db\TreeMapper;
1313
use OCA\Bookmarks\Events\BeforeDeleteEvent;
1414
use OCA\Bookmarks\Events\CreateEvent;
15+
use OCA\Bookmarks\Events\InsertEvent;
16+
use OCA\Bookmarks\Events\ManipulateEvent;
1517
use OCA\Bookmarks\Events\UpdateEvent;
1618
use OCA\Bookmarks\Service\BookmarkService;
1719
use OCA\ContextChat\Event\ContentProviderRegisterEvent;
@@ -39,10 +41,10 @@ public function __construct(
3941

4042
public function handle(Event $event): void {
4143
if ($event instanceof ContentProviderRegisterEvent) {
42-
$this->register($event);
44+
$this->register();
4345
return;
4446
}
45-
if ($event instanceof CreateEvent || $event instanceof UpdateEvent) {
47+
if ($event instanceof InsertEvent || $event instanceof ManipulateEvent) {
4648
if ($event->getType() !== TreeMapper::TYPE_BOOKMARK) {
4749
return;
4850
}
@@ -70,8 +72,8 @@ public function handle(Event $event): void {
7072

7173
public function register(): void {
7274
$this->contentManager->registerContentProvider($this->getAppId(), $this->getId(), self::class);
73-
$this->eventDispatcher->addServiceListener(CreateEvent::class, self::class);
74-
$this->eventDispatcher->addServiceListener(UpdateEvent::class, self::class);
75+
$this->eventDispatcher->addServiceListener(InsertEvent::class, self::class);
76+
$this->eventDispatcher->addServiceListener(ManipulateEvent::class, self::class);
7577
$this->eventDispatcher->addServiceListener(BeforeDeleteEvent::class, self::class);
7678
}
7779

lib/Db/BookmarkMapper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
namespace OCA\Bookmarks\Db;
1010

1111
use OCA\Bookmarks\Events\BeforeDeleteEvent;
12+
use OCA\Bookmarks\Events\InsertEvent;
13+
use OCA\Bookmarks\Events\ManipulateEvent;
1214
use OCA\Bookmarks\Exception\AlreadyExistsError;
1315
use OCA\Bookmarks\Exception\UrlParseError;
1416
use OCA\Bookmarks\Exception\UserLimitExceededError;
@@ -775,7 +777,9 @@ public function update(Entity $entity): Bookmark {
775777
$entity->setUrl($this->urlNormalizer->normalize($entity->getUrl()));
776778
}
777779
$entity->setLastmodified(time());
778-
return parent::update($entity);
780+
parent::update($entity);
781+
$this->eventDispatcher->dispatchTyped(new ManipulateEvent('bookmark', $entity->getId()));
782+
return $entity;
779783
}
780784

781785
/**
@@ -808,6 +812,7 @@ public function insert(Entity $entity): Bookmark {
808812
$this->findByUrl($entity->getUserId(), $entity->getUrl());
809813
} catch (DoesNotExistException $e) {
810814
parent::insert($entity);
815+
$this->eventDispatcher->dispatchTyped(new InsertEvent('bookmark', $entity->getId()));
811816
return $entity;
812817
} catch (MultipleObjectsReturnedException $e) {
813818
// noop

lib/Events/InsertEvent.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) 2020-2024. The Nextcloud Bookmarks contributors.
5+
*
6+
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
7+
*/
8+
9+
namespace OCA\Bookmarks\Events;
10+
11+
/**
12+
* Event emitted when a bookmarks entity is inserted into the DB
13+
* Not exposed via the activity app
14+
*/
15+
class InsertEvent extends ChangeEvent {
16+
}

lib/Events/ManipulateEvent.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) 2020-2024. The Nextcloud Bookmarks contributors.
5+
*
6+
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
7+
*/
8+
9+
namespace OCA\Bookmarks\Events;
10+
11+
/**
12+
* Event emitted when a bookmarks entity is manipulated into the DB
13+
* Not exposed via the activity app
14+
*/
15+
class ManipulateEvent extends ChangeEvent {
16+
}

0 commit comments

Comments
 (0)