]> git.mxchange.org Git - friendica.git/commitdiff
The transmitted language is now stored
authorMichael <heluecht@pirati.ca>
Thu, 9 Nov 2023 21:31:34 +0000 (21:31 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 9 Nov 2023 21:31:34 +0000 (21:31 +0000)
src/Model/Item.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php

index 491050c582f2f7d3acff45f30cd052e24196b25b..06838630ac9b477b03334d67fc09088ae28e9a68 100644 (file)
@@ -2002,13 +2002,23 @@ class Item
                        return $item['language'];
                }
 
+               $transmitted = [];
+               foreach ($item['transmitted-languages'] ??  [] as $language) {
+                       $transmitted[$language] = 0;
+               }
+
                if (!in_array($item['gravity'], [self::GRAVITY_PARENT, self::GRAVITY_COMMENT]) || empty($item['body'])) {
-                       return '';
+                       return empty($transmitted) ? '' : json_encode($transmitted);
                }
 
                $languages = self::getLanguageArray($item['title'] . ' ' . ($item['content-warning'] ?? '') . ' ' . $item['body'], 3, $item['uri-id'], $item['author-id']);
                if (empty($languages)) {
-                       return '';
+                       return empty($transmitted) ? '' : json_encode($transmitted);
+               }
+
+               if (!empty($transmitted)) {
+                       $languages = array_merge($transmitted, $languages);
+                       arsort($languages);
                }
 
                return json_encode($languages);
@@ -2209,7 +2219,7 @@ class Item
 
                // Glue it together to be able to make a hash from it
                if (!empty($parsed)) {
-                       $host_id = implode('/', $parsed);
+                       $host_id = implode('/', (array)$parsed);
                } else {
                        $host_id = $uri;
                }
@@ -3435,7 +3445,7 @@ class Item
                unset($urlparts['fragment']);
 
                try {
-                       $url = (string)Uri::fromParts($urlparts);
+                       $url = (string)Uri::fromParts((array)$urlparts);
                } catch (\InvalidArgumentException $e) {
                        DI::logger()->notice('Invalid URL', ['$url' => $url, '$urlparts' => $urlparts]);
                        /* See https://github.com/friendica/friendica/issues/12113
index 83c068e0edca7a170be3ac9617139383b88c3af9..49116444ad229620aa935845ccfc1fd9f5cda4be 100644 (file)
@@ -854,6 +854,8 @@ class Processor
                        $item['language'] = self::processLanguages($activity['languages']);
                }
 
+               $item['transmitted-languages'] = $activity['transmitted-languages'];
+
                if (!empty($activity['emojis'])) {
                        $content = self::replaceEmojis($item['uri-id'], $content, $activity['emojis']);
                }
@@ -1727,7 +1729,7 @@ class Processor
                        }
                }
 
-               $languages = self::getPostLanguages($activity);
+               $languages = self::getPostLanguages($activity['as:object'] ?? '');
 
                return Relay::isSolicitedPost($messageTags, $content, $authorid, $id, Protocol::ACTIVITYPUB, $activity['thread-completion'] ?? 0, $languages);
        }
@@ -1738,10 +1740,10 @@ class Processor
         * @param array $activity
         * @return array
         */
-       private static function getPostLanguages(array $activity): array
+       public static function getPostLanguages(array $activity): array
        {
-               $content   = JsonLD::fetchElement($activity['as:object'], 'as:content') ?? '';
-               $languages = JsonLD::fetchElementArray($activity['as:object'], 'as:content', '@language') ?? [];
+               $content   = JsonLD::fetchElement($activity, 'as:content') ?? '';
+               $languages = JsonLD::fetchElementArray($activity, 'as:content', '@language') ?? [];
                if (empty($languages)) {
                        return [];
                }
index bb671003da58d292bbd0b0a76ed49032d8572848..cd48768cc71c58e5e920404a8f9d65a2ece742c3 100644 (file)
@@ -2005,6 +2005,7 @@ class Receiver
                $object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag') ?? []);
                $object_data['emojis'] = self::processEmojis(JsonLD::fetchElementArray($object, 'as:tag', null, '@type', 'toot:Emoji') ?? []);
                $object_data['languages'] = self::processLanguages(JsonLD::fetchElementArray($object, 'sc:inLanguage') ?? []);
+               $object_data['transmitted-languages'] = Processor::getPostLanguages($object);
                $object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application');
                $object_data['generator'] = JsonLD::fetchElement($object_data, 'generator', '@value');
                $object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url', '@id');