+api_register_func('api/lists/ownerships', 'api_lists_ownerships', true);
+
+/**
+ * Returns recent statuses from users in the specified group.
+ *
+ * @param string $type Return type (atom, rss, xml, json)
+ *
+ * @return array|string
+ * @see https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-ownerships
+ */
+function api_lists_statuses($type)
+{
+ $a = get_app();
+
+ if (api_user() === false) {
+ throw new ForbiddenException();
+ }
+
+ unset($_REQUEST["user_id"]);
+ unset($_GET["user_id"]);
+
+ unset($_REQUEST["screen_name"]);
+ unset($_GET["screen_name"]);
+
+ $user_info = api_get_user($a);
+ if (!x($_REQUEST, 'list_id')) {
+ throw new BadRequestException('list_id not specified');
+ }
+
+ // 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);
+ $max_id = (x($_REQUEST, 'max_id') ? $_REQUEST['max_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);
+
+ $start = $page * $count;
+
+ $sql_extra = '';
+ if ($max_id > 0) {
+ $sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
+ }
+ if ($exclude_replies > 0) {
+ $sql_extra .= ' AND `item`.`parent` = `item`.`id`';
+ }
+ if ($conversation_id > 0) {
+ $sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id);
+ }
+
+ $statuses = dba::p(
+ "SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
+ `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
+ `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
+ `contact`.`id` AS `cid`, `group_member`.`gid`
+ FROM `item`
+ STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
+ AND (NOT `contact`.`blocked` OR `contact`.`pending`)
+ STRAIGHT_JOIN `group_member` ON `group_member`.`contact-id` = `item`.`contact-id`
+ WHERE `item`.`uid` = ? AND `verb` = ?
+ AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
+ AND `item`.`id`>?
+ AND `group_member`.`gid` = ?
+ ORDER BY `item`.`id` DESC LIMIT ".intval($start)." ,".intval($count),
+ api_user(),
+ ACTIVITY_POST,
+ $since_id,
+ $_REQUEST['list_id']
+ );
+
+ $items = api_format_items($statuses, $user_info, false, $type);
+
+ $data = ['status' => $items];
+ switch ($type) {
+ case "atom":
+ case "rss":
+ $data = api_rss_extra($a, $data, $user_info);
+ break;
+ }
+
+ return api_format_data("statuses", $type, $data);
+}
+
+/// @TODO move to top of file or somewhere better
+api_register_func('api/lists/statuses', 'api_lists_statuses', true);