コード例 #1
0
 /**
  * @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;
 }
コード例 #2
0
 /**
  * @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)]);
 }
コード例 #3
0
 public function testDeleteById()
 {
     $notification = $this->getNotification(['getApp' => 'testing_notifications', 'getUser' => 'test_user1', 'getTimestamp' => time(), 'getObjectType' => 'notification', 'getObjectId' => 1337, 'getSubject' => 'subject', 'getSubjectParameters' => [], 'getMessage' => 'message', 'getMessageParameters' => [], 'getLink' => 'link', 'getIcon' => 'icon', 'getActions' => [['getLabel' => 'action_label', 'getIcon' => 'action_icon', 'getLink' => 'action_link', 'getRequestType' => 'GET']]]);
     $limitedNotification = $this->getNotification(['getApp' => 'testing_notifications', 'getUser' => 'test_user1']);
     // Make sure there is no notification
     $this->assertSame(0, $this->handler->count($limitedNotification));
     $notifications = $this->handler->get($limitedNotification);
     $this->assertCount(0, $notifications);
     // Add and count
     $this->handler->add($notification);
     $this->assertSame(1, $this->handler->count($limitedNotification));
     // Get and count
     $notifications = $this->handler->get($limitedNotification);
     $this->assertCount(1, $notifications);
     reset($notifications);
     $notificationId = key($notifications);
     // Delete with wrong user
     $this->handler->deleteById($notificationId, 'test_user2');
     $this->assertSame(1, $this->handler->count($limitedNotification), 'Wrong notification count for user1 after trying to delete for user2');
     // Delete and count
     $this->handler->deleteById($notificationId, 'test_user1');
     $this->assertSame(0, $this->handler->count($limitedNotification), 'Wrong notification count for user1 after deleting');
 }