Merge pull request #3704 from annando/ostatus-improved

OStatus: Only fetch items that don't exist in the system
This commit is contained in:
Tobias Diekershoff 2017-09-15 07:18:14 +02:00 committed by GitHub
commit ad3566aeaa
1 changed files with 33 additions and 21 deletions

View File

@ -373,7 +373,7 @@ class ostatus {
$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue; $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
/// Delete a message /// Delete a message
if ($item["verb"] == "qvitter-delete-notice" || $item["verb"] == ACTIVITY_DELETE) { if (in_array($item["verb"], array('qvitter-delete-notice', ACTIVITY_DELETE, 'delete'))) {
// ignore "Delete" messages (by now) // ignore "Delete" messages (by now)
logger("Ignore delete message ".print_r($item, true)); logger("Ignore delete message ".print_r($item, true));
continue; continue;
@ -411,6 +411,8 @@ class ostatus {
} }
// http://activitystrea.ms/schema/1.0/rsvp-yes // http://activitystrea.ms/schema/1.0/rsvp-yes
// http://activitystrea.ms/schema/1.0/unfavorite
// http://mastodon.social/schema/1.0/block
if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE))) { if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE))) {
logger("Unhandled verb ".$item["verb"]." ".print_r($item, true)); logger("Unhandled verb ".$item["verb"]." ".print_r($item, true));
} }
@ -418,27 +420,26 @@ class ostatus {
self::processPost($xpath, $entry, $item, $importer); self::processPost($xpath, $entry, $item, $importer);
if ($initialize && (count(self::$itemlist) > 0)) { if ($initialize && (count(self::$itemlist) > 0)) {
// We will import it everytime, when it is started by our contacts if (self::$itemlist[0]['uri'] == self::$itemlist[0]['parent-uri']) {
$valid = !empty(self::$itemlist[0]['contact-id']); // We will import it everytime, when it is started by our contacts
if (!$valid) { $valid = !empty(self::$itemlist[0]['contact-id']);
// If not, then it depends on this setting if (!$valid) {
$valid = !Config::get('system','ostatus_full_threads'); // If not, then it depends on this setting
} $valid = !Config::get('system','ostatus_full_threads');
}
if ($valid) { if ($valid) {
// But we will only import complete threads // Never post a thread when the only interaction by our contact was a like
$valid = self::$itemlist[0]['uri'] == self::$itemlist[0]['parent-uri']; $valid = false;
} $verbs = array(ACTIVITY_POST, ACTIVITY_SHARE);
foreach (self::$itemlist AS $item) {
if ($valid) { if (!empty($item['contact-id']) && in_array($item['verb'], $verbs)) {
// Never post a thread when the only interaction by our contact was a like $valid = true;
$valid = false; }
$verbs = array(ACTIVITY_POST, ACTIVITY_SHARE);
foreach (self::$itemlist AS $item) {
if (!empty($item['contact-id']) && in_array($item['verb'], $verbs)) {
$valid = true;
} }
} }
} else {
// But we will only import complete threads
$valid = dba::exists('item', array('uid' => $importer["uid"], 'uri' => self::$itemlist[0]['parent-uri']));
} }
if ($valid) { if ($valid) {
@ -477,6 +478,12 @@ class ostatus {
*/ */
private static function processPost($xpath, $entry, &$item, $importer) { private static function processPost($xpath, $entry, &$item, $importer) {
$item["uri"] = $xpath->query('atom:id/text()', $entry)->item(0)->nodeValue; $item["uri"] = $xpath->query('atom:id/text()', $entry)->item(0)->nodeValue;
if (dba::exists('item', array('uid' => $importer["uid"], 'uri' => $item["uri"]))) {
logger('Post with URI '.$item["uri"].' already existed for user '.$importer["uid"].'.');
return;
}
$item["body"] = html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue); $item["body"] = html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue);
$item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue; $item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue;
if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) { if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
@ -591,7 +598,12 @@ class ostatus {
} }
if (isset($item["parent-uri"]) && ($related != '')) { if (isset($item["parent-uri"]) && ($related != '')) {
self::fetchRelated($related, $item["parent-uri"], $importer); if (!dba::exists('item', array('uid' => $importer["uid"], 'uri' => $item['parent-uri']))) {
self::fetchRelated($related, $item["parent-uri"], $importer);
} else {
logger('Reply with URI '.$item["uri"].' already existed for user '.$importer["uid"].'.');
}
$item["type"] = 'remote-comment'; $item["type"] = 'remote-comment';
$item["gravity"] = GRAVITY_COMMENT; $item["gravity"] = GRAVITY_COMMENT;
} else { } else {