]> git.mxchange.org Git - friendica.git/commitdiff
Store the "EmojiReact" activity
authorMichael <heluecht@pirati.ca>
Mon, 4 Apr 2022 16:03:53 +0000 (16:03 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 4 Apr 2022 16:03:53 +0000 (16:03 +0000)
src/Protocol/Activity.php
src/Protocol/ActivityNamespace.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php

index 4ebb02b8dd5880597d33429c07bc687983d0699c..637669a61e8bc7acd3744db6f87c224d0e954687 100644 (file)
@@ -176,6 +176,13 @@ final class Activity
        const O_UNFOLLOW    = ActivityNamespace::OSTATUS . '/unfollow';
        const O_UNFAVOURITE = ActivityNamespace::OSTATUS . '/unfavorite';
 
+       /**
+        * React to a post via an emoji 
+        *
+        * @var string
+        */
+       const EMOJIREACT = ActivityNamespace::LITEPUB . '/emojireact';
+
        /**
         * likes (etc.) can apply to other things besides posts. Check if they are post children,
         * in which case we handle them specially
@@ -183,10 +190,11 @@ final class Activity
         * Hidden activities, which doesn't need to be shown
         */
        const HIDDEN_ACTIVITIES = [
-               Activity::LIKE, Activity::DISLIKE,
-               Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE,
-               Activity::FOLLOW,
-               Activity::ANNOUNCE,
+               self::LIKE, self::DISLIKE,
+               self::ATTEND, self::ATTENDNO, self::ATTENDMAYBE,
+               self::FOLLOW,
+               self::ANNOUNCE,
+               self::EMOJIREACT,
        ];
 
        /**
index 550655460963d1425a78499af9ac227946362be1..5dbf88c86c2669ad9c6e8fc87fd3bdfba5bbdffa 100644 (file)
@@ -148,4 +148,8 @@ final class ActivityNamespace
         * @var string
         */
        const MASTODON        = 'http://mastodon.social/schema/1.0';
+       /**
+        * @var string
+        */
+       const LITEPUB         = 'http://litepub.social';
 }
index 3fc7dabe05f9100ca1384c45fef32c058a6ad1a5..533d3a29b10a11767fcfc7634f7182184135692c 100644 (file)
@@ -430,6 +430,10 @@ class Processor
                unset($item['post-type']);
                $item['object-type'] = Activity\ObjectType::NOTE;
 
+               if (!empty($activity['content'])) {
+                       $item['body'] = HTML::toBBCode($activity['content']);
+               }
+
                $item['diaspora_signed_text'] = $activity['diaspora:like'] ?? '';
 
                self::postItem($activity, $item);
index f53ce741933742e6219b1c7ef9d03afd74f43f9e..13d1a921f82b47e3328231f3fd8809628b02b179 100644 (file)
@@ -384,7 +384,7 @@ class Receiver
                        } else {
                                $object_data['directmessage'] = JsonLD::fetchElement($activity, 'litepub:directMessage');
                        }
-               } elseif (in_array($type, array_merge(self::ACTIVITY_TYPES, ['as:Follow'])) && in_array($object_type, self::CONTENT_TYPES)) {
+               } elseif (in_array($type, array_merge(self::ACTIVITY_TYPES, ['as:Follow', 'litepub:EmojiReact'])) && in_array($object_type, self::CONTENT_TYPES)) {
                        // Create a mostly empty array out of the activity data (instead of the object).
                        // This way we later don't have to check for the existence of each individual array element.
                        $object_data = self::processObject($activity);
@@ -752,8 +752,10 @@ class Receiver
                                break;
 
                        case 'litepub:EmojiReact':
-                               if (in_array($object_data['object_type'], array_merge([''], self::CONTENT_TYPES))) {
-                                       // Unhandled Pleroma activity to react to a post via an emoji
+                               if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
+                                       ActivityPub\Processor::createActivity($object_data, Activity::EMOJIREACT);
+                               } elseif ($object_data['object_type'] == '') {
+                                       // The object type couldn't be determined. We don't have it and we can't fetch it. We ignore this activity.
                                } else {
                                        self::storeUnhandledActivity(true, $type, $object_data, $activity, $body, $uid, $trust_source, $push, $signer);
                                }
@@ -786,7 +788,17 @@ class Receiver
                        return;
                }
 
-               $tempfile = tempnam(System::getTempPath(), ($unknown  ? 'unknown-' : 'unhandled-') . str_replace(':', '-', $type) . '-' . str_replace(':', '-', $object_data['object_type']) . '-' . str_replace(':', '-', $object_data['object_object_type'] ?? '') . '-');
+               $file = ($unknown  ? 'unknown-' : 'unhandled-') . str_replace(':', '-', $type) . '-';
+       
+               if (!empty($object_data['object_type'])) {
+                       $file .= str_replace(':', '-', $object_data['object_type']) . '-';
+               }
+
+               if (!empty($object_data['object_object_type'])) {
+                       $file .= str_replace(':', '-', $object_data['object_object_type']) . '-';
+               }
+
+               $tempfile = tempnam(System::getTempPath(), $file);
                file_put_contents($tempfile, json_encode(['activity' => $activity, 'body' => $body, 'uid' => $uid, 'trust_source' => $trust_source, 'push' => $push, 'signer' => $signer, 'object_data' => $object_data], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
                Logger::notice('Unknown activity stored', ['type' => $type, 'object_type' => $object_data['object_type'], $object_data['object_object_type'] ?? '', 'file' => $tempfile]);
        }