1
0
Fork 0

Merge pull request #6419 from annando/unfollow

Unfollow should now work with Pleroma again
This commit is contained in:
Tobias Diekershoff 2019-01-10 11:08:23 +01:00 committed by GitHub
commit 59f701d5a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 7 deletions

View file

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

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