1
0
Fork 0

"uri-id" instead of "uri" or "id"

This commit is contained in:
Michael 2021-01-27 10:01:42 +00:00
parent a7b07b6e2e
commit ef0400fc19
11 changed files with 130 additions and 147 deletions

View file

@ -838,8 +838,8 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
} }
} }
} else { } else {
$condition = ["`parent-uri` = ? AND `uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)", $condition = ["`parent-uri-id` = ? AND `uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
$parent['uri'], $uid, Verb::getID(Activity::FOLLOW)]; $parent['uri-id'], $uid, Verb::getID(Activity::FOLLOW)];
$activity = []; $activity = [];
} }
$items = conversation_fetch_items($parent, $items, $condition, $block_authors, $params, $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 = '<a href="' . $url . '"' . $sparkle . '>' . htmlentities($activity['author-name']) . '</a>'; $link = '<a href="' . $url . '"' . $sparkle . '>' . htmlentities($activity['author-name']) . '</a>';
if (empty($activity['thr-parent'])) { if (empty($activity['thr-parent-id'])) {
$activity['thr-parent'] = $activity['parent-uri']; $activity['thr-parent-id'] = $activity['parent-uri-id'];
} }
// Skip when the causer of the parent is the same than the author of the announce // 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])) { 'uid' => $activity['uid'], 'causer-id' => $activity['author-id'], 'gravity' => GRAVITY_PARENT])) {
continue; continue;
} }
if (!isset($conv_responses[$mode][$activity['thr-parent']])) { if (!isset($conv_responses[$mode][$activity['thr-parent-id']])) {
$conv_responses[$mode][$activity['thr-parent']] = [ $conv_responses[$mode][$activity['thr-parent-id']] = [
'links' => [], 'links' => [],
'self' => 0, '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 // only list each unique author once
continue; continue;
} }
if (public_contact() == $activity['author-id']) { 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 // there can only be one activity verb per item so if we found anything, we can stop looking
return; return;
@ -1268,17 +1268,17 @@ function get_item_children(array &$item_list, array $parent, $recursive = true)
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != GRAVITY_PARENT) {
if ($recursive) { if ($recursive) {
// Fallback to parent-uri if thr-parent is not set // Fallback to parent-uri if thr-parent is not set
$thr_parent = $item['thr-parent']; $thr_parent = $item['thr-parent-id'];
if ($thr_parent == '') { 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); $item['children'] = get_item_children($item_list, $item);
$children[] = $item; $children[] = $item;
unset($item_list[$i]); unset($item_list[$i]);
} }
} elseif ($item['parent'] == $parent['id']) { } elseif ($item['parent-uri-id'] == $parent['uri-id']) {
$children[] = $item; $children[] = $item;
unset($item_list[$i]); unset($item_list[$i]);
} }
@ -1408,7 +1408,7 @@ function conv_sort(array $item_list, $order)
continue; continue;
} }
$item_array[$item['uri']] = $item; $item_array[$item['uri-id']] = $item;
} }
// Extract the top level items // Extract the top level items

View file

