2014-09-25 06:20:35 +09:00
|
|
|
<?php
|
2015-08-07 01:54:15 +09:00
|
|
|
/* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
|
2014-09-25 06:20:35 +09:00
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· Q V I T T E R ·
|
|
|
|
· ·
|
2016-01-18 09:24:37 +09:00
|
|
|
· https://git.gnu.io/h2p/Qvitter ·
|
2014-09-25 06:20:35 +09:00
|
|
|
· ·
|
|
|
|
· ·
|
|
|
|
· <o) ·
|
|
|
|
· /_//// ·
|
|
|
|
· (____/ ·
|
|
|
|
· (o< ·
|
|
|
|
· o> \\\\_\ ·
|
|
|
|
· \\) \____) ·
|
|
|
|
· ·
|
2015-08-07 01:54:15 +09:00
|
|
|
· ·
|
2014-09-25 06:20:35 +09:00
|
|
|
· ·
|
|
|
|
· Qvitter is free software: you can redistribute it and / or modify it ·
|
|
|
|
· under the terms of the GNU Affero General Public License as published by ·
|
|
|
|
· the Free Software Foundation, either version three of the License or (at ·
|
|
|
|
· your option) any later version. ·
|
|
|
|
· ·
|
|
|
|
· Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
|
|
|
|
· WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
|
|
|
|
· FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
|
|
|
|
· more details. ·
|
|
|
|
· ·
|
|
|
|
· You should have received a copy of the GNU Affero General Public License ·
|
|
|
|
· along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
|
|
|
|
· ·
|
|
|
|
· Contact h@nnesmannerhe.im if you have any questions. ·
|
2015-08-07 01:54:15 +09:00
|
|
|
· ·
|
2014-09-25 06:20:35 +09:00
|
|
|
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
|
|
|
|
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
class ApiQvitterNotificationsAction extends ApiPrivateAuthAction
|
|
|
|
{
|
2015-01-18 22:18:19 +09:00
|
|
|
var $notifications = array();
|
2014-09-25 06:20:35 +09:00
|
|
|
var $notices = null;
|
|
|
|
var $profiles = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Take arguments for running
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST args
|
|
|
|
*
|
|
|
|
* @return boolean success flag
|
|
|
|
*
|
|
|
|
*/
|
2015-01-18 22:37:49 +09:00
|
|
|
protected function prepare(array $args=array())
|
2014-09-25 06:20:35 +09:00
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
2016-02-02 02:22:41 +09:00
|
|
|
$this->format = 'json';
|
|
|
|
|
2014-09-25 06:20:35 +09:00
|
|
|
$this->notifications = $this->getNotifications();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the request
|
|
|
|
*
|
|
|
|
* Just show the notices
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST data (unused)
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-01-18 22:37:49 +09:00
|
|
|
protected function handle()
|
2014-09-25 06:20:35 +09:00
|
|
|
{
|
2015-01-18 22:37:49 +09:00
|
|
|
parent::handle();
|
2014-09-25 06:20:35 +09:00
|
|
|
$this->showTimeline();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the timeline of notices
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showTimeline()
|
|
|
|
{
|
2015-08-07 01:54:15 +09:00
|
|
|
$notice = null;
|
2015-01-18 22:24:15 +09:00
|
|
|
|
2014-09-25 06:20:35 +09:00
|
|
|
$notifications_populated = array();
|
2014-11-26 05:38:00 +09:00
|
|
|
|
2015-01-18 22:24:15 +09:00
|
|
|
foreach ($this->notifications as $notification) {
|
|
|
|
// all but follow has an notice
|
|
|
|
if ($notification->ntype != 'follow') {
|
|
|
|
// we need a notice id here, skip this notification if notice id is null
|
|
|
|
if($notification->notice_id === null) {
|
|
|
|
continue;
|
|
|
|
} else {
|
2015-08-07 01:54:15 +09:00
|
|
|
$notice_object = Notice::getKV($notification->notice_id);
|
|
|
|
if($notice_object instanceof Notice) {
|
|
|
|
$notice = self::twitterSimpleStatusArray($notice_object);
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-01-18 22:24:15 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$from_profile = Profile::getKV($notification->from_profile_id);
|
2014-11-26 05:38:00 +09:00
|
|
|
|
2015-01-18 22:24:15 +09:00
|
|
|
// a user might have deleted their profile, don't show these notifications
|
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
2014-10-06 18:56:34 +09:00
|
|
|
|
2015-01-18 22:27:42 +09:00
|
|
|
// mark as seen
|
2015-01-18 22:24:15 +09:00
|
|
|
if($notification->is_seen == 0) {
|
2015-01-18 22:28:53 +09:00
|
|
|
$orig = clone($notification);
|
2015-01-18 22:24:15 +09:00
|
|
|
$notification->is_seen = 1;
|
2015-01-18 22:28:53 +09:00
|
|
|
$notification->update($orig);
|
2015-01-18 22:24:15 +09:00
|
|
|
}
|
|
|
|
}
|
2014-09-25 06:20:35 +09:00
|
|
|
|
|
|
|
$this->initDocument('json');
|
|
|
|
$this->showJsonObjects($notifications_populated);
|
|
|
|
$this->endDocument('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get notices
|
|
|
|
*
|
|
|
|
* @return array notices
|
|
|
|
*/
|
|
|
|
function getNotifications()
|
|
|
|
{
|
|
|
|
$notices = array();
|
|
|
|
|
|
|
|
$profile = ($this->auth_user) ? $this->auth_user->getProfile() : null;
|
2015-08-07 01:54:15 +09:00
|
|
|
|
2014-10-05 21:07:31 +09:00
|
|
|
if(!$profile instanceof Profile) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-07 01:54:15 +09:00
|
|
|
|
2014-09-25 06:20:35 +09:00
|
|
|
$stream = new NotificationStream($profile);
|
|
|
|
|
|
|
|
$notifications = $stream->getNotifications(($this->page - 1) * $this->count,
|
|
|
|
$this->count,
|
|
|
|
$this->since_id,
|
2015-08-07 01:54:15 +09:00
|
|
|
$this->max_id);
|
2014-09-25 06:20:35 +09:00
|
|
|
|
|
|
|
$notifications = $notifications->fetchAll();
|
|
|
|
|
|
|
|
return $notifications;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this action read only?
|
|
|
|
*
|
|
|
|
* @param array $args other arguments
|
|
|
|
*
|
|
|
|
* @return boolean true
|
|
|
|
*/
|
|
|
|
function isReadOnly($args)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When was this feed last modified?
|
|
|
|
*
|
|
|
|
* @return string datestamp of the latest notice in the stream
|
|
|
|
*/
|
|
|
|
function lastModified()
|
|
|
|
{
|
|
|
|
if (!empty($this->notifications) && (count($this->notifications) > 0)) {
|
|
|
|
return strtotime($this->notifications[0]->created);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An entity tag for this stream
|
|
|
|
*
|
|
|
|
* Returns an Etag based on the action name, language, and
|
|
|
|
* timestamps of the first and last notice in the timeline
|
|
|
|
*
|
|
|
|
* @return string etag
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
2015-08-07 01:54:15 +09:00
|
|
|
|
2014-09-25 06:20:35 +09:00
|
|
|
}
|