diff --git a/include/api.php b/include/api.php index 6f8c952475..f1a8e5ee94 100644 --- a/include/api.php +++ b/include/api.php @@ -1559,7 +1559,7 @@ function api_search($type) $params['group_by'] = ['uri-id']; } else { $condition = ["`id` > ? - " . ($exclude_replies ? " AND `id` = `parent` " : ' ') . " + " . ($exclude_replies ? " AND `gravity` = " . GRAVITY_PARENT : ' ') . " AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `body` LIKE CONCAT('%',?,'%')", $since_id, api_user(), $_REQUEST['q']]; @@ -3028,7 +3028,7 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use $retweeted_item = []; $quoted_item = []; - if ($item["id"] == $item["parent"]) { + if ($item['gravity'] == GRAVITY_PARENT) { $body = $item['body']; $retweeted_item = api_share_as_retweet($item); if ($body != $item['body']) { diff --git a/include/conversation.php b/include/conversation.php index eb5e95d6db..b163184af9 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -671,7 +671,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o $item['pagedrop'] = $page_dropping; - if ($item['id'] == $item['parent']) { + if ($item['gravity'] == GRAVITY_PARENT) { $item_object = new Post($item); $conv->addParent($item_object); } @@ -948,7 +948,7 @@ function builtin_activity_puller($item, &$conv_responses) { return; } - if (!empty($item['verb']) && DI::activity()->match($item['verb'], $verb) && ($item['id'] != $item['parent'])) { + if (!empty($item['verb']) && DI::activity()->match($item['verb'], $verb) && ($item['gravity'] != GRAVITY_PARENT)) { $author = ['uid' => 0, 'id' => $item['author-id'], 'network' => $item['author-network'], 'url' => $item['author-link']]; $url = Contact::magicLinkByContact($author); @@ -1218,7 +1218,7 @@ function get_item_children(array &$item_list, array $parent, $recursive = true) { $children = []; foreach ($item_list as $i => $item) { - if ($item['id'] != $item['parent']) { + if ($item['gravity'] != GRAVITY_PARENT) { if ($recursive) { // Fallback to parent-uri if thr-parent is not set $thr_parent = $item['thr-parent']; @@ -1366,7 +1366,7 @@ function conv_sort(array $item_list, $order) // Extract the top level items foreach ($item_array as $item) { - if ($item['id'] == $item['parent']) { + if ($item['gravity'] == GRAVITY_PARENT) { $parents[] = $item; } } diff --git a/mod/display.php b/mod/display.php index a06d8a7239..d3c0e02499 100644 --- a/mod/display.php +++ b/mod/display.php @@ -54,7 +54,7 @@ function display_init(App $a) $item = null; $item_user = local_user(); - $fields = ['id', 'parent', 'author-id', 'body', 'uid', 'guid']; + $fields = ['id', 'parent', 'author-id', 'body', 'uid', 'guid', 'gravity']; // If there is only one parameter, then check if this parameter could be a guid if ($a->argc == 2) { @@ -101,12 +101,12 @@ function display_init(App $a) } if (!empty($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'application/atom+xml')) { - Logger::log('Directly serving XML for id '.$item["id"], Logger::DEBUG); - displayShowFeed($item["id"], false); + Logger::log('Directly serving XML for id '.$item['id'], Logger::DEBUG); + displayShowFeed($item['id'], false); } - if ($item["id"] != $item["parent"]) { - $parent = Item::selectFirstForUser($item_user, $fields, ['id' => $item["parent"]]); + if ($item['gravity'] != GRAVITY_PARENT) { + $parent = Item::selectFirstForUser($item_user, $fields, ['id' => $item['parent']]); $item = $parent ?: $item; } @@ -205,8 +205,8 @@ function display_content(App $a, $update = false, $update_uid = 0) $condition = ['guid' => $a->argv[1], 'uid' => local_user()]; $item = Item::selectFirstForUser(local_user(), $fields, $condition); if (DBA::isResult($item)) { - $item_id = $item["id"]; - $item_parent = $item["parent"]; + $item_id = $item['id']; + $item_parent = $item['parent']; $item_parent_uri = $item['parent-uri']; } } @@ -214,8 +214,8 @@ function display_content(App $a, $update = false, $update_uid = 0) if (($item_parent == 0) && remote_user()) { $item = Item::selectFirst($fields, ['guid' => $a->argv[1], 'private' => Item::PRIVATE, 'origin' => true]); if (DBA::isResult($item) && Contact::isFollower(remote_user(), $item['uid'])) { - $item_id = $item["id"]; - $item_parent = $item["parent"]; + $item_id = $item['id']; + $item_parent = $item['parent']; $item_parent_uri = $item['parent-uri']; } } @@ -224,8 +224,8 @@ function display_content(App $a, $update = false, $update_uid = 0) $condition = ['private' => [Item::PUBLIC, Item::UNLISTED], 'guid' => $a->argv[1], 'uid' => 0]; $item = Item::selectFirstForUser(local_user(), $fields, $condition); if (DBA::isResult($item)) { - $item_id = $item["id"]; - $item_parent = $item["parent"]; + $item_id = $item['id']; + $item_parent = $item['parent']; $item_parent_uri = $item['parent-uri']; } } diff --git a/mod/item.php b/mod/item.php index ad3351dd4a..6671d94393 100644 --- a/mod/item.php +++ b/mod/item.php @@ -119,7 +119,7 @@ function item_post(App $a) { // The URI and the contact is taken from the direct parent which needn't to be the top parent $thr_parent_uri = $toplevel_item['uri']; - if ($toplevel_item['id'] != $toplevel_item['parent']) { + if ($toplevel_item['gravity'] != GRAVITY_PARENT) { $toplevel_item = Item::selectFirst([], ['id' => $toplevel_item['parent']]); } } diff --git a/mod/network.php b/mod/network.php index 433d4079c1..16fde6c351 100644 --- a/mod/network.php +++ b/mod/network.php @@ -709,7 +709,7 @@ function networkThreadedView(App $a, $update, $parent) } if ($order === 'post') { // Only show toplevel posts when updating posts in this order mode - $sql_extra4 .= " AND `item`.`id` = `item`.`parent`"; + $sql_extra4 .= " AND `item`.`gravity` = " . GRAVITY_PARENT; } } diff --git a/mod/photos.php b/mod/photos.php index 7a647e06b9..7b74a39dd8 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1456,7 +1456,7 @@ function photos_content(App $a) if (($activity->match($item['verb'], Activity::LIKE) || $activity->match($item['verb'], Activity::DISLIKE)) && - ($item['id'] != $item['parent'])) { + ($item['gravity'] != GRAVITY_PARENT)) { continue; } diff --git a/mod/ping.php b/mod/ping.php index 168b508ea0..73e759107b 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -467,13 +467,13 @@ function ping_get_notifications($uid) if ($notification["visible"] && !$notification["deleted"] - && empty($result[$notification["parent"]]) + && empty($result[$notification['parent']]) ) { // Should we condense the notifications or show them all? if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) { $result[$notification["id"]] = $notification; } else { - $result[$notification["parent"]] = $notification; + $result[$notification['parent']] = $notification; } } } diff --git a/src/Factory/Notification/Notification.php b/src/Factory/Notification/Notification.php index 990d274a01..cedc0ad656 100644 --- a/src/Factory/Notification/Notification.php +++ b/src/Factory/Notification/Notification.php @@ -95,11 +95,11 @@ class Notification extends BaseFactory $item['author-avatar'] = $item['contact-avatar']; } - $item['label'] = (($item['id'] == $item['parent']) ? 'post' : 'comment'); + $item['label'] = (($item['gravity'] == GRAVITY_PARENT) ? 'post' : 'comment'); $item['link'] = $this->baseUrl->get(true) . '/display/' . $item['parent-guid']; $item['image'] = Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO); $item['url'] = $item['author-link']; - $item['text'] = (($item['id'] == $item['parent']) + $item['text'] = (($item['gravity'] == GRAVITY_PARENT) ? $this->l10n->t("%s created a new post", $item['author-name']) : $this->l10n->t("%s commented on %s's post", $item['author-name'], $item['parent-author-name'])); $item['when'] = DateTimeFormat::local($item['created'], 'r'); diff --git a/src/Model/Item.php b/src/Model/Item.php index 6b48acf4cb..a6036e6bdb 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1047,7 +1047,7 @@ class Item $fields = ['id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri', 'origin', 'deleted', 'file', 'resource-id', 'event-id', 'attach', 'verb', 'object-type', 'object', 'target', 'contact-id', - 'icid', 'psid']; + 'icid', 'psid', 'gravity']; $item = self::selectFirst($fields, ['id' => $item_id]); if (!DBA::isResult($item)) { Logger::info('Item not found.', ['id' => $item_id]); @@ -1138,7 +1138,7 @@ class Item //} // If it's the parent of a comment thread, kill all the kids - if ($item['id'] == $item['parent']) { + if ($item['gravity'] == GRAVITY_PARENT) { self::markForDeletion(['parent' => $item['parent'], 'deleted' => false], $priority); } @@ -1494,7 +1494,7 @@ class Item } } - $item["parent"] = $parent['id']; + $item['parent'] = $parent['id']; $item["deleted"] = $parent['deleted']; $item["allow_cid"] = $parent['allow_cid']; $item['allow_gid'] = $parent['allow_gid']; @@ -1529,8 +1529,8 @@ class Item // If its a post that originated here then tag the thread as "mention" if ($item['origin'] && $item['uid']) { - DBA::update('thread', ['mention' => true], ['iid' => $item["parent"]]); - Logger::info('tagged thread as mention', ['parent' => $item["parent"], 'uid' => $item['uid']]); + DBA::update('thread', ['mention' => true], ['iid' => $item['parent']]); + Logger::info('tagged thread as mention', ['parent' => $item['parent'], 'uid' => $item['uid']]); } // Update the contact relations @@ -2246,7 +2246,7 @@ class Item } // Is it a toplevel post? - if ($item['id'] == $item['parent']) { + if ($item['gravity'] == GRAVITY_PARENT) { self::addShadow($itemid); return; } @@ -2544,7 +2544,7 @@ class Item if (!$mention) { if (($community_page || $prvgroup) && - !$item['wall'] && !$item['origin'] && ($item['id'] == $item['parent'])) { + !$item['wall'] && !$item['origin'] && ($item['gravity'] == GRAVITY_PARENT)) { Logger::info('Delete private group/communiy top-level item without mention', ['id' => $item_id, 'guid'=> $item['guid']]); DBA::delete('item', ['id' => $item_id]); return true; @@ -2845,7 +2845,7 @@ class Item return; } - $condition = ["`uid` = ? AND NOT `deleted` AND `id` = `parent` AND `gravity` = ?", + $condition = ["`uid` = ? AND NOT `deleted` AND `gravity` = ?", $uid, GRAVITY_PARENT]; /* @@ -3227,9 +3227,9 @@ class Item return DI::l10n()->t('event'); } elseif (!empty($item['resource-id'])) { return DI::l10n()->t('photo'); - } elseif (!empty($item['verb']) && $item['verb'] !== Activity::POST) { + } elseif ($item['gravity'] == GRAVITY_ACTIVITY) { return DI::l10n()->t('activity'); - } elseif ($item['id'] != $item['parent']) { + } elseif ($item['gravity'] == GRAVITY_COMMENT) { return DI::l10n()->t('comment'); } diff --git a/src/Object/Post.php b/src/Object/Post.php index 8488df000f..1ca02873d7 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -214,7 +214,7 @@ class Post $pinned = DI::l10n()->t('pinned item'); } - if ($origin && ($item['id'] != $item['parent']) && ($item['network'] == Protocol::ACTIVITYPUB)) { + if ($origin && ($item['gravity'] != GRAVITY_PARENT) && ($item['network'] == Protocol::ACTIVITYPUB)) { // ActivityPub doesn't allow removal of remote comments $delete = DI::l10n()->t('Delete locally'); } else { diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 9ca23f1dcb..54e44f5b99 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1059,7 +1059,7 @@ class DFRN if ($item['object-type'] != "") { XML::addElement($doc, $entry, "activity:object-type", $item['object-type']); - } elseif ($item['id'] == $item['parent']) { + } elseif ($item['gravity'] == GRAVITY_PARENT) { XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::NOTE); } else { XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::COMMENT); @@ -2110,7 +2110,7 @@ class DFRN $author = DBA::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item['author-id']]); $parent = Item::selectFirst(['id'], ['uri' => $item['parent-uri'], 'uid' => $importer["importer_uid"]]); - $item["parent"] = $parent['id']; + $item['parent'] = $parent['id']; // send a notification notification( @@ -2129,7 +2129,7 @@ class DFRN "verb" => $item["verb"], "otype" => "person", "activity" => $verb, - "parent" => $item["parent"]] + "parent" => $item['parent']] ); } } @@ -2634,7 +2634,7 @@ class DFRN } $condition = ['uri' => $uri, 'uid' => $importer["importer_uid"]]; - $item = Item::selectFirst(['id', 'parent', 'contact-id', 'file', 'deleted'], $condition); + $item = Item::selectFirst(['id', 'parent', 'contact-id', 'file', 'deleted', 'gravity'], $condition); if (!DBA::isResult($item)) { Logger::log("Item with uri " . $uri . " for user " . $importer["importer_uid"] . " wasn't found.", Logger::DEBUG); return; @@ -2646,13 +2646,13 @@ class DFRN } // When it is a starting post it has to belong to the person that wants to delete it - if (($item['id'] == $item['parent']) && ($item['contact-id'] != $importer["id"])) { + if (($item['gravity'] == GRAVITY_PARENT) && ($item['contact-id'] != $importer["id"])) { Logger::log("Item with uri " . $uri . " don't belong to contact " . $importer["id"] . " - ignoring deletion.", Logger::DEBUG); return; } // Comments can be deleted by the thread owner or comment owner - if (($item['id'] != $item['parent']) && ($item['contact-id'] != $importer["id"])) { + if (($item['gravity'] != GRAVITY_PARENT) && ($item['contact-id'] != $importer["id"])) { $condition = ['id' => $item['parent'], 'contact-id' => $importer["id"]]; if (!Item::exists($condition)) { Logger::log("Item with uri " . $uri . " wasn't found or mustn't be deleted by contact " . $importer["id"] . " - ignoring deletion.", Logger::DEBUG); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 243550862b..c4e7d9fb87 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1517,7 +1517,7 @@ class Diaspora private static function parentItem($uid, $guid, $author, array $contact) { $fields = ['id', 'parent', 'body', 'wall', 'uri', 'guid', 'private', 'origin', - 'author-name', 'author-link', 'author-avatar', + 'author-name', 'author-link', 'author-avatar', 'gravity', 'owner-name', 'owner-link', 'owner-avatar']; $condition = ['uid' => $uid, 'guid' => $guid]; $item = Item::selectFirst($fields, $condition); @@ -2164,8 +2164,8 @@ class Diaspora $datarray["changed"] = $datarray["created"] = $datarray["edited"] = DateTimeFormat::utcNow(); // like on comments have the comment as parent. So we need to fetch the toplevel parent - if ($parent_item["id"] != $parent_item["parent"]) { - $toplevel = Item::selectFirst(['origin'], ['id' => $parent_item["parent"]]); + if ($parent_item['gravity'] != GRAVITY_PARENT) { + $toplevel = Item::selectFirst(['origin'], ['id' => $parent_item['parent']]); $origin = $toplevel["origin"]; } else { $origin = $parent_item["origin"]; @@ -2891,7 +2891,7 @@ class Diaspora } // Fetch the parent item - $parent = Item::selectFirst(['author-link'], ['id' => $item["parent"]]); + $parent = Item::selectFirst(['author-link'], ['id' => $item['parent']]); // Only delete it if the parent author really fits if (!Strings::compareLink($parent["author-link"], $contact["url"]) && !Strings::compareLink($item["author-link"], $contact["url"])) { @@ -2901,7 +2901,7 @@ class Diaspora Item::markForDeletion(['id' => $item['id']]); - Logger::log("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item["parent"], Logger::DEBUG); + Logger::log("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item['parent'], Logger::DEBUG); } return true; @@ -3870,9 +3870,9 @@ class Diaspora return $result; } - $toplevel_item = Item::selectFirst(['guid', 'author-id', 'author-link'], ['id' => $item["parent"], 'parent' => $item["parent"]]); + $toplevel_item = Item::selectFirst(['guid', 'author-id', 'author-link'], ['id' => $item['parent'], 'parent' => $item['parent']]); if (!DBA::isResult($toplevel_item)) { - Logger::error('Missing parent conversation item', ['parent' => $item["parent"]]); + Logger::error('Missing parent conversation item', ['parent' => $item['parent']]); return false; } @@ -4066,7 +4066,7 @@ class Diaspora $msg_type = "retraction"; - if ($item['id'] == $item['parent']) { + if ($item['gravity'] == GRAVITY_PARENT) { $target_type = "Post"; } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) { $target_type = "Like"; diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 4cb27956ba..24decc000e 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1675,7 +1675,7 @@ class OStatus */ private static function reshareEntry(DOMDocument $doc, array $item, array $owner, $repeated_guid, $toplevel) { - if (($item["id"] != $item["parent"]) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) { + if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) { Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } @@ -1740,7 +1740,7 @@ class OStatus */ private static function likeEntry(DOMDocument $doc, array $item, array $owner, $toplevel) { - if (($item["id"] != $item["parent"]) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) { + if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) { Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } @@ -1824,7 +1824,7 @@ class OStatus */ private static function followEntry(DOMDocument $doc, array $item, array $owner, $toplevel) { - $item["id"] = $item["parent"] = 0; + $item["id"] = $item['parent'] = 0; $item["created"] = $item["edited"] = date("c"); $item["private"] = Item::PRIVATE; @@ -1889,7 +1889,7 @@ class OStatus */ private static function noteEntry(DOMDocument $doc, array $item, array $owner, $toplevel, $feed_mode) { - if (($item["id"] != $item["parent"]) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) { + if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) { Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } @@ -2021,7 +2021,7 @@ class OStatus $mentioned = []; if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { - $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item["parent"]]); + $parent = Item::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]); $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']); $thrparent = Item::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $parent_item]); @@ -2047,7 +2047,7 @@ class OStatus XML::addElement($doc, $entry, "link", "", $attributes); } - if (!$feed_mode && (intval($item["parent"]) > 0)) { + if (!$feed_mode && (intval($item['parent']) > 0)) { $conversation_href = $conversation_uri = str_replace('/objects/', '/context/', $item['parent-uri']); if (isset($parent_item)) { @@ -2066,7 +2066,7 @@ class OStatus $attributes = [ "href" => $conversation_href, - "local_id" => $item["parent"], + "local_id" => $item['parent'], "ref" => $conversation_uri]; XML::addElement($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);