/**
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @return \OC_OCS_Result
  */
 public function listNotifications()
 {
     // When there are no apps registered that use the notifications
     // We stop polling for them.
     if (!$this->manager->hasNotifiers()) {
         return new \OC_OCS_Result(null, Http::STATUS_NO_CONTENT);
     }
     $filter = $this->manager->createNotification();
     $filter->setUser($this->getCurrentUser());
     $language = $this->config->getUserValue($this->getCurrentUser(), 'core', 'lang', null);
     $notifications = $this->handler->get($filter);
     $data = [];
     $notificationIds = [];
     foreach ($notifications as $notificationId => $notification) {
         /** @var INotification $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);
     }
     return new \OC_OCS_Result($data, 100, null, ['ETag' => $this->generateEtag($notificationIds)]);
 }
Exemple #2
0
 /**
  * Turn a database row into a INotification
  *
  * @param array $row
  * @return INotification
  */
 protected function notificationFromRow(array $row)
 {
     $dateTime = new \DateTime();
     $dateTime->setTimestamp((int) $row['timestamp']);
     $notification = $this->manager->createNotification();
     $notification->setApp($row['app'])->setUser($row['user'])->setDateTime($dateTime)->setObject($row['object_type'], $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']);
     }
     $actions = (array) json_decode($row['actions'], true);
     foreach ($actions as $actionData) {
         $action = $notification->createAction();
         $action->setLabel($actionData['label'])->setLink($actionData['link'], $actionData['type']);
         if (isset($actionData['primary'])) {
             $action->setPrimary($actionData['primary']);
         }
         $notification->addAction($action);
     }
     return $notification;
 }
Exemple #3
0
 public function testCreateNotification()
 {
     $action = $this->manager->createNotification();
     $this->assertInstanceOf('OCP\\Notification\\INotification', $action);
 }
Exemple #4
0
 /**
  * @param int $remoteShare
  */
 public function processNotification($remoteShare)
 {
     $filter = $this->notificationManager->createNotification();
     $filter->setApp('files_sharing')->setUser($this->uid)->setObject('remote_share', (int) $remoteShare);
     $this->notificationManager->markProcessed($filter);
 }
 /**
  * Delete notifications for old updates
  *
  * @param string $app
  * @param string $version
  */
 protected function deleteOutdatedNotifications($app, $version)
 {
     $notification = $this->notificationManager->createNotification();
     $notification->setApp('updatenotification')->setObject($app, $version);
     $this->notificationManager->markProcessed($notification);
 }