diff --git a/include/conversation.php b/include/conversation.php
index 0051b09866..b2353db2a3 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -838,8 +838,8 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
}
}
} else {
- $condition = ["`parent-uri` = ? AND `uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
- $parent['uri'], $uid, Verb::getID(Activity::FOLLOW)];
+ $condition = ["`parent-uri-id` = ? AND `uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
+ $parent['uri-id'], $uid, Verb::getID(Activity::FOLLOW)];
$activity = [];
}
$items = conversation_fetch_items($parent, $items, $condition, $block_authors, $params, $activity);
@@ -1037,31 +1037,31 @@ function builtin_activity_puller(array $activity, array &$conv_responses)
$link = '' . htmlentities($activity['author-name']) . '';
- if (empty($activity['thr-parent'])) {
- $activity['thr-parent'] = $activity['parent-uri'];
+ if (empty($activity['thr-parent-id'])) {
+ $activity['thr-parent-id'] = $activity['parent-uri-id'];
}
// Skip when the causer of the parent is the same than the author of the announce
- if (($verb == Activity::ANNOUNCE) && Post::exists(['uri' => $activity['thr-parent'],
+ if (($verb == Activity::ANNOUNCE) && Post::exists(['uri-id' => $activity['thr-parent-id'],
'uid' => $activity['uid'], 'causer-id' => $activity['author-id'], 'gravity' => GRAVITY_PARENT])) {
continue;
}
- if (!isset($conv_responses[$mode][$activity['thr-parent']])) {
- $conv_responses[$mode][$activity['thr-parent']] = [
+ if (!isset($conv_responses[$mode][$activity['thr-parent-id']])) {
+ $conv_responses[$mode][$activity['thr-parent-id']] = [
'links' => [],
'self' => 0,
];
- } elseif (in_array($link, $conv_responses[$mode][$activity['thr-parent']]['links'])) {
+ } elseif (in_array($link, $conv_responses[$mode][$activity['thr-parent-id']]['links'])) {
// only list each unique author once
continue;
}
if (public_contact() == $activity['author-id']) {
- $conv_responses[$mode][$activity['thr-parent']]['self'] = 1;
+ $conv_responses[$mode][$activity['thr-parent-id']]['self'] = 1;
}
- $conv_responses[$mode][$activity['thr-parent']]['links'][] = $link;
+ $conv_responses[$mode][$activity['thr-parent-id']]['links'][] = $link;
// there can only be one activity verb per item so if we found anything, we can stop looking
return;
@@ -1268,17 +1268,17 @@ function get_item_children(array &$item_list, array $parent, $recursive = true)
if ($item['gravity'] != GRAVITY_PARENT) {
if ($recursive) {
// Fallback to parent-uri if thr-parent is not set
- $thr_parent = $item['thr-parent'];
+ $thr_parent = $item['thr-parent-id'];
if ($thr_parent == '') {
- $thr_parent = $item['parent-uri'];
+ $thr_parent = $item['parent-uri-id'];
}
- if ($thr_parent == $parent['uri']) {
+ if ($thr_parent == $parent['uri-id']) {
$item['children'] = get_item_children($item_list, $item);
$children[] = $item;
unset($item_list[$i]);
}
- } elseif ($item['parent'] == $parent['id']) {
+ } elseif ($item['parent-uri-id'] == $parent['uri-id']) {
$children[] = $item;
unset($item_list[$i]);
}
@@ -1408,7 +1408,7 @@ function conv_sort(array $item_list, $order)
continue;
}
- $item_array[$item['uri']] = $item;
+ $item_array[$item['uri-id']] = $item;
}
// Extract the top level items
diff --git a/mod/display.php b/mod/display.php
index 4d03e223ef..2a64bcfe66 100644
--- a/mod/display.php
+++ b/mod/display.php
@@ -20,7 +20,6 @@
*/
use Friendica\App;
-use Friendica\Content\Pager;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\ACL;
@@ -55,7 +54,7 @@ function display_init(App $a)
$item = null;
$item_user = local_user();
- $fields = ['id', 'parent', 'author-id', 'body', 'uid', 'guid', 'gravity'];
+ $fields = ['uri-id', 'parent-uri-id', '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) {
@@ -86,11 +85,11 @@ function display_init(App $a)
$item = Post::selectFirstForUser(local_user(), $fields, ['guid' => $a->argv[1], 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]);
}
} elseif ($a->argc >= 3 && $nick == 'feed-item') {
- $item_id = $a->argv[2];
- if (substr($item_id, -5) == '.atom') {
- $item_id = substr($item_id, 0, -5);
+ $uri_id = $a->argv[2];
+ if (substr($uri_id, -5) == '.atom') {
+ $uri_id = substr($uri_id, 0, -5);
}
- $item = Post::selectFirstForUser(local_user(), $fields, ['id' => $item_id, 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]);
+ $item = Post::selectFirstForUser(local_user(), $fields, ['uri-id' => $uri_id, 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]);
}
if (!DBA::isResult($item)) {
@@ -98,16 +97,16 @@ function display_init(App $a)
}
if ($a->argc >= 3 && $nick == 'feed-item') {
- displayShowFeed($item['id'], $a->argc > 3 && $a->argv[3] == 'conversation.atom');
+ displayShowFeed($item['uri-id'], $item['uid'], $a->argc > 3 && $a->argv[3] == 'conversation.atom');
}
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 uri-id '.$item['uri-id'], Logger::DEBUG);
+ displayShowFeed($item['uri-id'], $item['uid'], false);
}
if ($item['gravity'] != GRAVITY_PARENT) {
- $parent = Post::selectFirstForUser($item_user, $fields, ['id' => $item['parent']]);
+ $parent = Post::selectFirstForUser($item_user, $fields, ['uid' => $item['uid'], 'uri-id' => $item['parent-uri-id']]);
$item = $parent ?: $item;
}
@@ -187,49 +186,44 @@ function display_content(App $a, $update = false, $update_uid = 0)
$force = (bool)($_REQUEST['force'] ?? false);
if ($update) {
- $item_id = $_REQUEST['item_id'];
- $item = Post::selectFirst(['uid', 'parent', 'parent-uri', 'parent-uri-id'], ['id' => $item_id]);
+ $uri_id = $_REQUEST['uri_id'];
+ $item = Post::selectFirst(['uid', 'parent-uri-id'], ['uri-id' => $uri_id, 'uid' => $update_uid]);
if ($item['uid'] != 0) {
$a->profile = ['uid' => intval($item['uid'])];
} else {
$a->profile = ['uid' => intval($update_uid)];
}
- $item_parent = $item['parent'];
- $item_parent_uri = $item['parent-uri'];
+ $parent_uri_id = $item['parent-uri-id'];
} else {
- $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
- $item_parent = $item_id;
+ $uri_id = (($a->argc > 2) ? $a->argv[2] : 0);
+ $parent_uri_id = $uri_id;
if ($a->argc == 2) {
- $item_parent = 0;
- $fields = ['id', 'parent', 'parent-uri', 'parent-uri-id', 'uid'];
+ $fields = ['uri-id', 'parent-uri-id', 'uid'];
if (local_user()) {
$condition = ['guid' => $a->argv[1], 'uid' => local_user()];
$item = Post::selectFirstForUser(local_user(), $fields, $condition);
if (DBA::isResult($item)) {
- $item_id = $item['id'];
- $item_parent = $item['parent'];
- $item_parent_uri = $item['parent-uri'];
+ $uri_id = $item['uri-id'];
+ $parent_uri_id = $item['parent-uri-id'];
}
}
- if (($item_parent == 0) && remote_user()) {
+ if (($parent_uri_id == 0) && remote_user()) {
$item = Post::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_parent_uri = $item['parent-uri'];
+ $uri_id = $item['uri-id'];
+ $parent_uri_id = $item['parent-uri-id'];
}
}
- if ($item_parent == 0) {
+ if ($parent_uri_id == 0) {
$condition = ['private' => [Item::PUBLIC, Item::UNLISTED], 'guid' => $a->argv[1], 'uid' => 0];
$item = Post::selectFirstForUser(local_user(), $fields, $condition);
if (DBA::isResult($item)) {
- $item_id = $item['id'];
- $item_parent = $item['parent'];
- $item_parent_uri = $item['parent-uri'];
+ $uri_id = $item['uri-id'];
+ $parent_uri_id = $item['parent-uri-id'];
}
}
}
@@ -244,11 +238,11 @@ function display_content(App $a, $update = false, $update_uid = 0)
}
// We are displaying an "alternate" link if that post was public. See issue 2864
- $is_public = Post::exists(['id' => $item_id, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
+ $is_public = Post::exists(['uri-id' => $uri_id, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
if ($is_public) {
// For the atom feed the nickname doesn't matter at all, we only need the item id.
- $alternate = DI::baseUrl().'/display/feed-item/'.$item_id.'.atom';
- $conversation = DI::baseUrl().'/display/feed-item/'.$item_parent.'/conversation.atom';
+ $alternate = DI::baseUrl().'/display/feed-item/'.$uri_id.'.atom';
+ $conversation = DI::baseUrl().'/display/feed-item/' . $parent_uri_id . '/conversation.atom';
} else {
$alternate = '';
$conversation = '';
@@ -262,8 +256,8 @@ function display_content(App $a, $update = false, $update_uid = 0)
$item_uid = local_user();
$parent = null;
- if (!empty($item_parent_uri)) {
- $parent = Post::selectFirst(['uid'], ['uri' => $item_parent_uri, 'wall' => true]);
+ if (!empty($parent_uri_id)) {
+ $parent = Post::selectFirst(['uid'], ['uri-id' => $parent_uri_id, 'wall' => true]);
}
if (DBA::isResult($parent)) {
@@ -305,7 +299,7 @@ function display_content(App $a, $update = false, $update_uid = 0)
$sql_extra = Item::getPermissionsSQLByUserId($a->profile['uid']);
if (local_user() && (local_user() == $a->profile['uid'])) {
- $condition = ['parent-uri' => $item_parent_uri, 'uid' => local_user(), 'unseen' => true];
+ $condition = ['parent-uri-id' => $parent_uri_id, 'uid' => local_user(), 'unseen' => true];
$unseen = Post::exists($condition);
} else {
$unseen = false;
@@ -315,23 +309,23 @@ function display_content(App $a, $update = false, $update_uid = 0)
return '';
}
- $condition = ["`id` = ? AND `uid` IN (0, ?) " . $sql_extra, $item_id, $item_uid];
- $fields = ['parent-uri', 'body', 'title', 'author-name', 'author-avatar', 'plink', 'author-id', 'owner-id', 'contact-id'];
+ $condition = ["`uri-id` = ? AND `uid` IN (0, ?) " . $sql_extra, $uri_id, $item_uid];
+ $fields = ['parent-uri-id', 'body', 'title', 'author-name', 'author-avatar', 'plink', 'author-id', 'owner-id', 'contact-id'];
$item = Post::selectFirstForUser($a->profile['uid'], $fields, $condition);
if (!DBA::isResult($item)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('The requested item doesn\'t exist or has been deleted.'));
}
- $item['uri'] = $item['parent-uri'];
+ $item['uri-id'] = $item['parent-uri-id'];
if ($unseen) {
- $condition = ['parent-uri' => $item_parent_uri, 'uid' => local_user(), 'unseen' => true];
+ $condition = ['parent-uri-id' => $parent_uri_id, 'uid' => local_user(), 'unseen' => true];
Item::update(['unseen' => false], $condition);
}
- if (!$update) {
- $o .= "";
+ if (!$update && local_user()) {
+ $o .= "";
}
$o .= conversation($a, [$item], 'display', $update_uid, false, 'commented', $item_uid);
@@ -396,9 +390,9 @@ function display_content(App $a, $update = false, $update_uid = 0)
return $o;
}
-function displayShowFeed($item_id, $conversation)
+function displayShowFeed(int $uri_id, int $uid, bool $conversation)
{
- $xml = DFRN::itemFeed($item_id, $conversation);
+ $xml = DFRN::itemFeed($uri_id, $uid, $conversation);
if ($xml == '') {
throw new HTTPException\InternalServerErrorException(DI::l10n()->t('The feed for this item is unavailable.'));
}
diff --git a/mod/notes.php b/mod/notes.php
index b0709eb952..b7f840b08c 100644
--- a/mod/notes.php
+++ b/mod/notes.php
@@ -82,7 +82,7 @@ function notes_content(App $a, $update = false)
$params = ['order' => ['created' => true],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
- $r = Post::selectThreadForUser(local_user(), ['uri'], $condition, $params);
+ $r = Post::selectThreadForUser(local_user(), ['uri-id'], $condition, $params);
$count = 0;
diff --git a/src/Model/Contact.php b/src/Model/Contact.php
index 153a7dc8a4..05c7fb61fb 100644
--- a/src/Model/Contact.php
+++ b/src/Model/Contact.php
@@ -1339,7 +1339,7 @@ class Contact
}
if ($thread_mode) {
- $items = Post::toArray(Post::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri', 'thr-parent-id', 'author-id'], $condition, $params));
+ $items = Post::toArray(Post::selectForUser(local_user(), ['uri-id', 'gravity', 'parent-uri-id', 'thr-parent-id', 'author-id'], $condition, $params));
$o .= conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
} else {
diff --git a/src/Model/Item.php b/src/Model/Item.php
index 393fead5f8..7e5ae10e86 100644
--- a/src/Model/Item.php
+++ b/src/Model/Item.php
@@ -73,7 +73,8 @@ class Item
// Field list that is used to display the items
const DISPLAY_FIELDLIST = [
- 'uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid', 'network', 'gravity',
+ 'uid', 'id', 'parent', 'guid', 'network', 'gravity',
+ 'uri-id', 'uri', 'thr-parent-id', 'thr-parent', 'parent-uri-id', 'parent-uri',
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
'wall', 'private', 'starred', 'origin', 'title', 'body', 'language',
'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
@@ -350,7 +351,7 @@ class Item
{
Logger::info('Mark item for deletion by id', ['id' => $item_id, 'callstack' => System::callstack()]);
// locate item to be deleted
- $fields = ['id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri', 'origin',
+ $fields = ['id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri-id', 'origin',
'deleted', 'resource-id', 'event-id',
'verb', 'object-type', 'object', 'target', 'contact-id', 'psid', 'gravity'];
$item = Post::selectFirst($fields, ['id' => $item_id]);
@@ -401,10 +402,10 @@ class Item
DBA::update('item', $item_fields, ['id' => $item['id']]);
Post\Category::storeTextByURIId($item['uri-id'], $item['uid'], '');
- self::deleteThread($item['id'], $item['parent-uri']);
+ self::deleteThread($item['id'], $item['parent-uri-id']);
- if (!Post::exists(["`uri` = ? AND `uid` != 0 AND NOT `deleted`", $item['uri']])) {
- self::markForDeletion(['uri' => $item['uri'], 'uid' => 0, 'deleted' => false], $priority);
+ if (!Post::exists(["`uri-id` = ? AND `uid` != 0 AND NOT `deleted`", $item['uri-id']])) {
+ self::markForDeletion(['uri-id' => $item['uri-id'], 'uid' => 0, 'deleted' => false], $priority);
}
Post\DeliveryData::delete($item['uri-id']);
@@ -425,7 +426,7 @@ class Item
// Is it our comment and/or our thread?
if (($item['origin'] || $parent['origin']) && ($item['uid'] != 0)) {
// When we delete the original post we will delete all existing copies on the server as well
- self::markForDeletion(['uri' => $item['uri'], 'deleted' => false], $priority);
+ self::markForDeletion(['uri-id' => $item['uri-id'], 'deleted' => false], $priority);
// send the notification upstream/downstream
if ($priority) {
@@ -435,7 +436,7 @@ class Item
Post\User::update($item['uri-id'], $item['uid'], ['hidden' => true]);
// When we delete just our local user copy of an item, we have to set a marker to hide it
- $global_item = Post::selectFirst(['id'], ['uri' => $item['uri'], 'uid' => 0, 'deleted' => false]);
+ $global_item = Post::selectFirst(['id'], ['uri-id' => $item['uri-id'], 'uid' => 0, 'deleted' => false]);
if (DBA::isResult($global_item)) {
DBA::update('user-item', ['hidden' => true], ['iid' => $global_item['id'], 'uid' => $item['uid']], true);
}
@@ -446,7 +447,6 @@ class Item
return true;
}
-
private static function guid($item, $notify)
{
if (!empty($item['guid'])) {
@@ -560,8 +560,8 @@ class Item
return true;
}
- $condition = ["`uri` = ? AND `network` IN (?, ?) AND `uid` = ?",
- $item['uri'], $item['network'], Protocol::DFRN, $item['uid']];
+ $condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'],
+ 'network' => [$item['network'], Protocol::DFRN]];
if (Post::exists($condition)) {
Logger::notice('duplicated item with the same uri found.', $item);
return true;
@@ -589,8 +589,8 @@ class Item
* There is a timing issue here that sometimes creates double postings.
* An unique index would help - but the limitations of MySQL (maximum size of index values) prevent this.
*/
- if (($item['uid'] == 0) && Post::exists(['uri' => trim($item['uri']), 'uid' => 0])) {
- Logger::notice('Global item already stored.', ['uri' => $item['uri'], 'network' => $item['network']]);
+ if (($item['uid'] == 0) && Post::exists(['uri-id' => $item['uri-id'], 'uid' => 0])) {
+ Logger::notice('Global item already stored.', ['uri-id' => $item['uri-id'], 'network' => $item['network']]);
return true;
}
@@ -708,15 +708,15 @@ class Item
private static function getDuplicateID(array $item)
{
if (empty($item['network']) || in_array($item['network'], Protocol::FEDERATED)) {
- $condition = ["`uri` = ? AND `uid` = ? AND `network` IN (?, ?, ?, ?)",
- trim($item['uri']), $item['uid'],
+ $condition = ["`uri-id` = ? AND `uid` = ? AND `network` IN (?, ?, ?, ?)",
+ $item['uri-id'], $item['uid'],
Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS];
$existing = Post::selectFirst(['id', 'network'], $condition);
if (DBA::isResult($existing)) {
// We only log the entries with a different user id than 0. Otherwise we would have too many false positives
if ($item['uid'] != 0) {
Logger::notice('Item already existed for user', [
- 'uri' => $item['uri'],
+ 'uri-id' => $item['uri-id'],
'uid' => $item['uid'],
'network' => $item['network'],
'existing_id' => $existing["id"],
@@ -740,28 +740,29 @@ class Item
private static function getTopLevelParent(array $item)
{
$fields = ['uid', 'uri', 'parent-uri', 'id', 'deleted',
+ 'uri-id', 'parent-uri-id',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'wall', 'private', 'forum_mode', 'origin', 'author-id'];
- $condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid']];
+ $condition = ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']];
$params = ['order' => ['id' => false]];
$parent = Post::selectFirst($fields, $condition, $params);
if (!DBA::isResult($parent)) {
- Logger::notice('item parent was not found - ignoring item', ['thr-parent' => $item['thr-parent'], 'uid' => $item['uid']]);
+ Logger::notice('item parent was not found - ignoring item', ['thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
return [];
}
- if ($parent['uri'] == $parent['parent-uri']) {
+ if ($parent['uri-id'] == $parent['parent-uri-id']) {
return $parent;
}
- $condition = ['uri' => $parent['parent-uri'],
- 'parent-uri' => $parent['parent-uri'],
+ $condition = ['uri-id' => $parent['parent-uri-id'],
+ 'parent-uri-id' => $parent['parent-uri-id'],
'uid' => $parent['uid']];
$params = ['order' => ['id' => false]];
$toplevel_parent = Post::selectFirst($fields, $condition, $params);
if (!DBA::isResult($toplevel_parent)) {
- Logger::notice('item top level parent was not found - ignoring item', ['parent-uri' => $parent['parent-uri'], 'uid' => $parent['uid']]);
+ Logger::notice('item top level parent was not found - ignoring item', ['parent-uri-id' => $parent['parent-uri-id'], 'uid' => $parent['uid']]);
return [];
}
@@ -780,7 +781,7 @@ class Item
if (isset($item['gravity'])) {
return intval($item['gravity']);
- } elseif ($item['parent-uri'] === $item['uri']) {
+ } elseif ($item['parent-uri-id'] === $item['uri-id']) {
return GRAVITY_PARENT;
} elseif ($activity->match($item['verb'], Activity::POST)) {
return GRAVITY_COMMENT;
@@ -829,6 +830,8 @@ class Item
$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']);
+
// Store conversation data
$item = Conversation::insert($item);
@@ -941,20 +944,21 @@ class Item
}
// If the thread originated from this node, we check the permission against the thread starter
- $condition = ['uri' => $toplevel_parent['uri'], 'wall' => true];
+ $condition = ['uri-id' => $toplevel_parent['uri-id'], 'wall' => true];
$localTopLevelParent = Post::selectFirst(['uid'], $condition);
if (!empty($localTopLevelParent['uid']) && !self::isAllowedByUser($item, $localTopLevelParent['uid'])) {
return 0;
}
- $parent_id = $toplevel_parent['id'];
- $item['parent-uri'] = $toplevel_parent['uri'];
- $item['deleted'] = $toplevel_parent['deleted'];
- $item['allow_cid'] = $toplevel_parent['allow_cid'];
- $item['allow_gid'] = $toplevel_parent['allow_gid'];
- $item['deny_cid'] = $toplevel_parent['deny_cid'];
- $item['deny_gid'] = $toplevel_parent['deny_gid'];
- $parent_origin = $toplevel_parent['origin'];
+ $parent_id = $toplevel_parent['id'];
+ $item['parent-uri'] = $toplevel_parent['uri'];
+ $item['parent-uri-id'] = $toplevel_parent['uri-id'];
+ $item['deleted'] = $toplevel_parent['deleted'];
+ $item['allow_cid'] = $toplevel_parent['allow_cid'];
+ $item['allow_gid'] = $toplevel_parent['allow_gid'];
+ $item['deny_cid'] = $toplevel_parent['deny_cid'];
+ $item['deny_gid'] = $toplevel_parent['deny_gid'];
+ $parent_origin = $toplevel_parent['origin'];
// Don't federate received participation messages
if ($item['verb'] != Activity::FOLLOW) {
@@ -1017,9 +1021,9 @@ class Item
$item["global"] = true;
// Set the global flag on all items if this was a global item entry
- DBA::update('item', ['global' => true], ['uri' => $item["uri"]]);
+ DBA::update('item', ['global' => true], ['uri-id' => $item['uri-id']]);
} else {
- $item["global"] = Post::exists(['uid' => 0, 'uri' => $item["uri"]]);
+ $item['global'] = Post::exists(['uid' => 0, 'uri-id' => $item['uri-id']]);
}
// ACL settings
@@ -1145,7 +1149,7 @@ class Item
}
$condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']];
- if (DBA::exists('item', $condition)) {
+ if (Post::exists($condition)) {
Logger::notice('Item is already inserted - aborting', $condition);
return 0;
}
@@ -1464,8 +1468,8 @@ class Item
$origin_uid = 0;
- if ($item['uri'] != $item['parent-uri']) {
- $parents = Post::select(['uid', 'origin'], ["`uri` = ? AND `uid` != 0", $item['parent-uri']]);
+ if ($item['uri-id'] != $item['parent-uri-id']) {
+ $parents = Post::select(['uid', 'origin'], ["`uri-id` = ? AND `uid` != 0", $item['parent-uri-id']]);
while ($parent = Post::fetch($parents)) {
$users[$parent['uid']] = $parent['uid'];
if ($parent['origin'] && !$origin) {
@@ -1590,7 +1594,7 @@ class Item
*/
private static function addShadow($itemid)
{
- $fields = ['uid', 'private', 'moderated', 'visible', 'deleted', 'network', 'uri'];
+ $fields = ['uid', 'private', 'moderated', 'visible', 'deleted', 'network', 'uri-id'];
$condition = ['id' => $itemid, 'parent' => [0, $itemid]];
$item = Post::selectFirst($fields, $condition);
@@ -1613,7 +1617,7 @@ class Item
return;
}
- if (Post::exists(['uri' => $item['uri'], 'uid' => 0])) {
+ if (Post::exists(['uri-id' => $item['uri-id'], 'uid' => 0])) {
return;
}
@@ -1631,7 +1635,7 @@ class Item
unset($item['postopts']);
unset($item['inform']);
unset($item['post-type']);
- if ($item['uri'] == $item['parent-uri']) {
+ if ($item['uri-id'] == $item['parent-uri-id']) {
$item['contact-id'] = $item['owner-id'];
} else {
$item['contact-id'] = $item['author-id'];
@@ -1670,12 +1674,12 @@ class Item
}
// Is there a shadow parent?
- if (!Post::exists(['uri' => $item['parent-uri'], 'uid' => 0])) {
+ if (!Post::exists(['uri-id' => $item['parent-uri-id'], 'uid' => 0])) {
return;
}
// Is there already a shadow entry?
- if (Post::exists(['uri' => $item['uri'], 'uid' => 0])) {
+ if (Post::exists(['uri-id' => $item['uri-id'], 'uid' => 0])) {
return;
}
@@ -1698,7 +1702,7 @@ class Item
$public_shadow = self::insert($item, false, true);
- Logger::info('Stored public shadow', ['uri' => $item['uri'], 'id' => $public_shadow]);
+ Logger::info('Stored public shadow', ['uri-id' => $item['uri-id'], 'id' => $public_shadow]);
// If this was a comment to a Diaspora post we don't get our comment back.
// This means that we have to distribute the comment by ourselves.
@@ -1835,7 +1839,7 @@ class Item
$update = ($arr['private'] != self::PRIVATE) || in_array($arr['network'], Protocol::FEDERATED);
// Is it a forum? Then we don't care about the rules from above
- if (!$update && in_array($arr["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN]) && ($arr["parent-uri"] === $arr["uri"])) {
+ if (!$update && in_array($arr["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN]) && ($arr["parent-uri-id"] === $arr["uri-id"])) {
if (DBA::exists('contact', ['id' => $arr['contact-id'], 'forum' => true])) {
$update = true;
}
@@ -2428,7 +2432,7 @@ class Item
return false;
}
- $item_uri = $item['uri'];
+ $uri_id = $item['uri-id'];
if (!in_array($item['uid'], [0, $uid])) {
return false;
@@ -2439,7 +2443,7 @@ class Item
if (($item['parent-uri-id'] == $item['uri-id']) && !empty($stored)) {
$item = Post::selectFirst(self::ITEM_FIELDLIST, ['id' => $stored]);
if (!DBA::isResult($item)) {
- Logger::info('Could not fetch just created item - should not happen', ['stored' => $stored, 'uid' => $uid, 'item-uri' => $item_uri]);
+ Logger::info('Could not fetch just created item - should not happen', ['stored' => $stored, 'uid' => $uid, 'uri-id' => $uri_id]);
return false;
}
}
@@ -2514,7 +2518,7 @@ class Item
}
$condition = ['vid' => $vids, 'deleted' => false, 'gravity' => GRAVITY_ACTIVITY,
- 'author-id' => $author_id, 'uid' => $item['uid'], 'thr-parent' => $item_uri];
+ 'author-id' => $author_id, 'uid' => $item['uid'], 'thr-parent-id' => $uri_id];
$like_item = Post::selectFirst(['id', 'guid', 'verb'], $condition);
if (DBA::isResult($like_item)) {
@@ -2651,7 +2655,7 @@ class Item
Logger::info('Update thread', ['item' => $itemid, 'guid' => $item["guid"], 'result' => $result]);
}
- private static function deleteThread($itemid, $itemuri = "")
+ private static function deleteThread($itemid, $uri_id)
{
$item = DBA::selectFirst('thread', ['uid'], ['iid' => $itemid]);
if (!DBA::isResult($item)) {
@@ -2663,12 +2667,10 @@ class Item
Logger::info('Deleted thread', ['item' => $itemid, 'result' => $result]);
- if ($itemuri != "") {
- $condition = ["`uri` = ? AND NOT `deleted` AND NOT (`uid` IN (?, 0))", $itemuri, $item["uid"]];
- if (!Post::exists($condition)) {
- DBA::delete('item', ['uri' => $itemuri, 'uid' => 0]);
- Logger::debug('Deleted shadow item', ['id' => $itemid, 'uri' => $itemuri]);
- }
+ $condition = ["`uri-id` = ? AND NOT `deleted` AND NOT (`uid` IN (?, 0))", $uri_id, $item["uid"]];
+ if (!Post::exists($condition)) {
+ DBA::delete('item', ['uri-id' => $uri_id, 'uid' => 0]);
+ Logger::debug('Deleted shadow item', ['id' => $itemid, 'uri-id' => $uri_id]);
}
}
@@ -3051,7 +3053,7 @@ class Item
if (($item['author-id'] == $item['owner-id']) ||
($owner['id'] == $item['contact-id']) ||
- ($item['uri'] != $item['parent-uri']) ||
+ ($item['uri-id'] != $item['parent-uri-id']) ||
$item['origin']) {
return false;
}
@@ -3072,22 +3074,12 @@ class Item
$ssl_uri = str_replace('http://', 'https://', $uri);
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
- $item = DBA::selectFirst('item', ['id'], ['uri' => $uris, 'uid' => $uid]);
+ $item = Post::selectFirst(['id'], ['uri' => $uris, 'uid' => $uid]);
if (DBA::isResult($item)) {
return $item['id'];
}
- $itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]);
- if (!DBA::isResult($itemcontent)) {
- return 0;
- }
-
- $itemuri = DBA::selectFirst('item-uri', ['uri'], ['id' => $itemcontent['uri-id']]);
- if (!DBA::isResult($itemuri)) {
- return 0;
- }
-
- $item = DBA::selectFirst('item', ['id'], ['uri' => $itemuri['uri'], 'uid' => $uid]);
+ $item = Post::selectFirst(['id'], ['plink' => $uris, 'uid' => $uid]);
if (DBA::isResult($item)) {
return $item['id'];
}
@@ -3107,19 +3099,14 @@ class Item
$ssl_uri = str_replace('http://', 'https://', $uri);
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
- $item = DBA::selectFirst('item', ['uri'], ['uri' => $uris]);
+ $item = Post::selectFirst(['uri'], ['uri' => $uris]);
if (DBA::isResult($item)) {
return $item['uri'];
}
- $itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]);
- if (!DBA::isResult($itemcontent)) {
- return '';
- }
-
- $itemuri = DBA::selectFirst('item-uri', ['uri'], ['id' => $itemcontent['uri-id']]);
- if (DBA::isResult($itemuri)) {
- return $itemuri['uri'];
+ $item = Post::selectFirst(['uri'], ['plink' => $uris]);
+ if (DBA::isResult($item)) {
+ return $item['uri'];
}
return '';
diff --git a/src/Module/Conversation/Community.php b/src/Module/Conversation/Community.php
index c9468d4520..2febbe5a1e 100644
--- a/src/Module/Conversation/Community.php
+++ b/src/Module/Conversation/Community.php
@@ -356,7 +356,7 @@ class Community extends BaseModule
}
}
- $r = Post::selectThreadForUser(0, ['uri', 'commented', 'author-link'], $condition, $params);
+ $r = Post::selectThreadForUser(0, ['uri-id', 'commented', 'author-link'], $condition, $params);
$items = Post::toArray($r);
diff --git a/src/Module/Profile/Status.php b/src/Module/Profile/Status.php
index 786c3594a4..7684c84358 100644
--- a/src/Module/Profile/Status.php
+++ b/src/Module/Profile/Status.php
@@ -194,7 +194,7 @@ class Status extends BaseProfile
$pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
$params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]];
- $items_stmt = Post::select(['uri', 'thr-parent-id', 'gravity', 'author-id', 'received'], $condition, $params);
+ $items_stmt = Post::select(['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'received'], $condition, $params);
// Set a time stamp for this page. We will make use of it when we
// search for new items (update routine)
@@ -228,7 +228,7 @@ class Status extends BaseProfile
$condition = [];
}
- $pinned_items = Post::selectPinned($a->profile['uid'], ['uri', 'pinned'], $condition);
+ $pinned_items = Post::selectPinned($a->profile['uid'], ['uri-id', 'pinned'], $condition);
$pinned = Post::toArray($pinned_items);
$items = array_merge($items, $pinned);
}
diff --git a/src/Module/Update/Network.php b/src/Module/Update/Network.php
index bcaa11fd49..dbde3bab62 100644
--- a/src/Module/Update/Network.php
+++ b/src/Module/Update/Network.php
@@ -4,7 +4,6 @@ namespace Friendica\Module\Update;
use Friendica\Core\System;
use Friendica\DI;
-use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Module\Conversation\Network as NetworkModule;
diff --git a/src/Module/Update/Profile.php b/src/Module/Update/Profile.php
index 741bcc79c5..f660d96be6 100644
--- a/src/Module/Update/Profile.php
+++ b/src/Module/Update/Profile.php
@@ -78,7 +78,7 @@ class Profile extends BaseModule
}
$items_stmt = DBA::p(
- "SELECT DISTINCT(`parent-uri`) AS `uri`, `created` FROM `post-view`
+ "SELECT DISTINCT(`parent-uri-id`) AS `uri-id`, `created` FROM `post-view`
WHERE `uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
AND `visible` AND (NOT `deleted` OR `gravity` = ?)
AND NOT `moderated` AND `wall` $sql_extra4 $sql_extra
diff --git a/src/Object/Post.php b/src/Object/Post.php
index 925f752c9a..34f46f7978 100644
--- a/src/Object/Post.php
+++ b/src/Object/Post.php
@@ -287,8 +287,8 @@ class Post
$responses = [];
foreach ($response_verbs as $value => $verb) {
$responses[$verb] = [
- 'self' => $conv_responses[$verb][$item['uri']]['self'] ?? 0,
- 'output' => !empty($conv_responses[$verb][$item['uri']]) ? format_activity($conv_responses[$verb][$item['uri']]['links'], $verb, $item['uri']) : '',
+ 'self' => $conv_responses[$verb][$item['uri-id']]['self'] ?? 0,
+ 'output' => !empty($conv_responses[$verb][$item['uri-id']]) ? format_activity($conv_responses[$verb][$item['uri-id']]['links'], $verb, $item['uri-id']) : '',
];
}
diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php
index aa637ef4eb..7cb9db1a13 100644
--- a/src/Protocol/DFRN.php
+++ b/src/Protocol/DFRN.php
@@ -310,23 +310,26 @@ class DFRN
}
/**
- * Generate an atom entry for a given item id
+ * Generate an atom entry for a given uri id and user
*
- * @param int $item_id The item id
+ * @param int $uri_id The uri id
+ * @param int $uid The user id
* @param boolean $conversation Show the conversation. If false show the single post.
*
* @return string DFRN feed entry
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function itemFeed($item_id, $conversation = false)
+ public static function itemFeed(int $uri_id, int $uid, bool $conversation = false)
{
if ($conversation) {
- $condition = ['parent' => $item_id];
+ $condition = ['parent-uri-id' => $uri_id];
} else {
- $condition = ['id' => $item_id];
+ $condition = ['uri-id' => $uri_id];
}
+ $condition['uid'] = $uid;
+
$items = Post::selectToArray(Item::DELIVER_FIELDLIST, $condition);
if (!DBA::isResult($items)) {
return '';