]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Transmitter.php
Merge pull request #7092 from MrPetovan/task/7047-theme-error-page
[friendica.git] / src / Protocol / ActivityPub / Transmitter.php
index eb1da09b3a9a6e8eea5b915e7642d5ccf93b6ae8..a06fbdcf19b532a0cad73877deddc8e05fd4672f 100644 (file)
@@ -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,10 +255,29 @@ class Transmitter
                $data['icon'] = ['type' => 'Image',
                        'url' => $contact['avatar']];
 
+               $data['generator'] = self::getService();
+
                // tags: https://kitty.town/@inmysocks/100656097926961126.json
                return $data;
        }
 
+       /**
+        * @param string $username
+        * @return array
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
+       public static function getDeletedUser($username)
+       {
+               return [
+                       '@context' => ActivityPub::CONTEXT,
+                       'id' => System::baseUrl() . '/profile/' . $username,
+                       'type' => 'Tombstone',
+                       'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+                       'updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+                       'deleted' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+               ];
+       }
+
        /**
         * Returns an array with permissions of a given item array
         *
@@ -692,7 +723,7 @@ class Transmitter
                        $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
                        $conversation = DBA::selectFirst('conversation', ['source'], $condition);
                        if (DBA::isResult($conversation)) {
-                               $data = json_decode($conversation['source']);
+                               $data = json_decode($conversation['source'], true);
                                if (!empty($data)) {
                                        return $data;
                                }
@@ -724,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));
 
@@ -1182,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' => []];
 
@@ -1211,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' => []];
 
@@ -1250,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' => []];
 
@@ -1281,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' => []];
 
@@ -1317,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);
@@ -1366,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);
@@ -1396,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);
@@ -1426,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);
@@ -1463,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);