@ -20,7 +20,6 @@
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Content\Pager;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML; use Friendica\Content\Text\HTML;
use Friendica\Core\ACL; use Friendica\Core\ACL;
@ -55,7 +54,7 @@ function display_init(App $a)
$item = null; $item = null;
$item_user = local_user(); $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 there is only one parameter, then check if this parameter could be a guid
if ($a->argc == 2) { 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]); $item = Post::selectFirstForUser(local_user(), $fields, ['guid' => $a->argv[1], 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]);
} }
} elseif ($a->argc >= 3 && $nick == 'feed-item') { } elseif ($a->argc >= 3 && $nick == 'feed-item') {
$item_id = $a->argv[2]; $uri_id = $a->argv[2];
if (substr($item_id, -5) == '.atom') { if (substr($uri_id, -5) == '.atom') {
$item_id = substr($item_id, 0, -5); $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)) { if (!DBA::isResult($item)) {
@ -98,16 +97,16 @@ function display_init(App $a)
} }
if ($a->argc >= 3 && $nick == 'feed-item') { 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')) { if (!empty($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'application/atom+xml')) {
Logger::log('Directly serving XML for id '.$item['id'], Logger::DEBUG); Logger::log('Directly serving XML for uri-id '.$item['uri-id'], Logger::DEBUG);
displayShowFeed($item['id'], false); displayShowFeed($item['uri-id'], $item['uid'], false);
} }
if ($item['gravity'] != GRAVITY_PARENT) { 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; $item = $parent ?: $item;
} }
@ -187,49 +186,44 @@ function display_content(App $a, $update = false, $update_uid = 0)
$force = (bool)($_REQUEST['force'] ?? false); $force = (bool)($_REQUEST['force'] ?? false);
if ($update) { if ($update) {
$item_id = $_REQUEST['item_id']; $uri_id = $_REQUEST['uri_id'];
$item = Post::selectFirst(['uid', 'parent', 'parent-uri', 'parent-uri-id'], ['id' => $item_id]); $item = Post::selectFirst(['uid', 'parent-uri-id'], ['uri-id' => $uri_id, 'uid' => $update_uid]);
if ($item['uid'] != 0) { if ($item['uid'] != 0) {
$a->profile = ['uid' => intval($item['uid'])]; $a->profile = ['uid' => intval($item['uid'])];
} else { } else {
$a->profile = ['uid' => intval($update_uid)]; $a->profile = ['uid' => intval($update_uid)];
} }
$item_parent = $item['parent']; $parent_uri_id = $item['parent-uri-id'];
$item_parent_uri = $item['parent-uri'];
} else { } else {
$item_id = (($a->argc > 2) ? $a->argv[2] : 0); $uri_id = (($a->argc > 2) ? $a->argv[2] : 0);
$item_parent = $item_id; $parent_uri_id = $uri_id;
if ($a->argc == 2) { if ($a->argc == 2) {
$item_parent = 0; $fields = ['uri-id', 'parent-uri-id', 'uid'];
$fields = ['id', 'parent', 'parent-uri', 'parent-uri-id', 'uid'];
if (local_user()) { if (local_user()) {
$condition = ['guid' => $a->argv[1], 'uid' => local_user()]; $condition = ['guid' => $a->argv[1], 'uid' => local_user()];
$item = Post::selectFirstForUser(local_user(), $fields, $condition); $item = Post::selectFirstForUser(local_user(), $fields, $condition);
if (DBA::isResult($item)) { if (DBA::isResult($item)) {
$item_id = $item['id']; $uri_id = $item['uri-id'];
$item_parent = $item['parent']; $parent_uri_id = $item['parent-uri-id'];
$item_parent_uri = $item['parent-uri'];
} }
} }
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]); $item = Post::selectFirst($fields, ['guid' => $a->argv[1], 'private' => Item::PRIVATE, 'origin' => true]);
if (DBA::isResult($item) && Contact::isFollower(remote_user(), $item['uid'])) { if (DBA::isResult($item) && Contact::isFollower(remote_user(), $item['uid'])) {
$item_id = $item['id']; $uri_id = $item['uri-id'];
$item_parent = $item['parent']; $parent_uri_id = $item['parent-uri-id'];
$item_parent_uri = $item['parent-uri'];
} }
} }
if ($item_parent == 0) { if ($parent_uri_id == 0) {
$condition = ['private' => [Item::PUBLIC, Item::UNLISTED], 'guid' => $a->argv[1], 'uid' => 0]; $condition = ['private' => [Item::PUBLIC, Item::UNLISTED], 'guid' => $a->argv[1], 'uid' => 0];
$item = Post::selectFirstForUser(local_user(), $fields, $condition); $item = Post::selectFirstForUser(local_user(), $fields, $condition);
if (DBA::isResult($item)) { if (DBA::isResult($item)) {
$item_id = $item['id']; $uri_id = $item['uri-id'];
$item_parent = $item['parent']; $parent_uri_id = $item['parent-uri-id'];
$item_parent_uri = $item['parent-uri'];
} }
} }
} }
@ -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 // 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) { if ($is_public) {
// For the atom feed the nickname doesn't matter at all, we only need the item id. // 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'; $alternate = DI::baseUrl().'/display/feed-item/'.$uri_id.'.atom';
$conversation = DI::baseUrl().'/display/feed-item/'.$item_parent.'/conversation.atom'; $conversation = DI::baseUrl().'/display/feed-item/' . $parent_uri_id . '/conversation.atom';
} else { } else {
$alternate = ''; $alternate = '';
$conversation = ''; $conversation = '';
@ -262,8 +256,8 @@ function display_content(App $a, $update = false, $update_uid = 0)
$item_uid = local_user(); $item_uid = local_user();
$parent = null; $parent = null;
if (!empty($item_parent_uri)) { if (!empty($parent_uri_id)) {
$parent = Post::selectFirst(['uid'], ['uri' => $item_parent_uri, 'wall' => true]); $parent = Post::selectFirst(['uid'], ['uri-id' => $parent_uri_id, 'wall' => true]);
} }
if (DBA::isResult($parent)) { 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']); $sql_extra = Item::getPermissionsSQLByUserId($a->profile['uid']);
if (local_user() && (local_user() == $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); $unseen = Post::exists($condition);
} else { } else {
$unseen = false; $unseen = false;
@ -315,23 +309,23 @@ function display_content(App $a, $update = false, $update_uid = 0)
return ''; return '';
} }
$condition = ["`id` = ? AND `uid` IN (0, ?) " . $sql_extra, $item_id, $item_uid]; $condition = ["`uri-id` = ? AND `uid` IN (0, ?) " . $sql_extra, $uri_id, $item_uid];
$fields = ['parent-uri', 'body', 'title', 'author-name', 'author-avatar', 'plink', 'author-id', 'owner-id', 'contact-id']; $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); $item = Post::selectFirstForUser($a->profile['uid'], $fields, $condition);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('The requested item doesn\'t exist or has been deleted.')); 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) { 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); Item::update(['unseen' => false], $condition);
} }
if (!$update) { if (!$update && local_user()) {
$o .= "<script> var netargs = '?item_id=" . $item_id . "'; </script>"; $o .= "<script> var netargs = '?uri_id=" . $item['uri-id'] . "'; </script>";
} }
$o .= conversation($a, [$item], 'display', $update_uid, false, 'commented', $item_uid); $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; 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 == '') { if ($xml == '') {
throw new HTTPException\InternalServerErrorException(DI::l10n()->t('The feed for this item is unavailable.')); throw new HTTPException\InternalServerErrorException(DI::l10n()->t('The feed for this item is unavailable.'));
} }

