]> git.mxchange.org Git - friendica.git/commitdiff
Fix some warnings on item creation
authorMichael <heluecht@pirati.ca>
Mon, 9 Jan 2023 15:55:35 +0000 (15:55 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 9 Jan 2023 15:55:35 +0000 (15:55 +0000)
src/Content/Item.php
src/Model/Item.php
src/Protocol/DFRN.php
src/Protocol/Feed.php

index 26df55fd064e32785812939e73374e00ab5387a5..1bf3e68726eb4586fc18d05d3fbd6a3800d2a67b 100644 (file)
@@ -859,7 +859,7 @@ class Item
 
                $user = User::getById($post['uid'], ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
                if (!$user) {
-                       throw new HTTPException\NotFoundException($this->l10n->t('Unable to locate original post.'));
+                       throw new HTTPException\NotFoundException($this->l10n->t('Unable to fetch user.'));
                }
 
                $post['allow_cid'] = isset($request['contact_allow']) ? $this->aclFormatter->toString($request['contact_allow']) : $user['allow_cid'] ?? '';
@@ -957,10 +957,30 @@ class Item
                $post['origin']    = true;
                $post['wall']      = $post['wall'] ?? true;
                $post['guid']      = $post['guid'] ?? System::createUUID();
-               $post['uri']       = $post['uri']  ?? ItemModel::newURI($post['guid']);
                $post['verb']      = $post['verb'] ?? Activity::POST;
+
+               if (empty($post['uri'])) {
+                       $post['thr-parent'] = $post['uri'] = ItemModel::newURI($post['guid']);
+                       $post['gravity']    = ItemModel::GRAVITY_PARENT;
+               }
+
                $owner = User::getOwnerDataById($post['uid']);
 
+               if (!isset($post['allow_cid']) || !isset($post['allow_gid']) || !isset($post['deny_cid']) || !isset($post['deny_gid'])) {
+                       $post['allow_cid'] = $owner['allow_cid'];
+                       $post['allow_gid'] = $owner['allow_gid'];
+                       $post['deny_cid']  = $owner['deny_cid'];
+                       $post['deny_gid']  = $owner['deny_gid'];
+               }
+               
+               if ($post['allow_gid'] || $post['allow_cid'] || $post['deny_gid'] || $post['deny_cid']) {
+                       $post['private'] = ItemModel::PRIVATE;
+               } elseif ($this->pConfig->get($post['uid'], 'system', 'unlisted')) {
+                       $post['private'] = ItemModel::UNLISTED;
+               } else {
+                       $post['private'] = ItemModel::PUBLIC;
+               }
+
                if (empty($post['contact-id'])) {
                        $post['contact-id'] = $owner['id'];
                }
index afa51461e8c5412e28042b54536e253bceb2a338..fb638d6e9329e044d061014ea417efefb760085b 100644 (file)
@@ -1224,6 +1224,8 @@ class Item
                        Post\Content::insert($item['uri-id'], $item);
                }
 
+               $item['parent'] = $parent_id;
+
                // Create Diaspora signature
                if ($item['origin'] && empty($item['diaspora_signed_text']) && ($item['gravity'] != self::GRAVITY_PARENT)) {
                        $signed = Diaspora::createCommentSignature($item);
@@ -1741,16 +1743,16 @@ class Item
                $item['origin'] = 0;
                $item['wall'] = 0;
 
-               $item['contact-id'] = self::contactId($item);
-
                $notify = false;
                if ($item['gravity'] == self::GRAVITY_PARENT) {
                        $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]);
                        if (DBA::isResult($contact)) {
                                $notify = self::isRemoteSelf($contact, $item);
+                               $item['wall'] = (bool)$notify;
                        }
                }
 
+               $item['contact-id'] = self::contactId($item);
                $distributed = self::insert($item, $notify);
 
                if (!$distributed) {
index 0b005570b230bc263e35318ae2fea405d0f69499..26d5376e4e0d40152f4fffafbdb6c9ee5ae54b34 100644 (file)
@@ -2079,6 +2079,7 @@ class DFRN
                        // This is my contact on another system, but it's really me.
                        // Turn this into a wall post.
                        $notify = Item::isRemoteSelf($importer, $item);
+                       $item['wall'] = (bool)$notify;
 
                        $posted_id = Item::insert($item, $notify);
 
index 63a9fbfbdc79ae9c4eb2b17ea4bbc06f2947bc1f..ccbe35e712497188e8ce5b0a44aff11799e10c67 100644 (file)
@@ -624,6 +624,7 @@ class Feed
                        Logger::info('Stored feed', ['item' => $item]);
 
                        $notify = Item::isRemoteSelf($contact, $item);
+                       $item['wall'] = (bool)$notify;
 
                        // Distributed items should have a well-formatted URI.
                        // Additionally, we have to avoid conflicts with identical URI between imported feeds and these items.