From 9753ccab33de32aeb917906caccf8c366378c36f Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 24 Apr 2019 19:06:39 +0000 Subject: [PATCH 1/3] API: Reshares and Quotes should now work in any combination --- include/api.php | 53 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/include/api.php b/include/api.php index ef2c05936f..a10c3a28c9 100644 --- a/include/api.php +++ b/include/api.php @@ -2981,14 +2981,35 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use } $retweeted_item = []; + $quoted_item = []; - $announce = api_get_announce($item); - if (!empty($announce) && ($item['owner-id'] == $item['author-id'])) { - $retweeted_item = $item; - $item = $announce; - $status['friendica_owner'] = api_get_user($a, $announce['author-id']); - } elseif ($item["id"] == $item["parent"]) { + if ($item["id"] == $item["parent"]) { + $body = $item['body']; $retweeted_item = api_share_as_retweet($item); + if ($body != $item['body']) { + $quoted_item = $retweeted_item; + $retweeted_item = []; + } + } + + if (empty($retweeted_item) && ($item['owner-id'] == $item['author-id'])) { + $announce = api_get_announce($item); + if (!empty($announce)) { + $retweeted_item = $item; + $item = $announce; + $status['friendica_owner'] = api_get_user($a, $announce['author-id']); + } + } + + if (!empty($quoted_item)) { + $quoted_status = api_convert_item($quoted_item); + try { + $quoted_status['friendica_owner'] = $quoted_status['friendica_author'] = $quoted_status["user"] = api_get_user($a, $quoted_item["author-id"]); + } catch (BadRequestException $e) { + // user not found. should be found? + /// @todo check if the user should be always found + $quoted_status["user"] = []; + } } if (!empty($retweeted_item)) { @@ -3009,8 +3030,19 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use $retweeted_status['friendica_activities'] = api_format_items_activities($retweeted_item, $type); $retweeted_status['created_at'] = api_date($retweeted_item['created']); $retweeted_status['friendica_owner'] = $retweeted_status['friendica_author']; - $status['retweeted_status'] = $retweeted_status; + + if (!empty($quoted_status)) { + $retweeted_status['quoted_status'] = $quoted_status; + } + $status['friendica_author'] = $retweeted_status['friendica_author']; + $status['retweeted_status'] = $retweeted_status; + } elseif (!empty($quoted_status)) { + $root_status = api_convert_item($item); + + $status['text'] = $root_status["text"]; + $status['statusnet_html'] = $root_status["html"]; + $status['quoted_status'] = $quoted_status; } // "uid" and "self" are only needed for some internal stuff, so remove it from here @@ -5117,7 +5149,12 @@ function api_share_as_retweet(&$item) $posted = $matches[1]; } - $shared_body = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$2", $body); + $pre_body = trim(preg_replace("/(.*?)\[share.*?\]\s?.*?\s?\[\/share\]\s?/ism", "$1", $body)); + if ($pre_body != '') { + $item['body'] = $pre_body; + } + + $shared_body = trim(preg_replace("/(.*?)\[share.*?\]\s?(.*?)\s?\[\/share\]\s?/ism", "$2", $body)); if (($shared_body == "") || ($profile == "") || ($author == "") || ($avatar == "") || ($posted == "")) { return false; From d778a29e04291b30c4971fd7878f7b2c785a9fe0 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 24 Apr 2019 20:46:12 +0000 Subject: [PATCH 2/3] Use all fields --- include/api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index a10c3a28c9..1d057a233f 100644 --- a/include/api.php +++ b/include/api.php @@ -3002,7 +3002,10 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use } if (!empty($quoted_item)) { - $quoted_status = api_convert_item($quoted_item); + $conv_quoted = api_convert_item($quoted_item); + $quoted_status = $status; + $quoted_status['text'] = $conv_quoted['text']; + $quoted_status['statusnet_html'] = $conv_quoted['html']; try { $quoted_status['friendica_owner'] = $quoted_status['friendica_author'] = $quoted_status["user"] = api_get_user($a, $quoted_item["author-id"]); } catch (BadRequestException $e) { From d4b7e0083766043f7dd50af06c14627af3487f94 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 24 Apr 2019 21:28:56 +0000 Subject: [PATCH 3/3] Cleaning up transmitted fields (only needed for the root entry) --- include/api.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/include/api.php b/include/api.php index 1d057a233f..698fa2f995 100644 --- a/include/api.php +++ b/include/api.php @@ -3004,10 +3004,15 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use if (!empty($quoted_item)) { $conv_quoted = api_convert_item($quoted_item); $quoted_status = $status; + unset($quoted_status['friendica_author']); + unset($quoted_status['friendica_owner']); + unset($quoted_status['friendica_activities']); + unset($quoted_status['friendica_private']); + unset($quoted_status['statusnet_conversation_id']); $quoted_status['text'] = $conv_quoted['text']; $quoted_status['statusnet_html'] = $conv_quoted['html']; try { - $quoted_status['friendica_owner'] = $quoted_status['friendica_author'] = $quoted_status["user"] = api_get_user($a, $quoted_item["author-id"]); + $quoted_status["user"] = api_get_user($a, $quoted_item["author-id"]); } catch (BadRequestException $e) { // user not found. should be found? /// @todo check if the user should be always found @@ -3017,9 +3022,14 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use if (!empty($retweeted_item)) { $retweeted_status = $status; + unset($retweeted_status['friendica_author']); + unset($retweeted_status['friendica_owner']); + unset($retweeted_status['friendica_activities']); + unset($retweeted_status['friendica_private']); + unset($retweeted_status['statusnet_conversation_id']); $status['user'] = $status['friendica_owner']; try { - $retweeted_status['friendica_author'] = $retweeted_status["user"] = api_get_user($a, $retweeted_item["author-id"]); + $retweeted_status["user"] = api_get_user($a, $retweeted_item["author-id"]); } catch (BadRequestException $e) { // user not found. should be found? /// @todo check if the user should be always found @@ -3030,15 +3040,13 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use $retweeted_status['text'] = $rt_converted["text"]; $retweeted_status['statusnet_html'] = $rt_converted["html"]; - $retweeted_status['friendica_activities'] = api_format_items_activities($retweeted_item, $type); $retweeted_status['created_at'] = api_date($retweeted_item['created']); - $retweeted_status['friendica_owner'] = $retweeted_status['friendica_author']; if (!empty($quoted_status)) { $retweeted_status['quoted_status'] = $quoted_status; } - $status['friendica_author'] = $retweeted_status['friendica_author']; + $status['friendica_author'] = $retweeted_status['user']; $status['retweeted_status'] = $retweeted_status; } elseif (!empty($quoted_status)) { $root_status = api_convert_item($item);