+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);
+ // get last newtork messages
+
+ // 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);
+ }
+
+ $r = q(
+ "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` = %d AND `verb` = '%s'
+ AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
+ $sql_extra
+ AND `item`.`id`>%d
+ AND `group_member`.`gid` = %d
+ ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
+ intval(api_user()),
+ dbesc(ACTIVITY_POST),
+ intval($since_id),
+ intval($_REQUEST['list_id']),
+ intval($start),
+ intval($count)
+ );
+
+ $ret = api_format_items($r, $user_info, false, $type);
+
+ // Set all posts from the query above to seen
+ $idarray = [];
+ foreach ($r as $item) {
+ $idarray[] = intval($item["id"]);
+ }
+
+ $idlist = implode(",", $idarray);
+
+ if ($idlist != "") {
+ $unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `id` IN (%s)", $idlist);
+
+ if ($unseen) {
+ q("UPDATE `item` SET `unseen` = 0 WHERE `unseen` AND `id` IN (%s)", $idlist);
+ }
+ }
+
+ $data = ['status' => $ret];
+ 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);