/** * @NoAdminRequired * @NoCSRFRequired * * @return JSONResponse */ public function get() { // When there are no apps registered that use the notifications // We stop polling for them. if (!$this->manager->hasNotifiers()) { $response = new Response(); $response->setStatus(Http::STATUS_NO_CONTENT); return $response; } $filter = $this->manager->createNotification(); $filter->setUser($this->user); $language = $this->config->getUserValue($this->user, 'core', 'lang', null); $notifications = $this->handler->get($filter); $data = []; $notificationIds = []; foreach ($notifications as $notificationId => $notification) { try { $notification = $this->manager->prepare($notification, $language); } catch (\InvalidArgumentException $e) { // The app was disabled, skip the notification continue; } $notificationIds[] = $notificationId; $data[] = $this->notificationToArray($notificationId, $notification); } $response = new JSONResponse($data); $response->setETag($this->generateEtag($notificationIds)); return $response; }
/** * @return \OC_OCS_Result */ public function disableMonthly() { $this->jobList->remove('OCA\\PopularityContestClient\\MonthlyReport'); $notification = $this->manager->createNotification(); $notification->setApp('popularitycontestclient'); $this->manager->markProcessed($notification); return new \OC_OCS_Result(); }
/** * @param int $id * @param string $authorId * @param int $timeStamp */ protected function createPublicity($id, $authorId, $timeStamp) { $users = $this->userManager->search(''); $event = $this->activityManager->generateEvent(); $event->setApp('announcementcenter')->setType('announcementcenter')->setAuthor($authorId)->setTimestamp($timeStamp)->setSubject('announcementsubject#' . $id, [$authorId])->setMessage('announcementmessage#' . $id, [$authorId])->setObject('announcement', $id); $dateTime = new \DateTime(); $dateTime->setTimestamp($timeStamp); $notification = $this->notificationManager->createNotification(); $notification->setApp('announcementcenter')->setDateTime($dateTime)->setObject('announcement', $id)->setSubject('announced', [$authorId])->setLink($this->urlGenerator->linkToRoute('announcementcenter.page.index')); foreach ($users as $user) { $event->setAffectedUser($user->getUID()); $this->activityManager->publish($event); if ($authorId !== $user->getUID()) { $notification->setUser($user->getUID()); $this->notificationManager->notify($notification); } } }
/** * Turn a database row into a INotification * * @param array $row * @return INotification */ protected function notificationFromRow(array $row) { $notification = $this->manager->createNotification(); $notification->setApp($row['app'])->setUser($row['user'])->setTimestamp((int) $row['timestamp'])->setObject($row['object_type'], (int) $row['object_id'])->setSubject($row['subject'], (array) json_decode($row['subject_parameters'], true)); if ($row['message'] !== '') { $notification->setMessage($row['message'], (array) json_decode($row['message_parameters'], true)); } if ($row['link'] !== '') { $notification->setLink($row['link']); } if ($row['icon'] !== '') { $notification->setIcon($row['icon']); } $actions = (array) json_decode($row['actions'], true); foreach ($actions as $actionData) { $action = $notification->createAction(); $action->setLabel($actionData['label'])->setLink($actionData['link'], $actionData['type']); if ($actionData['icon']) { $action->setIcon($actionData['icon']); } $notification->addAction($action); } return $notification; }
/** * @param int $remoteShare */ protected function scrapNotification($remoteShare) { $filter = $this->notificationManager->createNotification(); $filter->setApp('files_sharing')->setUser($this->uid)->setObject('remote_share', (int) $remoteShare); $this->notificationManager->markProcessed($filter); }
public function testCreateNotification() { $action = $this->manager->createNotification(); $this->assertInstanceOf('OC\\Notification\\INotification', $action); }