aboutsummaryrefslogtreecommitdiffstats
path: root/include/feedutils.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/feedutils.php')
-rw-r--r--include/feedutils.php95
1 files changed, 58 insertions, 37 deletions
diff --git a/include/feedutils.php b/include/feedutils.php
index 451946114..217da8188 100644
--- a/include/feedutils.php
+++ b/include/feedutils.php
@@ -900,6 +900,41 @@ function encode_rel_links($links) {
return $o;
}
+
+function process_feed_tombstones($feed,$importer,$contact,$pass) {
+
+ $arr_deleted = [];
+
+ $del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry');
+ if(is_array($del_entries) && count($del_entries) && $pass != 2) {
+ foreach($del_entries as $dentry) {
+ if(isset($dentry['attribs']['']['ref'])) {
+ $arr_deleted[] = normalise_id($dentry['attribs']['']['ref']);
+ }
+ }
+ }
+
+ if($arr_deleted && is_array($contact)) {
+ foreach($arr_deleted as $mid) {
+ $r = q("SELECT * from item where mid = '%s' and author_xchan = '%s' and uid = %d limit 1",
+ dbesc($mid),
+ dbesc($contact['xchan_hash']),
+ intval($importer['channel_id'])
+ );
+
+ if($r) {
+ $item = $r[0];
+
+ if(! intval($item['item_deleted'])) {
+ logger('deleting item ' . $item['id'] . ' mid=' . $item['mid'], LOGGER_DEBUG);
+ drop_item($item['id'],false);
+ }
+ }
+ }
+ }
+}
+
+
/**
* @brief Process atom feed and update anything/everything we might need to update.
*
@@ -955,43 +990,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) {
$permalink = $feed->get_permalink();
- // Check at the feed level for updated contact name and/or photo
-
- // process any deleted entries
-
- $del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry');
- if(is_array($del_entries) && count($del_entries) && $pass != 2) {
- foreach($del_entries as $dentry) {
- $deleted = false;
- if(isset($dentry['attribs']['']['ref'])) {
- $mid = normalise_id($dentry['attribs']['']['ref']);
- $deleted = true;
- if(isset($dentry['attribs']['']['when'])) {
- $when = $dentry['attribs']['']['when'];
- $when = datetime_convert('UTC','UTC', $when, 'Y-m-d H:i:s');
- }
- else
- $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
- }
- if($deleted && is_array($contact)) {
- $r = q("SELECT * from item where mid = '%s' and author_xchan = '%s' and uid = %d limit 1",
- dbesc($mid),
- dbesc($contact['xchan_hash']),
- intval($importer['channel_id'])
- );
+ // Check at the feed level for tombstones
- if($r) {
- $item = $r[0];
+ process_feed_tombstones($feed,$importer,$contact,$pass);
- if(! intval($item['item_deleted'])) {
- logger('deleting item ' . $item['id'] . ' mid=' . $item['mid'], LOGGER_DEBUG);
- drop_item($item['id'],false);
- }
- }
- }
- }
- }
// Now process the feed
@@ -1033,6 +1036,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) {
if(! $datarray['mid'])
continue;
+
$item_parent_mid = q("select parent_mid from item where mid = '%s' and uid = %d limit 1",
dbesc($parent_mid),
intval($importer['channel_id'])
@@ -1090,7 +1094,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) {
$datarray['owner_xchan'] = $contact['xchan_hash'];
- $r = q("SELECT id, edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1",
+ $r = q("SELECT id, edited, author_xchan, item_deleted FROM item WHERE mid = '%s' AND uid = %d LIMIT 1",
dbesc($datarray['mid']),
intval($importer['channel_id'])
);
@@ -1099,6 +1103,15 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) {
// Update content if 'updated' changes
if($r) {
+ if(activity_match($datarray['verb'],ACTIVITY_DELETE)
+ && $datarray['author_xchan'] === $r[0]['author_xchan']) {
+ if(! intval($r[0]['item_deleted'])) {
+ logger('deleting item ' . $r[0]['id'] . ' mid=' . $datarray['mid'], LOGGER_DEBUG);
+ drop_item($r[0]['id'],false);
+ }
+ continue;
+ }
+
if((x($datarray,'edited') !== false)
&& (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
@@ -1343,8 +1356,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) {
}
}
-
- $r = q("SELECT id, edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1",
+ $r = q("SELECT id, edited, author_xchan, item_deleted FROM item WHERE mid = '%s' AND uid = %d LIMIT 1",
dbesc($datarray['mid']),
intval($importer['channel_id'])
);
@@ -1352,6 +1364,15 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) {
// Update content if 'updated' changes
if($r) {
+ if(activity_match($datarray['verb'],ACTIVITY_DELETE)
+ && $datarray['author_xchan'] === $r[0]['author_xchan']) {
+ if(! intval($r[0]['item_deleted'])) {
+ logger('deleting item ' . $r[0]['id'] . ' mid=' . $datarray['mid'], LOGGER_DEBUG);
+ drop_item($r[0]['id'],false);
+ }
+ continue;
+ }
+
if((x($datarray,'edited') !== false)
&& (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {