process activity deletes from OStatus which for whatever reason do not use the industry standard tombstone mechanism
This commit is contained in:
parent
1fd2b6f5b6
commit
617f2863c4
1
boot.php
1
boot.php
@ -497,6 +497,7 @@ define ( 'ACTIVITY_TAG', NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
|
||||
define ( 'ACTIVITY_SHARE', NAMESPACE_ACTIVITY_SCHEMA . 'share' );
|
||||
define ( 'ACTIVITY_FAVORITE', NAMESPACE_ACTIVITY_SCHEMA . 'favorite' );
|
||||
define ( 'ACTIVITY_CREATE', NAMESPACE_ACTIVITY_SCHEMA . 'create' );
|
||||
define ( 'ACTIVITY_DELETE', NAMESPACE_ACTIVITY_SCHEMA . 'delete' );
|
||||
define ( 'ACTIVITY_WIN', NAMESPACE_ACTIVITY_SCHEMA . 'win' );
|
||||
define ( 'ACTIVITY_LOSE', NAMESPACE_ACTIVITY_SCHEMA . 'lose' );
|
||||
define ( 'ACTIVITY_TIE', NAMESPACE_ACTIVITY_SCHEMA . 'tie' );
|
||||
|
@ -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
|
||||
// Check at the feed level for tombstones
|
||||
|
||||
$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');
|
||||
}
|
||||
process_feed_tombstones($feed,$importer,$contact,$pass);
|
||||
|
||||
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'])
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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'])) {
|
||||
|
||||
|
Reference in New Issue
Block a user