View file

@ -82,7 +82,7 @@ function notes_content(App $a, $update = false)
$params = ['order' => ['created' => true], $params = ['order' => ['created' => true],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
$r = Post::selectThreadForUser(local_user(), ['uri'], $condition, $params); $r = Post::selectThreadForUser(local_user(), ['uri-id'], $condition, $params);
$count = 0; $count = 0;

View file

@ -1339,7 +1339,7 @@ class Contact
} }
if ($thread_mode) { 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()); $o .= conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
} else { } else {

View file

@ -73,7 +73,8 @@ class Item
// Field list that is used to display the items // Field list that is used to display the items
const DISPLAY_FIELDLIST = [ 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', 'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
'wall', 'private', 'starred', 'origin', 'title', 'body', 'language', 'wall', 'private', 'starred', 'origin', 'title', 'body', 'language',
'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object', '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()]); Logger::info('Mark item for deletion by id', ['id' => $item_id, 'callstack' => System::callstack()]);
// locate item to be deleted // 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', 'deleted', 'resource-id', 'event-id',
'verb', 'object-type', 'object', 'target', 'contact-id', 'psid', 'gravity']; 'verb', 'object-type', 'object', 'target', 'contact-id', 'psid', 'gravity'];
$item = Post::selectFirst($fields, ['id' => $item_id]); $item = Post::selectFirst($fields, ['id' => $item_id]);
@ -401,10 +402,10 @@ class Item
DBA::update('item', $item_fields, ['id' => $item['id']]); DBA::update('item', $item_fields, ['id' => $item['id']]);
Post\Category::storeTextByURIId($item['uri-id'], $item['uid'], ''); 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']])) { if (!Post::exists(["`uri-id` = ? AND `uid` != 0 AND NOT `deleted`", $item['uri-id']])) {
self::markForDeletion(['uri' => $item['uri'], 'uid' => 0, 'deleted' => false], $priority); self::markForDeletion(['uri-id' => $item['uri-id'], 'uid' => 0, 'deleted' => false], $priority);
} }
Post\DeliveryData::delete($item['uri-id']); Post\DeliveryData::delete($item['uri-id']);
@ -425,7 +426,7 @@ class Item
// Is it our comment and/or our thread? // Is it our comment and/or our thread?
if (($item['origin'] || $parent['origin']) && ($item['uid'] != 0)) { 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 // 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 // send the notification upstream/downstream
if ($priority) { if ($priority) {
@ -435,7 +436,7 @@ class Item
Post\User::update($item['uri-id'], $item['uid'], ['hidden' => true]); 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 // 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)) { if (DBA::isResult($global_item)) {
DBA::update('user-item', ['hidden' => true], ['iid' => $global_item['id'], 'uid' => $item['uid']], true); DBA::update('user-item', ['hidden' => true], ['iid' => $global_item['id'], 'uid' => $item['uid']], true);
} }
@ -446,7 +447,6 @@ class Item
return true; return true;
} }
private static function guid($item, $notify) private static function guid($item, $notify)
{ {
if (!empty($item['guid'])) { if (!empty($item['guid'])) {
@ -560,8 +560,8 @@ class Item
return true; return true;
} }
$condition = ["`uri` = ? AND `network` IN (?, ?) AND `uid` = ?", $condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'],
$item['uri'], $item['network'], Protocol::DFRN, $item['uid']]; 'network' => [$item['network'], Protocol::DFRN]];
if (Post::exists($condition)) { if (Post::exists($condition)) {
Logger::notice('duplicated item with the same uri found.', $item); Logger::notice('duplicated item with the same uri found.', $item);
return true; return true;
@ -589,8 +589,8 @@ class Item
* There is a timing issue here that sometimes creates double postings. * 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. * 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])) { if (($item['uid'] == 0) && Post::exists(['uri-id' => $item['uri-id'], 'uid' => 0])) {
Logger::notice('Global item already stored.', ['uri' => $item['uri'], 'network' => $item['network']]); Logger::notice('Global item already stored.', ['uri-id' => $item['uri-id'], 'network' => $item['network']]);
return true; return true;
} }
@ -708,15 +708,15 @@ class Item
private static function getDuplicateID(array $item) private static function getDuplicateID(array $item)
{ {
if (empty($item['network']) || in_array($item['network'], Protocol::FEDERATED)) { if (empty($item['network']) || in_array($item['network'], Protocol::FEDERATED)) {
$condition = ["`uri` = ? AND `uid` = ? AND `network` IN (?, ?, ?, ?)", $condition = ["`uri-id` = ? AND `uid` = ? AND `network` IN (?, ?, ?, ?)",
trim($item['uri']), $item['uid'], $item['uri-id'], $item['uid'],
Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS]; Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS];
$existing = Post::selectFirst(['id', 'network'], $condition); $existing = Post::selectFirst(['id', 'network'], $condition);
if (DBA::isResult($existing)) { if (DBA::isResult($existing)) {
// We only log the entries with a different user id than 0. Otherwise we would have too many false positives // We only log the entries with a different user id than 0. Otherwise we would have too many false positives
if ($item['uid'] != 0) { if ($item['uid'] != 0) {
Logger::notice('Item already existed for user', [ Logger::notice('Item already existed for user', [
'uri' => $item['uri'], 'uri-id' => $item['uri-id'],
'uid' => $item['uid'], 'uid' => $item['uid'],
'network' => $item['network'], 'network' => $item['network'],
'existing_id' => $existing["id"], 'existing_id' => $existing["id"],
@ -740,28 +740,29 @@ class Item
private static function getTopLevelParent(array $item) private static function getTopLevelParent(array $item)
{ {
$fields = ['uid', 'uri', 'parent-uri', 'id', 'deleted', $fields = ['uid', 'uri', 'parent-uri', 'id', 'deleted',
'uri-id', 'parent-uri-id',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'wall', 'private', 'forum_mode', 'origin', 'author-id']; '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]]; $params = ['order' => ['id' => false]];
$parent = Post::selectFirst($fields, $condition, $params); $parent = Post::selectFirst($fields, $condition, $params);
if (!DBA::isResult($parent)) { 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 []; return [];
} }
if ($parent['uri'] == $parent['parent-uri']) { if ($parent['uri-id'] == $parent['parent-uri-id']) {
return $parent; return $parent;
} }
$condition = ['uri' => $parent['parent-uri'], $condition = ['uri-id' => $parent['parent-uri-id'],
'parent-uri' => $parent['parent-uri'], 'parent-uri-id' => $parent['parent-uri-id'],
'uid' => $parent['uid']]; 'uid' => $parent['uid']];
$params = ['order' => ['id' => false]]; $params = ['order' => ['id' => false]];
$toplevel_parent = Post::selectFirst($fields, $condition, $params); $toplevel_parent = Post::selectFirst($fields, $condition, $params);
if (!DBA::isResult($toplevel_parent)) { 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 []; return [];
} }
@ -780,7 +781,7 @@ class Item
if (isset($item['gravity'])) { if (isset($item['gravity'])) {
return intval($item['gravity']); return intval($item['gravity']);
} elseif ($item['parent-uri'] === $item['uri']) { } elseif ($item['parent-uri-id'] === $item['uri-id']) {
return GRAVITY_PARENT; return GRAVITY_PARENT;
} elseif ($activity->match($item['verb'], Activity::POST)) { } elseif ($activity->match($item['verb'], Activity::POST)) {
return GRAVITY_COMMENT; return GRAVITY_COMMENT;
@ -829,6 +830,8 @@ class Item
$item['thr-parent'] = trim($item['thr-parent'] ?? $item['parent-uri'] ?? $item['uri']); $item['thr-parent'] = trim($item['thr-parent'] ?? $item['parent-uri'] ?? $item['uri']);
$item['parent-uri'] = $item['thr-parent']; $item['parent-uri'] = $item['thr-parent'];
$item['thr-parent-id'] = $item['parent-uri-id'] = ItemURI::getIdByURI($item['thr-parent']);
// Store conversation data // Store conversation data
$item = Conversation::insert($item); $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 // 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); $localTopLevelParent = Post::selectFirst(['uid'], $condition);
if (!empty($localTopLevelParent['uid']) && !self::isAllowedByUser($item, $localTopLevelParent['uid'])) { if (!empty($localTopLevelParent['uid']) && !self::isAllowedByUser($item, $localTopLevelParent['uid'])) {
return 0; return 0;
} }
$parent_id = $toplevel_parent['id']; $parent_id = $toplevel_parent['id'];
$item['parent-uri'] = $toplevel_parent['uri']; $item['parent-uri'] = $toplevel_parent['uri'];
$item['deleted'] = $toplevel_parent['deleted']; $item['parent-uri-id'] = $toplevel_parent['uri-id'];
$item['allow_cid'] = $toplevel_parent['allow_cid']; $item['deleted'] = $toplevel_parent['deleted'];
$item['allow_gid'] = $toplevel_parent['allow_gid']; $item['allow_cid'] = $toplevel_parent['allow_cid'];
$item['deny_cid'] = $toplevel_parent['deny_cid']; $item['allow_gid'] = $toplevel_parent['allow_gid'];
$item['deny_gid'] = $toplevel_parent['deny_gid']; $item['deny_cid'] = $toplevel_parent['deny_cid'];
$parent_origin = $toplevel_parent['origin']; $item['deny_gid'] = $toplevel_parent['deny_gid'];
$parent_origin = $toplevel_parent['origin'];
// Don't federate received participation messages // Don't federate received participation messages
if ($item['verb'] != Activity::FOLLOW) { if ($item['verb'] != Activity::FOLLOW) {
@ -1017,9 +1021,9 @@ class Item
$item["global"] = true; $item["global"] = true;
// Set the global flag on all items if this was a global item entry // 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 { } else {
$item["global"] = Post::exists(['uid' => 0, 'uri' => $item["uri"]]); $item['global'] = Post::exists(['uid' => 0, 'uri-id' => $item['uri-id']]);
} }
// ACL settings // ACL settings
@ -1145,7 +1149,7 @@ class Item
} }
$condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']]; $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); Logger::notice('Item is already inserted - aborting', $condition);
return 0; return 0;
} }
@ -1464,8 +1468,8 @@ class Item
$origin_uid = 0; $origin_uid = 0;
if ($item['uri'] != $item['parent-uri']) { if ($item['uri-id'] != $item['parent-uri-id']) {
$parents = Post::select(['uid', 'origin'], ["`uri` = ? AND `uid` != 0", $item['parent-uri']]); $parents = Post::select(['uid', 'origin'], ["`uri-id` = ? AND `uid` != 0", $item['parent-uri-id']]);
while ($parent = Post::fetch($parents)) { while ($parent = Post::fetch($parents)) {
$users[$parent['uid']] = $parent['uid']; $users[$parent['uid']] = $parent['uid'];
if ($parent['origin'] && !$origin) { if ($parent['origin'] && !$origin) {
@ -1590,7 +1594,7 @@ class Item
*/ */
private static function addShadow($itemid) 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]]; $condition = ['id' => $itemid, 'parent' => [0, $itemid]];
$item = Post::selectFirst($fields, $condition); $item = Post::selectFirst($fields, $condition);
@ -1613,7 +1617,7 @@ class Item
return; return;
} }
if (Post::exists(['uri' => $item['uri'], 'uid' => 0])) { if (Post::exists(['uri-id' => $item['uri-id'], 'uid' => 0])) {
return; return;
} }
@ -1631,7 +1635,7 @@ class Item
unset($item['postopts']); unset($item['postopts']);
unset($item['inform']); unset($item['inform']);
unset($item['post-type']); unset($item['post-type']);
if ($item['uri'] == $item['parent-uri']) { if ($item['uri-id'] == $item['parent-uri-id']) {
$item['contact-id'] = $item['owner-id']; $item['contact-id'] = $item['owner-id'];
} else { } else {
$item['contact-id'] = $item['author-id']; $item['contact-id'] = $item['author-id'];
@ -1670,12 +1674,12 @@ class Item
} }
// Is there a shadow parent? // 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; return;
} }
// Is there already a shadow entry? // 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; return;
} }
@ -1698,7 +1702,7 @@ class Item
$public_shadow = self::insert($item, false, true); $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. // 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. // 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); $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 // 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])) { if (DBA::exists('contact', ['id' => $arr['contact-id'], 'forum' => true])) {
$update = true; $update = true;
} }
@ -2428,7 +2432,7 @@ class Item
return false; return false;
} }
$item_uri = $item['uri']; $uri_id = $item['uri-id'];
if (!in_array($item['uid'], [0, $uid])) { if (!in_array($item['uid'], [0, $uid])) {
return false; return false;
@ -2439,7 +2443,7 @@ class Item
if (($item['parent-uri-id'] == $item['uri-id']) && !empty($stored)) { if (($item['parent-uri-id'] == $item['uri-id']) && !empty($stored)) {
$item = Post::selectFirst(self::ITEM_FIELDLIST, ['id' => $stored]); $item = Post::selectFirst(self::ITEM_FIELDLIST, ['id' => $stored]);
if (!DBA::isResult($item)) { 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; return false;
} }
} }
@ -2514,7 +2518,7 @@ class Item
} }
$condition = ['vid' => $vids, 'deleted' => false, 'gravity' => GRAVITY_ACTIVITY, $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); $like_item = Post::selectFirst(['id', 'guid', 'verb'], $condition);
if (DBA::isResult($like_item)) { if (DBA::isResult($like_item)) {
@ -2651,7 +2655,7 @@ class Item
Logger::info('Update thread', ['item' => $itemid, 'guid' => $item["guid"], 'result' => $result]); 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]); $item = DBA::selectFirst('thread', ['uid'], ['iid' => $itemid]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
@ -2663,12 +2667,10 @@ class Item
Logger::info('Deleted thread', ['item' => $itemid, 'result' => $result]); Logger::info('Deleted thread', ['item' => $itemid, 'result' => $result]);
if ($itemuri != "") { $condition = ["`uri-id` = ? AND NOT `deleted` AND NOT (`uid` IN (?, 0))", $uri_id, $item["uid"]];
$condition = ["`uri` = ? AND NOT `deleted` AND NOT (`uid` IN (?, 0))", $itemuri, $item["uid"]]; if (!Post::exists($condition)) {
if (!Post::exists($condition)) { DBA::delete('item', ['uri-id' => $uri_id, 'uid' => 0]);
DBA::delete('item', ['uri' => $itemuri, 'uid' => 0]); Logger::debug('Deleted shadow item', ['id' => $itemid, 'uri-id' => $uri_id]);
Logger::debug('Deleted shadow item', ['id' => $itemid, 'uri' => $itemuri]);
}
} }
} }
@ -3051,7 +3053,7 @@ class Item
if (($item['author-id'] == $item['owner-id']) || if (($item['author-id'] == $item['owner-id']) ||
($owner['id'] == $item['contact-id']) || ($owner['id'] == $item['contact-id']) ||
($item['uri'] != $item['parent-uri']) || ($item['uri-id'] != $item['parent-uri-id']) ||
$item['origin']) { $item['origin']) {
return false; return false;
} }
@ -3072,22 +3074,12 @@ class Item
$ssl_uri = str_replace('http://', 'https://', $uri); $ssl_uri = str_replace('http://', 'https://', $uri);
$uris = [$uri, $ssl_uri, Strings::normaliseLink($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)) { if (DBA::isResult($item)) {
return $item['id']; return $item['id'];
} }
$itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]); $item = Post::selectFirst(['id'], ['plink' => $uris, 'uid' => $uid]);
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]);
if (DBA::isResult($item)) { if (DBA::isResult($item)) {
return $item['id']; return $item['id'];
} }
@ -3107,19 +3099,14 @@ class Item
$ssl_uri = str_replace('http://', 'https://', $uri); $ssl_uri = str_replace('http://', 'https://', $uri);
$uris = [$uri, $ssl_uri, Strings::normaliseLink($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)) { if (DBA::isResult($item)) {
return $item['uri']; return $item['uri'];
} }
$itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]); $item = Post::selectFirst(['uri'], ['plink' => $uris]);
if (!DBA::isResult($itemcontent)) { if (DBA::isResult($item)) {
return ''; return $item['uri'];
}
$itemuri = DBA::selectFirst('item-uri', ['uri'], ['id' => $itemcontent['uri-id']]);
if (DBA::isResult($itemuri)) {
return $itemuri['uri'];
} }
return ''; return '';

