Esempio n. 1
0
 /**
  * Get IDs in a range
  *
  * @param int $offset   Offset from start
  * @param int $limit    Limit of number to get
  * @param int $since_id Since this notice
  * @param int $max_id   Before this notice
  *
  * @return Array IDs found
  */
 function getNotificationIds($offset, $limit, $since_id, $max_id)
 {
     $notification = new QvitterNotification();
     $notification->selectAdd();
     $notification->selectAdd('id');
     $notification->whereAdd(sprintf('qvitternotification.to_profile_id = "%s"', $notification->escape($this->target->id)));
     $notification->whereAdd(sprintf('qvitternotification.created >= "%s"', $notification->escape($this->target->created)));
     $notification->limit($offset, $limit);
     $notification->orderBy('qvitternotification.created DESC');
     if ($since_id) {
         $notification->whereAdd(sprintf('qvitternotification.id > %d', $notification->escape($since_id)));
     }
     if ($max_id) {
         $notification->whereAdd(sprintf('qvitternotification.id <= %d', $notification->escape($max_id)));
     }
     if (!$notification->find()) {
         return array();
     }
     $ids = $notification->fetchAll('id');
     return $ids;
 }
Esempio n. 2
0
 /**
  * Get IDs in a range
  *
  * @param int $offset   Offset from start
  * @param int $limit    Limit of number to get
  * @param int $since_id Since this notice
  * @param int $max_id   Before this notice
  *
  * @return Array IDs found
  */
 function getNotificationIds($offset, $limit, $since_id, $max_id)
 {
     $notification = new QvitterNotification();
     $notification->selectAdd();
     $notification->selectAdd('id');
     $notification->whereAdd(sprintf('qvitternotification.to_profile_id = "%s"', $notification->escape($this->target->id)));
     $notification->whereAdd(sprintf('qvitternotification.created >= "%s"', $notification->escape($this->target->created)));
     // the user might have opted out from certain notification types
     $current_profile = Profile::current();
     $disable_notify_replies_and_mentions = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_replies_and_mentions');
     $disable_notify_favs = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_favs');
     $disable_notify_repeats = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_repeats');
     $disable_notify_follows = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_follows');
     if ($disable_notify_replies_and_mentions == '1') {
         $notification->whereAdd('qvitternotification.ntype != "mention"');
         $notification->whereAdd('qvitternotification.ntype != "reply"');
     }
     if ($disable_notify_favs == '1') {
         $notification->whereAdd('qvitternotification.ntype != "like"');
     }
     if ($disable_notify_repeats == '1') {
         $notification->whereAdd('qvitternotification.ntype != "repeat"');
     }
     if ($disable_notify_follows == '1') {
         $notification->whereAdd('qvitternotification.ntype != "follow"');
     }
     $notification->limit($offset, $limit);
     $notification->orderBy('qvitternotification.created DESC');
     if ($since_id) {
         $notification->whereAdd(sprintf('qvitternotification.id > %d', $notification->escape($since_id)));
     }
     if ($max_id) {
         $notification->whereAdd(sprintf('qvitternotification.id <= %d', $notification->escape($max_id)));
     }
     if (!$notification->find()) {
         return array();
     }
     $ids = $notification->fetchAll('id');
     return $ids;
 }
 /**
  * Handle the request
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     $n = new QvitterNotification();
     $n->selectAdd();
     $n->selectAdd('id');
     $n->whereAdd(sprintf('qvitternotification.to_profile_id = "%s"', $n->escape($this->auth_user->id)));
     $ids = $n->fetchAll('id');
     $notifications = QvitterNotification::pivotGet('id', $ids);
     $notifications = new ArrayWrapper($notifications);
     $notifications = $notifications->fetchAll();
     foreach ($notifications as $notification) {
         if ($notification->is_seen == 0) {
             $orig = clone $notification;
             $notification->is_seen = 1;
             $notification->update($orig);
         }
     }
     $this->initDocument('json');
     $this->showJsonObjects(true);
     $this->endDocument('json');
 }
Esempio n. 4
0
 /**
  * Add unread notification count to all API responses, when logged in
  *
  * @return boolean hook flag
  */
 public function onEndSetApiUser($user)
 {
     // cleanup sessions, to allow for simultaneous http-requests,
     // e.g. if posting a notice takes a very long time
     Session::cleanup();
     if (!$user instanceof User) {
         return true;
     }
     $user_id = $user->id;
     $notification = new QvitterNotification();
     $notification->selectAdd();
     $notification->selectAdd('ntype');
     $notification->selectAdd('count(id) as count');
     $notification->whereAdd("(to_profile_id = '" . $user_id . "')");
     // the user might have opted out from certain notification types
     $current_profile = $user->getProfile();
     $disable_notify_replies_and_mentions = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_replies_and_mentions');
     $disable_notify_favs = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_favs');
     $disable_notify_repeats = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_repeats');
     $disable_notify_follows = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_follows');
     if ($disable_notify_replies_and_mentions == '1') {
         $notification->whereAdd('qvitternotification.ntype != "mention"');
         $notification->whereAdd('qvitternotification.ntype != "reply"');
     }
     if ($disable_notify_favs == '1') {
         $notification->whereAdd('qvitternotification.ntype != "like"');
     }
     if ($disable_notify_repeats == '1') {
         $notification->whereAdd('qvitternotification.ntype != "repeat"');
     }
     if ($disable_notify_follows == '1') {
         $notification->whereAdd('qvitternotification.ntype != "follow"');
     }
     $notification->groupBy('ntype');
     $notification->whereAdd("(is_seen = '0')");
     $notification->whereAdd("(notice_id IS NOT NULL)");
     // sometimes notice_id is NULL, those notifications are corrupt and should be discarded
     $notification->find();
     $new_notifications = array();
     while ($notification->fetch()) {
         $new_notifications[$notification->ntype] = $notification->count;
     }
     header('Qvitter-Notifications: ' . json_encode($new_notifications));
     return true;
 }
