appManager->isEnabledForUser(self::NOTIFICATIONS_APP, $user); } catch (Throwable $e) { return false; } } /** * One notification per card, unlike the mail: each one links its card * and can be dismissed on its own. An older notification about the same * card is removed first, so a card that comes back and falls due again * is not listed twice. * * @param non-empty-list $entries */ public function sendCardsMovedNotification(IUser $recipient, array $entries): void { if (!$this->isAvailableFor($recipient)) { return; } foreach ($entries as $entry) { $workflow = $entry['workflow']; $card = $entry['card']; $targets = $entry['targets']; try { $this->dismiss($recipient, self::OBJECT_CARD, (string)$card->getId(), self::SUBJECT_CARD_MOVED); $notification = $this->notificationManager->createNotification(); $notification->setApp(Application::APP_ID) ->setUser($recipient->getUID()) ->setDateTime($this->timeFactory->getDateTime()) ->setObject(self::OBJECT_CARD, (string)$card->getId()) ->setSubject(self::SUBJECT_CARD_MOVED, [ 'cardTitle' => (string)$card->getTitle(), 'boardId' => $workflow->getBoardId(), 'boardTitle' => $targets['board'], 'sourceStackId' => $workflow->getSourceStackId(), 'sourceStackTitle' => $targets['sourceStack'], 'targetStackId' => $workflow->getTargetStackId(), 'targetStackTitle' => $targets['targetStack'], ]); $this->notificationManager->notify($notification); } catch (Throwable $e) { $this->logger->error('Could not notify ' . $recipient->getUID() . ' about moved card ' . $card->getId() . ': ' . $e->getMessage(), [ 'app' => Application::APP_ID, 'exception' => $e, ]); } } } /** * Companion to NotificationMailer::sendWorkflowDisabledNotification(). * * @param WorkflowRunner::TARGET_* $brokenTarget */ public function sendWorkflowDisabledNotification(IUser $user, Workflow $workflow, string $brokenTarget): void { if (!$this->isAvailableFor($user)) { return; } try { $notification = $this->notificationManager->createNotification(); $notification->setApp(Application::APP_ID) ->setUser($user->getUID()) ->setDateTime($this->timeFactory->getDateTime()) ->setObject(self::OBJECT_WORKFLOW, (string)$workflow->getId()) ->setSubject(self::SUBJECT_WORKFLOW_DISABLED, [ 'workflowTitle' => (string)$workflow->getTitle(), 'brokenTarget' => $brokenTarget, ]); $this->notificationManager->notify($notification); } catch (Throwable $e) { $this->logger->error('Could not notify ' . $user->getUID() . ' about disabled workflow ' . $workflow->getId() . ': ' . $e->getMessage(), [ 'app' => Application::APP_ID, 'exception' => $e, ]); } } private function dismiss(IUser $user, string $objectType, string $objectId, string $subject): void { $notification = $this->notificationManager->createNotification(); $notification->setApp(Application::APP_ID) ->setUser($user->getUID()) ->setObject($objectType, $objectId) ->setSubject($subject); $this->notificationManager->markProcessed($notification); } }