Unfollow should now work with Pleroma again

This commit is contained in:
Michael 2019-01-10 07:24:12 +00:00
parent cd48b7a68e
commit 1a702359f1
2 changed files with 42 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -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()],