X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FItem.php;h=c0c67352e4ddbe6884189ce0fa8772c127a3aa34;hb=3d04562c87140a5d026e8405b6d1213b181ffc0d;hp=9406df2ac86896d9e9cb2709f3d15c739e23f8c6;hpb=61e2c7d20dfcf3eba7442c2b181d22b8926062e3;p=friendica.git diff --git a/src/Model/Item.php b/src/Model/Item.php index 9406df2ac8..c0c67352e4 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1081,9 +1081,8 @@ class Item extends BaseObject DBA::delete('item-delivery-data', ['iid' => $item['id']]); - if (!empty($item['iaid']) && !self::exists(['iaid' => $item['iaid'], 'deleted' => false])) { - DBA::delete('item-activity', ['id' => $item['iaid']], ['cascade' => false]); - } + // We don't delete the item-activity here, since we need some of the data for ActivityPub + if (!empty($item['icid']) && !self::exists(['icid' => $item['icid'], 'deleted' => false])) { DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]); } @@ -1167,7 +1166,7 @@ class Item extends BaseObject if ($notify) { // We have to avoid duplicates. So we create the GUID in form of a hash of the plink or uri. // We add the hash of our own host because our host is the original creator of the post. - $prefix_host = get_app()->get_hostname(); + $prefix_host = get_app()->getHostName(); } else { $prefix_host = ''; @@ -1205,7 +1204,7 @@ class Item extends BaseObject } elseif (!empty($item['uri'])) { $guid = self::guidFromUri($item['uri'], $prefix_host); } else { - $guid = System::createGUID(32, hash('crc32', $prefix_host)); + $guid = System::createUUID(hash('crc32', $prefix_host)); } return $guid; @@ -1936,6 +1935,7 @@ class Item extends BaseObject } else { // This shouldn't happen. logger('Could not insert activity for URI ' . $item['uri'] . ' - should not happen'); + Lock::release('item_insert_activity'); return false; } if ($locked) { @@ -2071,14 +2071,46 @@ class Item extends BaseObject $users = []; - $condition = ["`nurl` IN (SELECT `nurl` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)", - $parent['owner-id'], Contact::SHARING, Contact::FRIEND]; + /// @todo add a field "pcid" in the contact table that referrs to the public contact id. + $owner = DBA::selectFirst('contact', ['url', 'nurl', 'alias'], ['id' => $parent['owner-id']]); + if (!DBA::isResult($owner)) { + return; + } + $condition = ['nurl' => $owner['nurl'], 'rel' => [Contact::SHARING, Contact::FRIEND]]; $contacts = DBA::select('contact', ['uid'], $condition); + while ($contact = DBA::fetch($contacts)) { + if ($contact['uid'] == 0) { + continue; + } + + $users[$contact['uid']] = $contact['uid']; + } + DBA::close($contacts); + $condition = ['alias' => $owner['url'], 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $contacts = DBA::select('contact', ['uid'], $condition); while ($contact = DBA::fetch($contacts)) { + if ($contact['uid'] == 0) { + continue; + } + $users[$contact['uid']] = $contact['uid']; } + DBA::close($contacts); + + if (!empty($owner['alias'])) { + $condition = ['url' => $owner['alias'], 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $contacts = DBA::select('contact', ['uid'], $condition); + while ($contact = DBA::fetch($contacts)) { + if ($contact['uid'] == 0) { + continue; + } + + $users[$contact['uid']] = $contact['uid']; + } + DBA::close($contacts); + } $origin_uid = 0; @@ -2326,16 +2358,10 @@ class Item extends BaseObject public static function newURI($uid, $guid = "") { if ($guid == "") { - $guid = System::createGUID(32); + $guid = System::createUUID(); } - $hostname = self::getApp()->get_hostname(); - - $user = DBA::selectFirst('user', ['nickname'], ['uid' => $uid]); - - $uri = "urn:X-dfrn:" . $hostname . ':' . $user['nickname'] . ':' . $guid; - - return $uri; + return self::getApp()->getBaseURL() . '/objects/' . $guid; } /** @@ -2618,7 +2644,7 @@ class Item extends BaseObject } // Prevent to forward already forwarded posts - if ($datarray["app"] == $a->get_hostname()) { + if ($datarray["app"] == $a->getHostName()) { logger('Already forwarded (second test)', LOGGER_DEBUG); return false; } @@ -2659,7 +2685,7 @@ class Item extends BaseObject } if ($contact['network'] != Protocol::FEED) { - $datarray["guid"] = System::createGUID(32); + $datarray["guid"] = System::createUUID(); unset($datarray["plink"]); $datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]); $datarray["parent-uri"] = $datarray["uri"]; @@ -2825,7 +2851,7 @@ class Item extends BaseObject } // returns an array of contact-ids that are allowed to see this object - private static function enumeratePermissions($obj) + public static function enumeratePermissions($obj) { $allow_people = expand_acl($obj['allow_cid']); $allow_groups = Group::expand(expand_acl($obj['allow_gid'])); @@ -3085,10 +3111,10 @@ class Item extends BaseObject return true; } - $objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ; + $objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE; $new_item = [ - 'guid' => System::createGUID(32), + 'guid' => System::createUUID(), 'uri' => self::newURI($item['uid']), 'uid' => $item['uid'], 'contact-id' => $item_contact_id, @@ -3099,7 +3125,7 @@ class Item extends BaseObject 'parent' => $item['id'], 'parent-uri' => $item['uri'], 'thr-parent' => $item['uri'], - 'owner-id' => $item['owner-id'], + 'owner-id' => $author_id, 'author-id' => $author_id, 'body' => $activity, 'verb' => $activity,