From 9468b7427d82d4ee5da7fc8f36d37f49c37c2bc0 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Sep 2017 10:00:45 +0000 Subject: [PATCH 1/3] Allow replies as well --- include/ostatus.php | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 0c99905fa4..099c0516e8 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -418,27 +418,26 @@ class ostatus { self::processPost($xpath, $entry, $item, $importer); if ($initialize && (count(self::$itemlist) > 0)) { - // We will import it everytime, when it is started by our contacts - $valid = !empty(self::$itemlist[0]['contact-id']); - if (!$valid) { - // If not, then it depends on this setting - $valid = !Config::get('system','ostatus_full_threads'); - } - - if ($valid) { - // But we will only import complete threads - $valid = self::$itemlist[0]['uri'] == self::$itemlist[0]['parent-uri']; - } - - if ($valid) { - // Never post a thread when the only interaction by our contact was a like - $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; + if (self::$itemlist[0]['uri'] == self::$itemlist[0]['parent-uri']) { + // We will import it everytime, when it is started by our contacts + $valid = !empty(self::$itemlist[0]['contact-id']); + if (!$valid) { + // If not, then it depends on this setting + $valid = !Config::get('system','ostatus_full_threads'); + } + if ($valid) { + // Never post a thread when the only interaction by our contact was a like + $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) { From 9dfb9c1c456458b6db3bcf471a4f7dda1dca9bfa Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Sep 2017 19:23:14 +0000 Subject: [PATCH 2/3] Only fetch items that don't exist in the system --- include/ostatus.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/ostatus.php b/include/ostatus.php index 099c0516e8..7169359553 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -476,6 +476,12 @@ class ostatus { */ private static function processPost($xpath, $entry, &$item, $importer) { $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["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)) { @@ -590,7 +596,12 @@ class ostatus { } 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["gravity"] = GRAVITY_COMMENT; } else { From 87fffde80ec986d135c28816ad59f3afb102b085 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Sep 2017 20:40:05 +0000 Subject: [PATCH 3/3] Documented some unknown verbs --- include/ostatus.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/ostatus.php b/include/ostatus.php index 7169359553..45ac8061c9 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -373,7 +373,7 @@ class ostatus { $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue; /// 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) logger("Ignore delete message ".print_r($item, true)); continue; @@ -411,6 +411,8 @@ class ostatus { } // 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))) { logger("Unhandled verb ".$item["verb"]." ".print_r($item, true)); }