Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use deleteIds to get rid of notifications
Signed-off-by: Artur Neumann <[email protected]>
  • Loading branch information
individual-it committed Nov 8, 2022
commit 0e57658b9a94dff688824b4cc392c17d83ed5acb
15 changes: 12 additions & 3 deletions lib/Service/OpenProjectAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use DateTime;
use DateTimeZone;
use Exception;
use OCA\Notifications\Handler;
use OCP\Files\Node;
use OCA\OpenProject\Exception\OpenprojectErrorException;
use OCA\OpenProject\Exception\OpenprojectResponseException;
Expand Down Expand Up @@ -92,6 +93,8 @@ class OpenProjectAPIService {
/**
* Service to make requests to OpenProject v3 (JSON) API
*/
private $handler;

public function __construct(
string $appName,
IUserManager $userManager,
Expand All @@ -103,7 +106,8 @@ public function __construct(
IClientService $clientService,
IRootFolder $storage,
IURLGenerator $urlGenerator,
ICacheFactory $cacheFactory) {
ICacheFactory $cacheFactory,
Handler $handler) {
$this->appName = $appName;
$this->userManager = $userManager;
$this->avatarManager = $avatarManager;
Expand All @@ -114,7 +118,7 @@ public function __construct(
$this->client = $clientService->newClient();
$this->storage = $storage;
$this->urlGenerator = $urlGenerator;

$this->handler = $handler;
$this->cache = $cacheFactory->createDistributed();
}

Expand Down Expand Up @@ -164,7 +168,12 @@ private function checkNotificationsForUser(string $userId): void {
$notification = $manager->createNotification();
$notification->setApp(Application::APP_ID)
->setUser($userId);
$manager->markProcessed($notification);
$notifications = $this->handler->get($notification);
$notificationsToDelete = [];
foreach ($notifications as $notificationId => $n) {
$notificationsToDelete[] = $notificationId;
}
$this->handler->deleteIds($notificationsToDelete);

foreach ($aggregatedNotifications as $n) {
$n['reasons'] = array_unique($n['reasons']);
Expand Down