From 1273ac67f40c4c45807b178a9f679efc18bcc9c2 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 27 Jun 2017 19:20:13 -0700 Subject: (untested currently) fetch conversation for GNU-Social and Mastodon when provided a comment with no local copy of the parent. --- include/feedutils.php | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'include/feedutils.php') diff --git a/include/feedutils.php b/include/feedutils.php index 2a0dba982..8bd4673f5 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -971,6 +971,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { foreach($items as $item) { $is_reply = false; + $parent_link = ''; logger('processing ' . $item->get_id(), LOGGER_DEBUG); @@ -979,6 +980,9 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $is_reply = true; $parent_mid = normalise_id($rawthread[0]['attribs']['']['ref']); } + if(isset($rawthread[0]['attribs']['']['href'])) { + $parent_link = $rawthread[0]['attribs']['']['href']; + } if($is_reply) { @@ -1050,7 +1054,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { intval($importer['channel_id']) ); if($c) { - $pmid = $x[0]['parent_mid']; + $pmid = $c[0]['parent_mid']; $datarray['parent_mid'] = $pmid; } } @@ -1065,6 +1069,20 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['parent_mid'] = $pmid; } } + if((! $pmid) && $parent_link !== '') { + $f = feed_conversation_fetch($importer,$contact,$parent_link); + if($f) { + $x = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", + dbesc($parent_mid), + intval($importer['channel_id']) + ); + + if($x) { + $pmid = $x[0]['parent_mid']; + $datarray['parent_mid'] = $pmid; + } + } + } if(! $pmid) { @@ -1195,6 +1213,34 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } } + +function feed_conversation_fetch($importer,$contact,$parent_link) { + + $link = ''; + + // GNU-Social flavoured feeds + if(strpos($parent_link,'/notice/')) { + $link = str_replace('/notice/','/api/statuses/show',$link) . '.atom'; + } + + // Mastodon flavoured feeds + if(strpos($parent_link,'/users/') && strpos($parent_link,'/updates/')) { + $link = $parent_link . '.xml'; + } + + if(! $link) + return false; + + $fetch = z_fetch_url($link); + + if(! $fetch['success']) + return false; + + consume_feed($fetch['body'],$importer,$contact,1); + consume_feed($fetch['body'],$importer,$contact,2); + +} + /** * @brief Normalise an id. * -- cgit v1.2.3