From: Michael Date: Fri, 2 Nov 2018 21:57:06 +0000 (+0000) Subject: Preparations for a relocation message / fix for notice X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1395bdc1881e8e8ecac3823f62648d250fcf7874;p=friendica.git Preparations for a relocation message / fix for notice --- diff --git a/src/Model/APContact.php b/src/Model/APContact.php index c7cf54b720..917e0895dc 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -106,6 +106,10 @@ class APContact extends BaseObject $compacted = JsonLD::compact($data); + if (empty($compacted['@id'])) { + return false; + } + $apcontact = []; $apcontact['url'] = $compacted['@id']; $apcontact['uuid'] = JsonLD::fetchElement($compacted, 'diaspora:guid'); diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index e6701074c6..107cc423a6 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -40,6 +40,7 @@ class ActivityPub const PUBLIC_COLLECTION = 'https://www.w3.org/ns/activitystreams#Public'; const CONTEXT = ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', ['vcard' => 'http://www.w3.org/2006/vcard/ns#', + 'dfrn' => 'http://purl.org/macgirvin/dfrn/1.0/', 'diaspora' => 'https://diasporafoundation.org/ns/', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag']]; diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index d3043c530b..64b98e17e7 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -1000,11 +1000,10 @@ class Transmitter public static function sendContactSuggestion($uid, $inbox, $suggestion_id) { $owner = User::getOwnerDataById($uid); - $profile = APContact::getByURL($owner['url']); $suggestion = DBA::selectFirst('fsuggest', ['url', 'note', 'created'], ['id' => $suggestion_id]); - $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + $data = ['@context' => ActivityPub::CONTEXT, 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => 'Announce', 'actor' => $owner['url'], @@ -1020,6 +1019,34 @@ class Transmitter return HTTPSignature::transmit($signed, $inbox, $uid); } + /** + * Transmits a profile relocation to a given inbox + * + * @param integer $uid User ID + * @param string $inbox Target inbox + * + * @return boolean was the transmission successful? + */ + public static function sendProfileRelocation($uid, $inbox) + { + $owner = User::getOwnerDataById($uid); + + $data = ['@context' => ActivityPub::CONTEXT, + 'id' => System::baseUrl() . '/activity/' . System::createGUID(), + 'type' => 'dfrn:relocate', + 'actor' => $owner['url'], + 'object' => $owner['url'], + 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), + 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()], + 'to' => [ActivityPub::PUBLIC_COLLECTION], + 'cc' => []]; + + $signed = LDSignature::sign($data, $owner); + + Logger::log('Deliver profile relocation for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG); + return HTTPSignature::transmit($signed, $inbox, $uid); + } + /** * Transmits a profile deletion to a given inbox * @@ -1031,9 +1058,8 @@ class Transmitter public static function sendProfileDeletion($uid, $inbox) { $owner = User::getOwnerDataById($uid); - $profile = APContact::getByURL($owner['url']); - $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + $data = ['@context' => ActivityPub::CONTEXT, 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => 'Delete', 'actor' => $owner['url'], @@ -1062,7 +1088,7 @@ class Transmitter $owner = User::getOwnerDataById($uid); $profile = APContact::getByURL($owner['url']); - $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + $data = ['@context' => ActivityPub::CONTEXT, 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => 'Update', 'actor' => $owner['url'], @@ -1091,7 +1117,7 @@ class Transmitter $owner = User::getOwnerDataById($uid); - $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + $data = ['@context' => ActivityPub::CONTEXT, 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => $activity, 'actor' => $owner['url'], @@ -1117,7 +1143,7 @@ class Transmitter $profile = APContact::getByURL($target); $owner = User::getOwnerDataById($uid); - $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + $data = ['@context' => ActivityPub::CONTEXT, 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => 'Accept', 'actor' => $owner['url'], @@ -1145,7 +1171,7 @@ class Transmitter $profile = APContact::getByURL($target); $owner = User::getOwnerDataById($uid); - $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + $data = ['@context' => ActivityPub::CONTEXT, 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => 'Reject', 'actor' => $owner['url'], @@ -1174,7 +1200,7 @@ class Transmitter $id = System::baseUrl() . '/activity/' . System::createGUID(); $owner = User::getOwnerDataById($uid); - $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + $data = ['@context' => ActivityPub::CONTEXT, 'id' => $id, 'type' => 'Undo', 'actor' => $owner['url'], diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index feaf3e62f5..bed7a67d60 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -85,11 +85,12 @@ class JsonLD $context = (object)['as' => 'https://www.w3.org/ns/activitystreams#', 'w3id' => 'https://w3id.org/security#', + 'ldp' => (object)['@id' => 'http://www.w3.org/ns/ldp#', '@type' => '@id'], 'vcard' => (object)['@id' => 'http://www.w3.org/2006/vcard/ns#', '@type' => '@id'], - 'ostatus' => (object)['@id' => 'http://ostatus.org#', '@type' => '@id'], + 'dfrn' => (object)['@id' => 'http://purl.org/macgirvin/dfrn/1.0/', '@type' => '@id'], 'diaspora' => (object)['@id' => 'https://diasporafoundation.org/ns/', '@type' => '@id'], - 'dc' => (object)['@id' => 'http://purl.org/dc/terms/', '@type' => '@id'], - 'ldp' => (object)['@id' => 'http://www.w3.org/ns/ldp#', '@type' => '@id']]; + 'ostatus' => (object)['@id' => 'http://ostatus.org#', '@type' => '@id'], + 'dc' => (object)['@id' => 'http://purl.org/dc/terms/', '@type' => '@id']]; $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));