X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItem.php;h=3ae23412e6e20689b5745f49b880740ed3e9e294;hb=073695b33c5f9c5d89d91958b09259c59e12dd98;hp=4013dc2ce13c1feab5071e215f087f960a49b945;hpb=9527cd5cb3ccc0c2ccb0337cbd5711a5fa622ca0;p=friendica.git diff --git a/src/Model/Item.php b/src/Model/Item.php index 4013dc2ce1..3ae23412e6 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -83,7 +83,7 @@ class Item // Field list that is used to display the items const DISPLAY_FIELDLIST = [ 'uid', 'id', 'parent', 'guid', 'network', 'gravity', - 'uri-id', 'uri', 'thr-parent-id', 'thr-parent', 'parent-uri-id', 'parent-uri', + 'uri-id', 'uri', 'thr-parent-id', 'thr-parent', 'parent-uri-id', 'parent-uri', 'conversation', 'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink', 'wall', 'private', 'starred', 'origin', 'parent-origin', 'title', 'body', 'language', 'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object', @@ -103,7 +103,7 @@ class Item // Field list that is used to deliver items via the protocols const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid', - 'parent-guid', 'received', 'created', 'edited', 'verb', 'object-type', 'object', 'target', + 'parent-guid', 'conversation', 'received', 'created', 'edited', 'verb', 'object-type', 'object', 'target', 'private', 'title', 'body', 'raw-body', 'location', 'coord', 'app', 'inform', 'deleted', 'extid', 'post-type', 'post-reason', 'gravity', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', @@ -116,7 +116,7 @@ class Item // All fields in the item table const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', - 'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid', + 'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'conversation', 'vid', 'contact-id', 'wall', 'gravity', 'extid', 'psid', 'created', 'edited', 'commented', 'received', 'changed', 'verb', 'postopts', 'plink', 'resource-id', 'event-id', 'inform', @@ -683,14 +683,19 @@ class Item 'uri-id', 'parent-uri-id', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'wall', 'private', 'origin', 'author-id']; - $condition = ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']]; + $condition = ['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => $item['uid']]; $params = ['order' => ['id' => false]]; $parent = Post::selectFirst($fields, $condition, $params); - if (!DBA::isResult($parent) && $item['origin']) { + if (!DBA::isResult($parent) && Post::exists(['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => 0])) { $stored = Item::storeForUserByUriId($item['thr-parent-id'], $item['uid']); - Logger::info('Stored thread parent item for user', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid'], 'stored' => $stored]); - $parent = Post::selectFirst($fields, $condition, $params); + if (!$stored && ($item['thr-parent-id'] != $item['parent-uri-id'])) { + $stored = Item::storeForUserByUriId($item['parent-uri-id'], $item['uid']); + } + if ($stored) { + Logger::info('Stored thread parent item for user', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid'], 'stored' => $stored]); + $parent = Post::selectFirst($fields, $condition, $params); + } } if (!DBA::isResult($parent)) { @@ -780,17 +785,20 @@ class Item $uid = intval($item['uid']); $item['guid'] = self::guid($item, $notify); - $item['uri'] = substr(trim($item['uri'] ?? '') ?: self::newURI($item['uid'], $item['guid']), 0, 255); + $item['uri'] = substr(trim($item['uri'] ?? '') ?: self::newURI($item['guid']), 0, 255); // Store URI data $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]); // Backward compatibility: parent-uri used to be the direct parent uri. // If it is provided without a thr-parent, it probably is the old behavior. - $item['thr-parent'] = trim($item['thr-parent'] ?? $item['parent-uri'] ?? $item['uri']); - $item['parent-uri'] = $item['thr-parent']; + if (empty($item['thr-parent']) || empty($item['parent-uri'])) { + $item['thr-parent'] = trim($item['thr-parent'] ?? $item['parent-uri'] ?? $item['uri']); + $item['parent-uri'] = $item['thr-parent']; + } - $item['thr-parent-id'] = $item['parent-uri-id'] = ItemURI::getIdByURI($item['thr-parent']); + $item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']); + $item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']); // Store conversation data $item = Conversation::insert($item); @@ -900,7 +908,7 @@ class Item $item['contact-id'] = self::contactId($item); if (!empty($item['direction']) && in_array($item['direction'], [Conversation::PUSH, Conversation::RELAY]) && - empty($item['origin']) &&self::isTooOld($item)) { + empty($item['origin']) && self::isTooOld($item)) { Logger::info('Item is too old', ['item' => $item]); return 0; } @@ -966,11 +974,19 @@ class Item } else { $parent_id = 0; $parent_origin = $item['origin']; + + if ($item['wall'] && empty($item['conversation'])) { + $item['conversation'] = $item['parent-uri'] . '#context'; + } } $item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']); $item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']); + if (!empty($item['conversation']) && empty($item['conversation-id'])) { + $item['conversation-id'] = ItemURI::getIdByURI($item['conversation']); + } + // Is this item available in the global items (with uid=0)? if ($item['uid'] == 0) { $item['global'] = true; @@ -1853,13 +1869,12 @@ class Item /** * generate an unique URI * - * @param integer $uid User id - * @param string $guid An existing GUID (Otherwise it will be generated) + * @param string $guid An existing GUID (Otherwise it will be generated) * * @return string * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function newURI(int $uid, string $guid = ''): string + public static function newURI(string $guid = ''): string { if ($guid == '') { $guid = System::createUUID(); @@ -2150,7 +2165,7 @@ class Item $old_uri_id = $datarray["uri-id"] ?? 0; $datarray["guid"] = System::createUUID(); unset($datarray["plink"]); - $datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]); + $datarray["uri"] = self::newURI($datarray["guid"]); $datarray["uri-id"] = ItemURI::getIdByURI($datarray["uri"]); $datarray["extid"] = Protocol::DFRN; $urlpart = parse_url($datarray2['author-link']); @@ -2591,7 +2606,7 @@ class Item $new_item = [ 'guid' => System::createUUID(), - 'uri' => self::newURI($item['uid']), + 'uri' => self::newURI(), 'uid' => $item['uid'], 'contact-id' => $owner['id'], 'wall' => $item['wall'], @@ -3411,7 +3426,9 @@ class Item return is_numeric($hookData['item_id']) ? $hookData['item_id'] : 0; } - if ($fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri)) { + $fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri); + + if ($fetched_uri) { $item_id = self::searchByLink($fetched_uri, $uid); } else { $item_id = Diaspora::fetchByURL($uri);