View file

@ -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); $items = Post::toArray($r);

View file

@ -194,7 +194,7 @@ class Status extends BaseProfile
$pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network); $pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
$params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]]; $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 // Set a time stamp for this page. We will make use of it when we
// search for new items (update routine) // search for new items (update routine)
@ -228,7 +228,7 @@ class Status extends BaseProfile
$condition = []; $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); $pinned = Post::toArray($pinned_items);
$items = array_merge($items, $pinned); $items = array_merge($items, $pinned);
} }

View file

@ -4,7 +4,6 @@ namespace Friendica\Module\Update;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Module\Conversation\Network as NetworkModule; use Friendica\Module\Conversation\Network as NetworkModule;

View file

@ -78,7 +78,7 @@ class Profile extends BaseModule
} }
$items_stmt = DBA::p( $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` WHERE `uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
AND `visible` AND (NOT `deleted` OR `gravity` = ?) AND `visible` AND (NOT `deleted` OR `gravity` = ?)
AND NOT `moderated` AND `wall` $sql_extra4 $sql_extra AND NOT `moderated` AND `wall` $sql_extra4 $sql_extra

View file

@ -287,8 +287,8 @@ class Post
$responses = []; $responses = [];
foreach ($response_verbs as $value => $verb) { foreach ($response_verbs as $value => $verb) {
$responses[$verb] = [ $responses[$verb] = [
'self' => $conv_responses[$verb][$item['uri']]['self'] ?? 0, 'self' => $conv_responses[$verb][$item['uri-id']]['self'] ?? 0,
'output' => !empty($conv_responses[$verb][$item['uri']]) ? format_activity($conv_responses[$verb][$item['uri']]['links'], $verb, $item['uri']) : '', 'output' => !empty($conv_responses[$verb][$item['uri-id']]) ? format_activity($conv_responses[$verb][$item['uri-id']]['links'], $verb, $item['uri-id']) : '',
]; ];
} }

View file

@ -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. * @param boolean $conversation Show the conversation. If false show the single post.
* *
* @return string DFRN feed entry * @return string DFRN feed entry
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function itemFeed($item_id, $conversation = false) public static function itemFeed(int $uri_id, int $uid, bool $conversation = false)
{ {
if ($conversation) { if ($conversation) {
$condition = ['parent' => $item_id]; $condition = ['parent-uri-id' => $uri_id];
} else { } else {
$condition = ['id' => $item_id]; $condition = ['uri-id' => $uri_id];
} }
$condition['uid'] = $uid;
$items = Post::selectToArray(Item::DELIVER_FIELDLIST, $condition); $items = Post::selectToArray(Item::DELIVER_FIELDLIST, $condition);
if (!DBA::isResult($items)) { if (!DBA::isResult($items)) {
return ''; return '';