function getNotifications($offset, $limit, $sinceId, $maxId) { $all = array(); do { $ids = $this->getNotificationIds($offset, $limit, $sinceId, $maxId); $notifications = QvitterNotification::pivotGet('id', $ids); // By default, takes out false values $notifications = array_filter($notifications); $all = array_merge($all, $notifications); if (count($notifications < count($ids))) { $offset += $limit; $limit -= count($notifications); } } while (count($notifications) < count($ids) && count($ids) > 0); return new ArrayWrapper($all); }
/** * 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'); }
/** * 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; }
/** * 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; }
/** * 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; }