-/**
- * Returns the most recent statuses posted by the user and the users they follow.
- *
- * @see https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline
- *
- * @param string $type Return type (atom, rss, xml, json)
- *
- * @return array|string
- * @throws BadRequestException
- * @throws ForbiddenException
- * @throws ImagickException
- * @throws InternalServerErrorException
- * @throws UnauthorizedException
- * @todo Optional parameters
- * @todo Add reply info
- */
-function api_statuses_home_timeline($type)
-{
- BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- $uid = BaseApi::getCurrentUserID();
-
- // get last network messages
-
- // params
- $count = $_REQUEST['count'] ?? 20;
- $page = $_REQUEST['page']?? 0;
- $since_id = $_REQUEST['since_id'] ?? 0;
- $max_id = $_REQUEST['max_id'] ?? 0;
- $exclude_replies = !empty($_REQUEST['exclude_replies']);
- $conversation_id = $_REQUEST['conversation_id'] ?? 0;
-
- $start = max(0, ($page - 1) * $count);
-
- $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ?",
- $uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
-
- if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
- $condition[] = $max_id;
- }
- if ($exclude_replies) {
- $condition[0] .= ' AND `gravity` = ?';
- $condition[] = GRAVITY_PARENT;
- }
- if ($conversation_id > 0) {
- $condition[0] .= " AND `parent` = ?";
- $condition[] = $conversation_id;
- }
-
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectForUser($uid, [], $condition, $params);
-
- $include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
-
- $ret = [];
- $idarray = [];
- while ($status = DBA::fetch($statuses)) {
- $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
- $idarray[] = intval($status['id']);
- }
- DBA::close($statuses);
-
- if (!empty($idarray)) {
- $unseen = Post::exists(['unseen' => true, 'id' => $idarray]);
- if ($unseen) {
- Item::update(['unseen' => false], ['unseen' => true, 'id' => $idarray]);
- }
- }
-
- return DI::apiResponse()->formatData("statuses", $type, ['status' => $ret], Contact::getPublicIdByUserId($uid));
-}
-
-
-api_register_func('api/statuses/home_timeline', 'api_statuses_home_timeline', true);
-api_register_func('api/statuses/friends_timeline', 'api_statuses_home_timeline', true);
-
-/**
- * Returns the most recent statuses from public users.
- *
- * @param string $type Return type (atom, rss, xml, json)
- *
- * @return array|string
- * @throws BadRequestException
- * @throws ForbiddenException
- * @throws ImagickException
- * @throws InternalServerErrorException
- * @throws UnauthorizedException
- */
-function api_statuses_public_timeline($type)
-{
- BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- $uid = BaseApi::getCurrentUserID();
-
- // get last network messages
-
- // params
- $count = $_REQUEST['count'] ?? 20;
- $page = $_REQUEST['page'] ?? 1;
- $since_id = $_REQUEST['since_id'] ?? 0;
- $max_id = $_REQUEST['max_id'] ?? 0;
- $exclude_replies = (!empty($_REQUEST['exclude_replies']) ? 1 : 0);
- $conversation_id = $_REQUEST['conversation_id'] ?? 0;
-
- $start = max(0, ($page - 1) * $count);
-
- if ($exclude_replies && !$conversation_id) {
- $condition = ["`gravity` = ? AND `id` > ? AND `private` = ? AND `wall` AND NOT `author-hidden`",
- GRAVITY_PARENT, $since_id, Item::PUBLIC];
-
- if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
- $condition[] = $max_id;
- }
-
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectForUser($uid, [], $condition, $params);
- } else {
- $condition = ["`gravity` IN (?, ?) AND `id` > ? AND `private` = ? AND `wall` AND `origin` AND NOT `author-hidden`",
- GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC];
-
- if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
- $condition[] = $max_id;
- }
- if ($conversation_id > 0) {
- $condition[0] .= " AND `parent` = ?";
- $condition[] = $conversation_id;
- }
-
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectForUser($uid, [], $condition, $params);
- }
-
- $include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
-
- $ret = [];
- while ($status = DBA::fetch($statuses)) {
- $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
- }
- DBA::close($statuses);
-
- return DI::apiResponse()->formatData("statuses", $type, ['status' => $ret], Contact::getPublicIdByUserId($uid));
-}
-
-api_register_func('api/statuses/public_timeline', 'api_statuses_public_timeline', true);
-
-/**
- * Returns the most recent statuses posted by users this node knows about.
- *
- * @param string $type Return format: json, xml, atom, rss
- * @return array|string
- * @throws BadRequestException
- * @throws ForbiddenException
- * @throws ImagickException
- * @throws InternalServerErrorException
- * @throws UnauthorizedException
- */
-function api_statuses_networkpublic_timeline($type)
-{
- BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
- $uid = BaseApi::getCurrentUserID();
-
- $since_id = $_REQUEST['since_id'] ?? 0;
- $max_id = $_REQUEST['max_id'] ?? 0;
-
- // pagination
- $count = $_REQUEST['count'] ?? 20;
- $page = $_REQUEST['page'] ?? 1;
-
- $start = max(0, ($page - 1) * $count);
-
- $condition = ["`uid` = 0 AND `gravity` IN (?, ?) AND `id` > ? AND `private` = ?",
- GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC];
-
- if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
- $condition[] = $max_id;
- }
-
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectForUser($uid, Item::DISPLAY_FIELDLIST, $condition, $params);
-
- $include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
-
- $ret = [];
- while ($status = DBA::fetch($statuses)) {
- $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
- }
- DBA::close($statuses);
-
- return DI::apiResponse()->formatData("statuses", $type, ['status' => $ret], Contact::getPublicIdByUserId($uid));
-}
-
-api_register_func('api/statuses/networkpublic_timeline', 'api_statuses_networkpublic_timeline', true);
-