Merge pull request #4080 from MrPetovan/task/4078-add-max_id-to-user_timeline

Add max_id support for statuses/user_timeline API
This commit is contained in:
Michael Vogel 2017-12-16 18:44:28 +01:00 committed by GitHub
commit 3d49062a6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2019,6 +2019,13 @@ function api_statuses_mentions($type)
api_register_func('api/statuses/mentions', 'api_statuses_mentions', true);
api_register_func('api/statuses/replies', 'api_statuses_mentions', true);
/**
* @brief Returns a user's public timeline
*
* @param string $type Either "json" or "xml"
* @return string|array
* @throws ForbiddenException
*/
function api_statuses_user_timeline($type)
{
$a = get_app();
@ -2028,7 +2035,6 @@ function api_statuses_user_timeline($type)
}
$user_info = api_get_user($a);
// get last network messages
logger(
"api_statuses_user_timeline: api_user: ". api_user() .
@ -2037,18 +2043,18 @@ function api_statuses_user_timeline($type)
LOGGER_DEBUG
);
// params
$count = (x($_REQUEST, 'count') ? $_REQUEST['count'] : 20);
$page = (x($_REQUEST, 'page') ? $_REQUEST['page'] -1 : 0);
if ($page < 0) {
$page = 0;
}
$since_id = (x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0);
//$since_id = 0;//$since_id = (x($_REQUEST, 'since_id')?$_REQUEST['since_id'] : 0);
$exclude_replies = (x($_REQUEST, 'exclude_replies') ? 1 : 0);
$conversation_id = (x($_REQUEST, 'conversation_id') ? $_REQUEST['conversation_id'] : 0);
$since_id = x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0;
$max_id = x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0;
$exclude_replies = x($_REQUEST, 'exclude_replies') ? 1 : 0;
$conversation_id = x($_REQUEST, 'conversation_id') ? $_REQUEST['conversation_id'] : 0;
$start = $page * $count;
// pagination
$count = x($_REQUEST, 'count') ? $_REQUEST['count'] : 20;
$page = x($_REQUEST, 'page') ? $_REQUEST['page'] : 1;
if ($page < 1) {
$page = 1;
}
$start = ($page - 1) * $count;
$sql_extra = '';
if ($user_info['self'] == 1) {
@ -2058,10 +2064,15 @@ function api_statuses_user_timeline($type)
if ($exclude_replies > 0) {
$sql_extra .= ' AND `item`.`parent` = `item`.`id`';
}
if ($conversation_id > 0) {
$sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id);
}
if ($max_id > 0) {
$sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
}
$r = q(
"SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
@ -2074,7 +2085,7 @@ function api_statuses_user_timeline($type)
AND `item`.`contact-id` = %d
AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
$sql_extra
AND `item`.`id`>%d
AND `item`.`id` > %d
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
intval(api_user()),
dbesc(ACTIVITY_POST),