123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
-
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiQvitterNotificationsAction extends ApiPrivateAuthAction
- {
- var $notifications = array();
- var $notices = null;
- var $profiles = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->format = 'json';
- $this->notifications = $this->getNotifications();
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- $this->showTimeline();
- }
-
- function showTimeline()
- {
- $notice = null;
- $notifications_populated = array();
- foreach ($this->notifications as $notification) {
-
- if ($notification->ntype != 'follow') {
-
- if($notification->notice_id === null) {
- continue;
- } else {
- $notice_object = Notice::getKV($notification->notice_id);
- if($notice_object instanceof Notice) {
- $notice = self::twitterSimpleStatusArray($notice_object);
- } else {
-
- $notification->delete();
- continue;
- }
- }
- }
- $from_profile = Profile::getKV($notification->from_profile_id);
-
- if ($from_profile instanceof Profile) {
- $notifications_populated[] = array(
- 'id'=> $notification->id,
- 'from_profile'=> self::twitterUserArray($from_profile),
- 'ntype'=> $notification->ntype,
- 'notice'=> $notice,
- 'created_at'=>self::dateTwitter($notification->created),
- 'is_seen'=>$notification->is_seen
- );
- } else {
-
- $notification->delete();
- }
-
- if($notification->is_seen == 0) {
- $orig = clone($notification);
- $notification->is_seen = 1;
- $notification->update($orig);
- }
- }
- $this->initDocument('json');
- $this->showJsonObjects($notifications_populated);
- $this->endDocument('json');
- }
-
- function getNotifications()
- {
- $notices = array();
- $profile = ($this->auth_user) ? $this->auth_user->getProfile() : null;
- if(!$profile instanceof Profile) {
- return false;
- }
- $stream = new NotificationStream($profile);
- $notifications = $stream->getNotifications(($this->page - 1) * $this->count,
- $this->count,
- $this->since_id,
- $this->max_id);
- $notifications = $notifications->fetchAll();
- return $notifications;
- }
-
- function isReadOnly($args)
- {
- return true;
- }
-
- function lastModified()
- {
- if (!empty($this->notifications) && (count($this->notifications) > 0)) {
- return strtotime($this->notifications[0]->created);
- }
- return null;
- }
-
- function etag()
- {
- if (!empty($this->notifications) && (count($this->notifications) > 0)) {
- $last = count($this->notifications) - 1;
- return '"' . implode(
- ':',
- array($this->arg('action'),
- common_user_cache_hash($this->auth_user),
- common_language(),
- strtotime($this->notifications[0]->created),
- strtotime($this->notifications[$last]->created))
- )
- . '"';
- }
- return null;
- }
- }
|