From: Michael Date: Sun, 17 Mar 2019 18:39:34 +0000 (+0000) Subject: Issue 6537: Transmit the real author of a post in a dedicated field in the API X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b8b5b7b753fb06b39c8936a16308ff2b993e5115;p=friendica.git Issue 6537: Transmit the real author of a post in a dedicated field in the API --- diff --git a/doc/api.md b/doc/api.md index f58419417b..ccd2e7a7ee 100644 --- a/doc/api.md +++ b/doc/api.md @@ -654,6 +654,7 @@ Returned status object is conform to GNU Social/Twitter api. Friendica adds some addictional fields: +- author: a user object, it's the author of the item. In case of a reshare for legacy reasons the "user" field doesn't show the real author. This field always contains the real author of a post. - owner: a user object, it's the owner of the item. - private: boolean, true if the item is marked as private - activities: map with activities related to the item. Every activity is a list of user objects. @@ -667,6 +668,9 @@ JSON: [ { // ... + 'friendica_author' : { + // user object + }, 'friendica_owner' : { // user object }, diff --git a/include/api.php b/include/api.php index 64b7409fa2..4e6cd628a5 100644 --- a/include/api.php +++ b/include/api.php @@ -775,15 +775,17 @@ function api_item_get_user(App $a, $item) { $status_user = api_get_user($a, defaults($item, 'author-id', null)); + $author_user = $status_user; + $status_user["protected"] = defaults($item, 'private', 0); if (defaults($item, 'thr-parent', '') == defaults($item, 'uri', '')) { $owner_user = api_get_user($a, defaults($item, 'owner-id', null)); } else { - $owner_user = $status_user; + $owner_user = $author_user; } - return ([$status_user, $owner_user]); + return ([$status_user, $author_user, $owner_user]); } /** @@ -2988,7 +2990,7 @@ function api_format_items($r, $user_info, $filter_user = false, $type = "json") foreach ((array)$r as $item) { localize_item($item); - list($status_user, $owner_user) = api_item_get_user($a, $item); + list($status_user, $author_user, $owner_user) = api_item_get_user($a, $item); // Look if the posts are matching if they should be filtered by user id if ($filter_user && ($status_user["id"] != $user_info["id"])) { @@ -3020,6 +3022,7 @@ function api_format_items($r, $user_info, $filter_user = false, $type = "json") $geo => null, 'favorited' => $item['starred'] ? true : false, 'user' => $status_user, + 'friendica_author' => $author_user, 'friendica_owner' => $owner_user, 'friendica_private' => $item['private'] == 1, //'entities' => NULL, @@ -3063,6 +3066,7 @@ function api_format_items($r, $user_info, $filter_user = false, $type = "json") $retweeted_status['friendica_activities'] = api_format_items_activities($retweeted_item, $type); $retweeted_status['created_at'] = api_date($retweeted_item['created']); $status['retweeted_status'] = $retweeted_status; + $status['friendica_author'] = $retweeted_status['user']; } }