time->getDateTime(); $dateTime->setTimestamp($timestamp); $this->logger->debug( 'Running background job to create app update notifications for "' . $appId . '"', [ 'app' => Application::APP_NAME, ], ); if ($this->manager->getChangelogFile($appId, 'en') === null) { $this->logger->debug('Skipping app updated notification - no changelog provided'); return; } $this->stopPreviousNotifications($appId); // Create new notifications $notification = $this->notificationManager->createNotification(); $notification->setApp(Application::APP_NAME) ->setDateTime($dateTime) ->setSubject('app_updated', [$appId]) ->setObject('app_updated', $appId); $this->notifyUsers($appId, $notification); } /** * Stop all previous notifications users might not have dismissed until now * @param string $appId The app to stop update notifications for */ private function stopPreviousNotifications(string $appId): void { $notification = $this->notificationManager->createNotification(); $notification->setApp(Application::APP_NAME) ->setObject('app_updated', $appId); $this->notificationManager->markProcessed($notification); } /** * Notify all users for which the updated app is enabled */ private function notifyUsers(string $appId, INotification $notification): void { $guestsEnabled = $this->appConfig->getAppValueBool('app_updated.notify_guests', false) && class_exists('\OCA\Guests\UserBackend'); $isDefer = $this->notificationManager->defer(); // Notify all seen users about the app update $this->userManager->callForSeenUsers(function (IUser $user) use ($guestsEnabled, $appId, $notification) { if (!$guestsEnabled && ($user->getBackendClassName() === '\OCA\Guests\UserBackend')) { return; } if (!$this->appManager->isEnabledForUser($appId, $user)) { return; } $notification->setUser($user->getUID()); $this->notificationManager->notify($notification); }); // If we enabled the defer we call the flush if ($isDefer) { $this->notificationManager->flush(); } } }