]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
"MIRROR_FORWARDED" is no more
[friendica.git] / src / Model / Item.php
index 5271dcefaab3cdb2c170a8a6034ad7c04939ec36..911e4216f0a70ea7c7d13a81ab6b1e4e6fab2fe9 100644 (file)
@@ -815,6 +815,49 @@ class Item
                return self::GRAVITY_UNKNOWN;   // Should not happen
        }
 
+       private static function prepareOriginPost(array $item): array
+       {
+               $item['wall'] = 1;
+               $item['origin'] = 1;
+               $item['network'] = Protocol::DFRN;
+               $item['protocol'] = Conversation::PARCEL_DIRECT;
+               $item['direction'] = Conversation::PUSH;
+
+               $owner = User::getOwnerDataById($item['uid']);
+
+               if (empty($item['contact-id'])) {
+                       $item['contact-id'] = $owner['id'];
+               }
+
+               if (empty($item['author-link']) && empty($item['author-id'])) {
+                       $item['author-link']   = $owner['url'];
+                       $item['author-name']   = $owner['name'];
+                       $item['author-avatar'] = $owner['thumb'];
+               }
+
+               if (empty($item['owner-link']) && empty($item['owner-id'])) {
+                       $item['owner-link']   = $item['author-link'];
+                       $item['owner-name']   = $item['author-name'];
+                       $item['owner-avatar'] = $item['author-avatar'];
+               }
+
+               // Setting the object type if not defined before
+               if (empty($item['object-type'])) {
+                       $item['object-type'] = Activity\ObjectType::NOTE; // Default value
+                       $objectdata = BBCode::getAttachedData($item['body']);
+
+                       if ($objectdata['type'] == 'link') {
+                               $item['object-type'] = Activity\ObjectType::BOOKMARK;
+                       } elseif ($objectdata['type'] == 'video') {
+                               $item['object-type'] = Activity\ObjectType::VIDEO;
+                       } elseif ($objectdata['type'] == 'photo') {
+                               $item['object-type'] = Activity\ObjectType::IMAGE;
+                       }
+               }
+
+               return $item;
+       }
+
        /**
         * Inserts item record
         *
@@ -831,11 +874,7 @@ class Item
 
                // If it is a posting where users should get notifications, then define it as wall posting
                if ($notify) {
-                       $item['wall'] = 1;
-                       $item['origin'] = 1;
-                       $item['network'] = Protocol::DFRN;
-                       $item['protocol'] = Conversation::PARCEL_DIRECT;
-                       $item['direction'] = Conversation::PUSH;
+                       $item = self::prepareOriginPost($item);
 
                        if (is_int($notify) && in_array($notify, Worker::PRIORITIES)) {
                                $priority = $notify;
@@ -993,6 +1032,7 @@ class Item
                        $item['parent-uri']    = $toplevel_parent['uri'];
                        $item['parent-uri-id'] = $toplevel_parent['uri-id'];
                        $item['deleted']       = $toplevel_parent['deleted'];
+                       $item['wall']          = $toplevel_parent['wall'];
 
                        // Reshares have to keep their permissions to allow forums to work
                        if (!$item['origin'] || ($item['verb'] != Activity::ANNOUNCE)) {
@@ -2272,7 +2312,7 @@ class Item
 
                $datarray2 = $datarray;
                Logger::info('remote-self start', ['contact' => $contact['url'], 'remote_self'=> $contact['remote_self'], 'item' => $datarray]);
-               if ($contact['remote_self'] == Contact::MIRROR_OWN_POST) {
+               if (in_array($contact['remote_self'], [Contact::MIRROR_OWN_POST, Contact::MIRROR_FORWARDED])) {
                        $self = DBA::selectFirst('contact', ['id', 'name', 'url', 'thumb'],
                                        ['uid' => $contact['uid'], 'self' => true]);
                        if (DBA::isResult($self)) {
@@ -2318,8 +2358,8 @@ class Item
                        $result = self::insert($datarray2);
                        Logger::info('remote-self post original item', ['contact' => $contact['url'], 'result'=> $result, 'item' => $datarray2]);
                } else {
-                       $datarray["app"] = "Feed";
-                       $result = true;
+                       Logger::info('No valid mirroring option', ['uid' => $contact['uid'], 'id' => $contact['id'], 'network' => $contact['network'], 'remote_self' => $contact['remote_self']]);
+                       return false;
                }
 
                return (bool)$result;
@@ -2974,7 +3014,7 @@ class Item
                        $quote_uri_id = $shared['post']['uri-id'];
                        $shared_links[] = strtolower($shared['post']['uri']);
                        $item['body'] = BBCode::removeSharedData($item['body']);
-               } elseif (empty($shared_item['uri-id']) && empty($item['quote-uri-id'])) {
+               } elseif (empty($shared_item['uri-id']) && empty($item['quote-uri-id']) && ($item['network'] != Protocol::DIASPORA)) {
                        $media = Post\Media::getByURIId($item['uri-id'], [Post\Media::ACTIVITY]);
                        if (!empty($media)) {
                                $shared_item = Post::selectFirst($fields, ['plink' => $media[0]['url'], 'uid' => [$item['uid'], 0]]);