diff options
author | zotlabs <mike@macgirvin.com> | 2017-06-27 19:20:13 -0700 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2017-06-27 19:20:13 -0700 |
commit | 1273ac67f40c4c45807b178a9f679efc18bcc9c2 (patch) | |
tree | 2ad75a61e5e87d64c6db60b6b2a69408fafe3f55 /include/feedutils.php | |
parent | 676481de58d078c93789f696ac003936461575d7 (diff) | |
download | volse-hubzilla-1273ac67f40c4c45807b178a9f679efc18bcc9c2.tar.gz volse-hubzilla-1273ac67f40c4c45807b178a9f679efc18bcc9c2.tar.bz2 volse-hubzilla-1273ac67f40c4c45807b178a9f679efc18bcc9c2.zip |
(untested currently) fetch conversation for GNU-Social and Mastodon when provided a comment with no local copy of the parent.
Diffstat (limited to 'include/feedutils.php')
-rw-r--r-- | include/feedutils.php | 48 |
1 files changed, 47 insertions, 1 deletions
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. * |