From 1a702359f10e34230e1cfae90d335752f8576e70 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 10 Jan 2019 07:24:12 +0000 Subject: [PATCH 1/2] Unfollow should now work with Pleroma again --- src/Model/Contact.php | 10 +++++-- src/Protocol/ActivityPub/Transmitter.php | 38 +++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 7ff0032d23..8754f1c5ff 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -598,7 +598,7 @@ class Contact extends BaseObject } elseif ($contact['network'] == Protocol::DIASPORA) { Diaspora::sendUnshare($user, $contact); } elseif ($contact['network'] == Protocol::ACTIVITYPUB) { - ActivityPub\Transmitter::sendContactUndo($contact['url'], $user['uid']); + ActivityPub\Transmitter::sendContactUndo($contact['url'], $contact['id'], $user['uid']); if ($dissolve) { ActivityPub\Transmitter::sendContactReject($contact['url'], $contact['hub-verify'], $user['uid']); @@ -1822,7 +1822,13 @@ class Contact extends BaseObject $ret = Diaspora::sendShare($a->user, $contact); Logger::log('share returns: ' . $ret); } elseif ($contact['network'] == Protocol::ACTIVITYPUB) { - $ret = ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid); + $activity_id = ActivityPub\Transmitter::activityIDFromContact($contact_id); + if (empty($activity_id)) { + // This really should never happen + return false; + } + + $ret = ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid, $activity_id); Logger::log('Follow returns: ' . $ret); } } diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index e70e618477..f09c18165b 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -997,6 +997,25 @@ class Transmitter return $announce['plink']; } + /** + * Creates an activity id for a given contact id + * + * @param integer $cid Contact ID of target + * + * @return bool|string activity id + */ + public static function activityIDFromContact($cid) + { + $contact = DBA::selectFirst('contact', ['uid', 'id', 'created'], ['id' => $cid]); + if (!DBA::isResult($contact)) { + return false; + } + + $hash = hash('ripemd128', $contact['uid'].'-'.$contact['id'].'-'.$contact['created']); + $uuid = substr($hash, 0, 8). '-' . substr($hash, 8, 4) . '-' . substr($hash, 12, 4) . '-' . substr($hash, 16, 4) . '-' . substr($hash, 20, 12); + return System::baseUrl() . '/activity/' . $uuid; + } + /** * Transmits a contact suggestion to a given inbox * @@ -1119,15 +1138,20 @@ class Transmitter * @param array $activity * @param string $target Target profile * @param integer $uid User ID + * @param string $id activity id */ - public static function sendActivity($activity, $target, $uid) + public static function sendActivity($activity, $target, $uid, $id = '') { $profile = APContact::getByURL($target); $owner = User::getOwnerDataById($uid); + if (empty($id)) { + $id = System::baseUrl() . '/activity/' . System::createGUID(); + } + $data = ['@context' => ActivityPub::CONTEXT, - 'id' => System::baseUrl() . '/activity/' . System::createGUID(), + 'id' => $id, 'type' => $activity, 'actor' => $owner['url'], 'object' => $profile['url'], @@ -1200,12 +1224,18 @@ class Transmitter * Transmits a message that we don't want to follow this contact anymore * * @param string $target Target profile + * @param integer $cid Contact ID of target * @param integer $uid User ID */ - public static function sendContactUndo($target, $uid) + public static function sendContactUndo($target, $cid, $uid) { $profile = APContact::getByURL($target); + $object_id = self::activityIDFromContact($cid); + if (empty($object_id)) { + return; + } + $id = System::baseUrl() . '/activity/' . System::createGUID(); $owner = User::getOwnerDataById($uid); @@ -1213,7 +1243,7 @@ class Transmitter 'id' => $id, 'type' => 'Undo', 'actor' => $owner['url'], - 'object' => ['id' => $id, 'type' => 'Follow', + 'object' => ['id' => $object_id, 'type' => 'Follow', 'actor' => $owner['url'], 'object' => $profile['url']], 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], From cc6836b89cc4a074d27398b44f97ec42ca3598ba Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 10 Jan 2019 09:19:19 +0000 Subject: [PATCH 2/2] Pending must only be set when we connect as well --- mod/dfrn_confirm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index c78cf45e72..848c25832c 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -337,7 +337,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) } else { if ($network == Protocol::ACTIVITYPUB) { ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid); - $pending = true; + $pending = $duplex; } else { $pending = false; }