From 581895c07d495cb1e7f2fd5cc260d5efc545d710 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 30 Apr 2019 20:07:20 +0200 Subject: [PATCH] Preparation for switching the connect mechanism from DFRN to AP --- mod/dfrn_confirm.php | 9 +++++++ src/Protocol/ActivityPub/Transmitter.php | 34 +++++++++++++++++------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 770c7070b4..97d19f1b71 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -24,6 +24,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\Model\APContact; use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\User; @@ -143,6 +144,14 @@ function dfrn_confirm_post(App $a, $handsfree = null) $network = $contact['network']; } + // an empty DFRN-ID tells us that it had been a request via AP from a Friendica contact + if (($network === Protocol::DFRN) && empty($dfrn_id) && !empty($contact['hub-verify'])) { + $apcontact = APContact::getByURL($contact['url']); + if (!empty($apcontact)) { + $network = Protocol::ACTIVITYPUB; + } + } + if ($network === Protocol::DFRN) { /* * Generate a key pair for all further communications with this person. diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index fd79318c5b..a06fbdcf19 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -187,6 +187,18 @@ class Transmitter return $data; } + /** + * Return the service array containing information the used software and it's url + * + * @return array with service data + */ + private static function getService() + { + return ['type' => 'Service', + 'name' => FRIENDICA_PLATFORM . " '" . FRIENDICA_CODENAME . "' " . FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, + 'url' => BaseObject::getApp()->getBaseURL()]; + } + /** * Return the ActivityPub profile of the given user * @@ -243,6 +255,8 @@ class Transmitter $data['icon'] = ['type' => 'Image', 'url' => $contact['avatar']]; + $data['generator'] = self::getService(); + // tags: https://kitty.town/@inmysocks/100656097926961126.json return $data; } @@ -741,7 +755,7 @@ class Transmitter $data['published'] = DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM); - $data['instrument'] = ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()]; + $data['instrument'] = self::getService(); $data = array_merge($data, self::createPermissionBlockForItem($item, false)); @@ -1199,7 +1213,7 @@ class Transmitter 'actor' => $owner['url'], 'object' => $suggestion['url'], 'content' => $suggestion['note'], - 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], + 'instrument' => self::getService(), 'to' => [ActivityPub::PUBLIC_COLLECTION], 'cc' => []]; @@ -1228,7 +1242,7 @@ class Transmitter 'actor' => $owner['url'], 'object' => $owner['url'], 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), - 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], + 'instrument' => self::getService(), 'to' => [ActivityPub::PUBLIC_COLLECTION], 'cc' => []]; @@ -1267,7 +1281,7 @@ class Transmitter 'actor' => $owner['url'], 'object' => $owner['url'], 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), - 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], + 'instrument' => self::getService(), 'to' => [ActivityPub::PUBLIC_COLLECTION], 'cc' => []]; @@ -1298,7 +1312,7 @@ class Transmitter 'actor' => $owner['url'], 'object' => self::getProfile($uid), 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), - 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], + 'instrument' => self::getService(), 'to' => [$profile['followers']], 'cc' => []]; @@ -1334,7 +1348,7 @@ class Transmitter 'type' => $activity, 'actor' => $owner['url'], 'object' => $profile['url'], - 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], + 'instrument' => self::getService(), 'to' => [$profile['url']]]; Logger::log('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, Logger::DEBUG); @@ -1383,7 +1397,7 @@ class Transmitter 'type' => 'Follow', 'actor' => $owner['url'], 'object' => $object, - 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], + 'instrument' => self::getService(), 'to' => [$profile['url']]]; Logger::log('Sending follow ' . $object . ' to ' . $target . ' for user ' . $uid, Logger::DEBUG); @@ -1413,7 +1427,7 @@ class Transmitter 'object' => ['id' => $id, 'type' => 'Follow', 'actor' => $profile['url'], 'object' => $owner['url']], - 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], + 'instrument' => self::getService(), 'to' => [$profile['url']]]; Logger::log('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG); @@ -1443,7 +1457,7 @@ class Transmitter 'object' => ['id' => $id, 'type' => 'Follow', 'actor' => $profile['url'], 'object' => $owner['url']], - 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], + 'instrument' => self::getService(), 'to' => [$profile['url']]]; Logger::log('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG); @@ -1480,7 +1494,7 @@ class Transmitter 'object' => ['id' => $object_id, 'type' => 'Follow', 'actor' => $owner['url'], 'object' => $profile['url']], - 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], + 'instrument' => self::getService(), 'to' => [$profile['url']]]; Logger::log('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG); -- 2.39.5