Esempio n. 5
0
 /**
  * Add unread notification count to all API responses, when logged in
  *
  * @return boolean hook flag
  */
 public function onEndSetApiUser($user)
 {
     if (!$user instanceof User) {
         return true;
     }
     $user_id = $user->id;
     $notification = new QvitterNotification();
     $notification->selectAdd();
     $notification->selectAdd('ntype');
     $notification->selectAdd('count(id) as count');
     $notification->whereAdd("(to_profile_id = '" . $user_id . "')");
     $notification->groupBy('ntype');
     $notification->whereAdd("(is_seen = '0')");
     $notification->whereAdd("(notice_id IS NOT NULL)");
     // sometimes notice_id is NULL, those notifications are corrupt and should be discarded
     $notification->find();
     $new_notifications = array();
     while ($notification->fetch()) {
         $new_notifications[$notification->ntype] = $notification->count;
     }
     header('Qvitter-Notifications: ' . json_encode($new_notifications));
     return true;
 }
Esempio n. 6
0
 /**
  * Add unread notification count to all API responses, when logged in
  *
  * @return boolean hook flag
  */
 public function onEndSetApiUser($user)
 {
     // cleanup sessions, to allow for simultaneous http-requests,
     // e.g. if posting a notice takes a very long time
     Session::cleanup();
     if (!$user instanceof User) {
         return true;
     }
     $user_id = $user->id;
     $notification = new QvitterNotification();
     $notification->selectAdd();
     $notification->selectAdd('ntype');
     $notification->selectAdd('count(id) as count');
     $notification->whereAdd("(to_profile_id = '" . $user_id . "')");
     $notification->groupBy('ntype');
     $notification->whereAdd("(is_seen = '0')");
     $notification->whereAdd("(notice_id IS NOT NULL)");
     // sometimes notice_id is NULL, those notifications are corrupt and should be discarded
     $notification->find();
     $new_notifications = array();
     while ($notification->fetch()) {
         $new_notifications[$notification->ntype] = $notification->count;
     }
     header('Qvitter-Notifications: ' . json_encode($new_notifications));
     return true;
 }