Merge pull request #9807 from annando/postforuser

"selectForUser" and "selectFirstForUser" is now moved to Post
This commit is contained in:
Hypolite Petovan 2021-01-16 19:02:14 -05:00 committed by GitHub
commit f5f8ea8715
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 208 additions and 143 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2021.03-dev (Red Hot Poker) -- Friendica 2021.03-dev (Red Hot Poker)
-- DB_UPDATE_VERSION 1386 -- DB_UPDATE_VERSION 1387
-- ------------------------------------------ -- ------------------------------------------
@ -1574,6 +1574,7 @@ CREATE VIEW `post-view` AS SELECT
`contact`.`avatar-date` AS `avatar-date`, `contact`.`avatar-date` AS `avatar-date`,
`contact`.`thumb` AS `thumb`, `contact`.`thumb` AS `thumb`,
`contact`.`dfrn-id` AS `dfrn-id`, `contact`.`dfrn-id` AS `dfrn-id`,
`group_member`.`gid` AS `group-id`,
`item`.`author-id` AS `author-id`, `item`.`author-id` AS `author-id`,
`author`.`url` AS `author-link`, `author`.`url` AS `author-link`,
`author`.`addr` AS `author-addr`, `author`.`addr` AS `author-addr`,
@ -1582,6 +1583,7 @@ CREATE VIEW `post-view` AS SELECT
IF (`contact`.`url` = `author`.`url`, `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`, IF (`contact`.`url` = `author`.`url`, `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`,
`author`.`network` AS `author-network`, `author`.`network` AS `author-network`,
`author`.`blocked` AS `author-blocked`, `author`.`blocked` AS `author-blocked`,
`author`.`hidden` AS `author-hidden`,
`item`.`owner-id` AS `owner-id`, `item`.`owner-id` AS `owner-id`,
`owner`.`url` AS `owner-link`, `owner`.`url` AS `owner-link`,
`owner`.`addr` AS `owner-addr`, `owner`.`addr` AS `owner-addr`,
@ -1590,6 +1592,7 @@ CREATE VIEW `post-view` AS SELECT
IF (`contact`.`url` = `owner`.`url`, `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`, IF (`contact`.`url` = `owner`.`url`, `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`,
`owner`.`network` AS `owner-network`, `owner`.`network` AS `owner-network`,
`owner`.`blocked` AS `owner-blocked`, `owner`.`blocked` AS `owner-blocked`,
`owner`.`hidden` AS `owner-hidden`,
`item`.`causer-id` AS `causer-id`, `item`.`causer-id` AS `causer-id`,
`causer`.`url` AS `causer-link`, `causer`.`url` AS `causer-link`,
`causer`.`addr` AS `causer-addr`, `causer`.`addr` AS `causer-addr`,
@ -1598,6 +1601,7 @@ CREATE VIEW `post-view` AS SELECT
`causer`.`thumb` AS `causer-avatar`, `causer`.`thumb` AS `causer-avatar`,
`causer`.`network` AS `causer-network`, `causer`.`network` AS `causer-network`,
`causer`.`blocked` AS `causer-blocked`, `causer`.`blocked` AS `causer-blocked`,
`causer`.`hidden` AS `causer-hidden`,
`causer`.`contact-type` AS `causer-contact-type`, `causer`.`contact-type` AS `causer-contact-type`,
`post-delivery-data`.`postopts` AS `postopts`, `post-delivery-data`.`postopts` AS `postopts`,
`post-delivery-data`.`inform` AS `inform`, `post-delivery-data`.`inform` AS `inform`,
@ -1632,6 +1636,7 @@ CREATE VIEW `post-view` AS SELECT
STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id` STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id`
STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id` STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id`
STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id` STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id`
LEFT JOIN `group_member` ON `group_member`.`contact-id` = `item`.`contact-id`
LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid`
LEFT JOIN `event` ON `event`.`id` = `item`.`event-id` LEFT JOIN `event` ON `event`.`id` = `item`.`event-id`
LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id` LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id`

View file

@ -1584,13 +1584,13 @@ function api_search($type)
} }
if (!empty($id)) { if (!empty($id)) {
$statuses = Item::select([], ['id' => $id]); $statuses = Post::select([], ['id' => $id]);
} }
} }
$statuses = $statuses ?: Item::selectForUser(api_user(), [], $condition, $params); $statuses = $statuses ?: Post::selectForUser(api_user(), [], $condition, $params);
$data['status'] = api_format_items(Item::inArray($statuses), $user_info); $data['status'] = api_format_items(Post::toArray($statuses), $user_info);
bindComments($data['status']); bindComments($data['status']);
@ -1644,26 +1644,26 @@ function api_statuses_home_timeline($type)
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ?", $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ?",
api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id]; api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `item`.`id` <= ?"; $condition[0] .= " AND `id` <= ?";
$condition[] = $max_id; $condition[] = $max_id;
} }
if ($exclude_replies) { if ($exclude_replies) {
$condition[0] .= ' AND `item`.`gravity` = ?'; $condition[0] .= ' AND `gravity` = ?';
$condition[] = GRAVITY_PARENT; $condition[] = GRAVITY_PARENT;
} }
if ($conversation_id > 0) { if ($conversation_id > 0) {
$condition[0] .= " AND `item`.`parent` = ?"; $condition[0] .= " AND `parent` = ?";
$condition[] = $conversation_id; $condition[] = $conversation_id;
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::selectForUser(api_user(), [], $condition, $params); $statuses = Post::selectForUser(api_user(), [], $condition, $params);
$items = Item::inArray($statuses); $items = Post::toArray($statuses);
$ret = api_format_items($items, $user_info, false, $type); $ret = api_format_items($items, $user_info, false, $type);
@ -1744,24 +1744,24 @@ function api_statuses_public_timeline($type)
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]]; $params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
$statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params); $statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$r = Item::inArray($statuses); $r = Item::toArray($statuses);
} else { } else {
$condition = ["`gravity` IN (?, ?) AND `id` > ? AND `private` = ? AND `wall` AND `item`.`origin` AND NOT `author`.`hidden`", $condition = ["`gravity` IN (?, ?) AND `id` > ? AND `private` = ? AND `wall` AND `origin` AND NOT `author-hidden`",
GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC]; GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC];
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `item`.`id` <= ?"; $condition[0] .= " AND `id` <= ?";
$condition[] = $max_id; $condition[] = $max_id;
} }
if ($conversation_id > 0) { if ($conversation_id > 0) {
$condition[0] .= " AND `item`.`parent` = ?"; $condition[0] .= " AND `parent` = ?";
$condition[] = $conversation_id; $condition[] = $conversation_id;
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::selectForUser(api_user(), [], $condition, $params); $statuses = Post::selectForUser(api_user(), [], $condition, $params);
$r = Item::inArray($statuses); $r = Post::toArray($statuses);
} }
$ret = api_format_items($r, $user_info, false, $type); $ret = api_format_items($r, $user_info, false, $type);
@ -1823,7 +1823,7 @@ function api_statuses_networkpublic_timeline($type)
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]]; $params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
$statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params); $statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type); $ret = api_format_items(Item::toArray($statuses), $user_info, false, $type);
bindComments($ret); bindComments($ret);
@ -1901,14 +1901,14 @@ function api_statuses_show($type)
$params = []; $params = [];
} }
$statuses = Item::selectForUser(api_user(), [], $condition, $params); $statuses = Post::selectForUser(api_user(), [], $condition, $params);
/// @TODO How about copying this to above methods which don't check $r ? /// @TODO How about copying this to above methods which don't check $r ?
if (!DBA::isResult($statuses)) { if (!DBA::isResult($statuses)) {
throw new BadRequestException("There is no status with this id."); throw new BadRequestException("There is no status with this id.");
} }
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type); $ret = api_format_items(Post::toArray($statuses), $user_info, false, $type);
if ($conversation) { if ($conversation) {
$data = ['status' => $ret]; $data = ['status' => $ret];
@ -1976,22 +1976,22 @@ function api_conversation_show($type)
$id = $parent['id']; $id = $parent['id'];
$condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `item`.`id` > ?", $condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `id` > ?",
$id, api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id]; $id, api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `item`.`id` <= ?"; $condition[0] .= " AND `id` <= ?";
$condition[] = $max_id; $condition[] = $max_id;
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::selectForUser(api_user(), [], $condition, $params); $statuses = Post::selectForUser(api_user(), [], $condition, $params);
if (!DBA::isResult($statuses)) { if (!DBA::isResult($statuses)) {
throw new BadRequestException("There is no status with id $id."); throw new BadRequestException("There is no status with id $id.");
} }
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type); $ret = api_format_items(Post::toArray($statuses), $user_info, false, $type);
$data = ['status' => $ret]; $data = ['status' => $ret];
return api_format_data("statuses", $type, $data); return api_format_data("statuses", $type, $data);
@ -2199,9 +2199,9 @@ function api_statuses_mentions($type)
DBA::close($useritems); DBA::close($useritems);
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::selectForUser(api_user(), [], ['id' => $itemids], $params); $statuses = Post::selectForUser(api_user(), [], ['id' => $itemids], $params);
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type); $ret = api_format_items(Post::toArray($statuses), $user_info, false, $type);
$data = ['status' => $ret]; $data = ['status' => $ret];
switch ($type) { switch ($type) {
@ -2253,32 +2253,32 @@ function api_statuses_user_timeline($type)
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `item`.`contact-id` = ?", $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `contact-id` = ?",
api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $user_info['cid']]; api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $user_info['cid']];
if ($user_info['self'] == 1) { if ($user_info['self'] == 1) {
$condition[0] .= ' AND `item`.`wall` '; $condition[0] .= ' AND `wall` ';
} }
if ($exclude_replies) { if ($exclude_replies) {
$condition[0] .= ' AND `item`.`gravity` = ?'; $condition[0] .= ' AND `gravity` = ?';
$condition[] = GRAVITY_PARENT; $condition[] = GRAVITY_PARENT;
} }
if ($conversation_id > 0) { if ($conversation_id > 0) {
$condition[0] .= " AND `item`.`parent` = ?"; $condition[0] .= " AND `parent` = ?";
$condition[] = $conversation_id; $condition[] = $conversation_id;
} }
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `item`.`id` <= ?"; $condition[0] .= " AND `id` <= ?";
$condition[] = $max_id; $condition[] = $max_id;
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::selectForUser(api_user(), [], $condition, $params); $statuses = Post::selectForUser(api_user(), [], $condition, $params);
$ret = api_format_items(Item::inArray($statuses), $user_info, true, $type); $ret = api_format_items(Post::toArray($statuses), $user_info, true, $type);
bindComments($ret); bindComments($ret);
@ -2336,7 +2336,7 @@ function api_favorites_create_destroy($type)
$itemid = intval($_REQUEST['id'] ?? 0); $itemid = intval($_REQUEST['id'] ?? 0);
} }
$item = Item::selectFirstForUser(api_user(), [], ['id' => $itemid, 'uid' => api_user()]); $item = Post::selectFirstForUser(api_user(), [], ['id' => $itemid, 'uid' => api_user()]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
throw new BadRequestException("Invalid item."); throw new BadRequestException("Invalid item.");
@ -2426,13 +2426,13 @@ function api_favorites($type)
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `item`.`id` <= ?"; $condition[0] .= " AND `id` <= ?";
$condition[] = $max_id; $condition[] = $max_id;
} }
$statuses = Item::selectForUser(api_user(), [], $condition, $params); $statuses = Post::selectForUser(api_user(), [], $condition, $params);
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type); $ret = api_format_items(Post::toArray($statuses), $user_info, false, $type);
} }
bindComments($ret); bindComments($ret);
@ -2873,7 +2873,7 @@ function api_format_items_activities($item, $type = "json")
]; ];
$condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY]; $condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY];
$ret = Item::selectForUser($item['uid'], ['author-id', 'verb'], $condition); $ret = Post::selectForUser($item['uid'], ['author-id', 'verb'], $condition);
while ($parent_item = Item::fetch($ret)) { while ($parent_item = Item::fetch($ret)) {
// not used as result should be structured like other user data // not used as result should be structured like other user data
@ -3304,26 +3304,26 @@ function api_lists_statuses($type)
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `group_member`.`gid` = ?", $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `group-id` = ?",
api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $_REQUEST['list_id']]; api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $_REQUEST['list_id']];
if ($max_id > 0) { if ($max_id > 0) {
$condition[0] .= " AND `item`.`id` <= ?"; $condition[0] .= " AND `id` <= ?";
$condition[] = $max_id; $condition[] = $max_id;
} }
if ($exclude_replies > 0) { if ($exclude_replies > 0) {
$condition[0] .= ' AND `item`.`gravity` = ?'; $condition[0] .= ' AND `gravity` = ?';
$condition[] = GRAVITY_PARENT; $condition[] = GRAVITY_PARENT;
} }
if ($conversation_id > 0) { if ($conversation_id > 0) {
$condition[0] .= " AND `item`.`parent` = ?"; $condition[0] .= " AND `parent` = ?";
$condition[] = $conversation_id; $condition[] = $conversation_id;
} }
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::selectForUser(api_user(), [], $condition, $params); $statuses = Post::selectForUser(api_user(), [], $condition, $params);
$items = api_format_items(Item::inArray($statuses), $user_info, false, $type); $items = api_format_items(Post::toArray($statuses), $user_info, false, $type);
$data = ['status' => $items]; $data = ['status' => $items];
switch ($type) { switch ($type) {
@ -4891,10 +4891,10 @@ function prepare_photo_data($type, $scale, $photo_id)
$condition = ["`parent` = ? AND `uid` = ? AND (`gravity` IN (?, ?) OR `type`='photo')", $condition = ["`parent` = ? AND `uid` = ? AND (`gravity` IN (?, ?) OR `type`='photo')",
$item['parent'], api_user(), GRAVITY_PARENT, GRAVITY_COMMENT]; $item['parent'], api_user(), GRAVITY_PARENT, GRAVITY_COMMENT];
$statuses = Item::selectForUser(api_user(), [], $condition); $statuses = Post::selectForUser(api_user(), [], $condition);
// prepare output of comments // prepare output of comments
$commentData = api_format_items(Item::inArray($statuses), $user_info, false, $type); $commentData = api_format_items(Post::toArray($statuses), $user_info, false, $type);
$comments = []; $comments = [];
if ($type == "xml") { if ($type == "xml") {
$k = 0; $k = 0;
@ -5007,7 +5007,7 @@ function api_get_announce($item)
$fields = ['author-id', 'author-name', 'author-link', 'author-avatar']; $fields = ['author-id', 'author-name', 'author-link', 'author-avatar'];
$condition = ['parent-uri' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY, 'uid' => [0, $item['uid']], 'vid' => Verb::getID(Activity::ANNOUNCE)]; $condition = ['parent-uri' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY, 'uid' => [0, $item['uid']], 'vid' => Verb::getID(Activity::ANNOUNCE)];
$announce = Item::selectFirstForUser($item['uid'], $fields, $condition, ['order' => ['received' => true]]); $announce = Post::selectFirstForUser($item['uid'], $fields, $condition, ['order' => ['received' => true]]);
if (!DBA::isResult($announce)) { if (!DBA::isResult($announce)) {
return []; return [];
} }
@ -5815,7 +5815,7 @@ function api_friendica_notification_seen($type)
DI::notify()->setSeen(true, $notify); DI::notify()->setSeen(true, $notify);
if ($notify->otype === Notify\ObjectType::ITEM) { if ($notify->otype === Notify\ObjectType::ITEM) {
$item = Item::selectFirstForUser(api_user(), [], ['id' => $notify->iid, 'uid' => api_user()]); $item = Post::selectFirstForUser(api_user(), [], ['id' => $notify->iid, 'uid' => api_user()]);
if (DBA::isResult($item)) { if (DBA::isResult($item)) {
// we found the item, return it to the user // we found the item, return it to the user
$ret = api_format_items([$item], $user_info, false, $type); $ret = api_format_items([$item], $user_info, false, $type);

View file

@ -718,7 +718,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
function conversation_fetch_comments($thread_items, bool $pinned, array $activity) { function conversation_fetch_comments($thread_items, bool $pinned, array $activity) {
$comments = []; $comments = [];
while ($row = Item::fetch($thread_items)) { while ($row = Post::fetch($thread_items)) {
if (!empty($activity)) { if (!empty($activity)) {
if (($row['gravity'] == GRAVITY_PARENT)) { if (($row['gravity'] == GRAVITY_PARENT)) {
$row['post-type'] = Item::PT_ANNOUNCEMENT; $row['post-type'] = Item::PT_ANNOUNCEMENT;
@ -827,7 +827,7 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
foreach ($parents AS $parent) { foreach ($parents AS $parent) {
if (!empty($parent['thr-parent-id']) && !empty($parent['gravity']) && ($parent['gravity'] == GRAVITY_ACTIVITY)) { if (!empty($parent['thr-parent-id']) && !empty($parent['gravity']) && ($parent['gravity'] == GRAVITY_ACTIVITY)) {
$condition = ["`item`.`parent-uri-id` = ? AND `item`.`uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)", $condition = ["`parent-uri-id` = ? AND `uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
$parent['thr-parent-id'], $uid, Verb::getID(Activity::FOLLOW)]; $parent['thr-parent-id'], $uid, Verb::getID(Activity::FOLLOW)];
if (!empty($parent['author-id'])) { if (!empty($parent['author-id'])) {
$activity = ['causer-id' => $parent['author-id']]; $activity = ['causer-id' => $parent['author-id']];
@ -838,7 +838,7 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
} }
} }
} else { } else {
$condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)", $condition = ["`parent-uri` = ? AND `uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
$parent['uri'], $uid, Verb::getID(Activity::FOLLOW)]; $parent['uri'], $uid, Verb::getID(Activity::FOLLOW)];
$activity = []; $activity = [];
} }
@ -869,10 +869,10 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
*/ */
function conversation_fetch_items(array $parent, array $items, array $condition, bool $block_authors, array $params, array $activity) { function conversation_fetch_items(array $parent, array $items, array $condition, bool $block_authors, array $params, array $activity) {
if ($block_authors) { if ($block_authors) {
$condition[0] .= " AND NOT `author`.`hidden`"; $condition[0] .= " AND NOT `author-hidden`";
} }
$thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-type']), $condition, $params); $thread_items = Post::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-type']), $condition, $params);
$comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false, $activity); $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false, $activity);

View file

@ -167,7 +167,7 @@ function notification($params)
// if it's a post figure out who's post it is. // if it's a post figure out who's post it is.
$item = null; $item = null;
if ($params['otype'] === Notify\ObjectType::ITEM && $parent_id) { if ($params['otype'] === Notify\ObjectType::ITEM && $parent_id) {
$item = Item::selectFirstForUser($params['uid'], Item::ITEM_FIELDLIST, ['id' => $parent_id, 'deleted' => false]); $item = Post::selectFirstForUser($params['uid'], Item::ITEM_FIELDLIST, ['id' => $parent_id, 'deleted' => false]);
} }
if (empty($item)) { if (empty($item)) {
@ -619,7 +619,7 @@ function check_item_notification($itemid, $uid, $notification_type) {
'title', 'body', 'author-link', 'author-name', 'author-avatar', 'author-id', 'title', 'body', 'author-link', 'author-name', 'author-avatar', 'author-id',
'gravity', 'guid', 'parent-uri', 'uri', 'contact-id', 'network']; 'gravity', 'guid', 'parent-uri', 'uri', 'contact-id', 'network'];
$condition = ['id' => $itemid, 'deleted' => false]; $condition = ['id' => $itemid, 'deleted' => false];
$item = Item::selectFirstForUser($uid, $fields, $condition); $item = Post::selectFirstForUser($uid, $fields, $condition);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
return false; return false;
} }

View file

@ -63,7 +63,7 @@ function display_init(App $a)
// Does the local user have this item? // Does the local user have this item?
if (local_user()) { if (local_user()) {
$item = Item::selectFirstForUser(local_user(), $fields, ['guid' => $a->argv[1], 'uid' => local_user()]); $item = Post::selectFirstForUser(local_user(), $fields, ['guid' => $a->argv[1], 'uid' => local_user()]);
if (DBA::isResult($item)) { if (DBA::isResult($item)) {
$nick = $a->user["nickname"]; $nick = $a->user["nickname"];
} }
@ -83,14 +83,14 @@ function display_init(App $a)
// Is it an item with uid=0? // Is it an item with uid=0?
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
$item = Item::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]; $item_id = $a->argv[2];
if (substr($item_id, -5) == '.atom') { if (substr($item_id, -5) == '.atom') {
$item_id = substr($item_id, 0, -5); $item_id = substr($item_id, 0, -5);
} }
$item = Item::selectFirstForUser(local_user(), $fields, ['id' => $item_id, 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]); $item = Post::selectFirstForUser(local_user(), $fields, ['id' => $item_id, 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]);
} }
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
@ -107,7 +107,7 @@ function display_init(App $a)
} }
if ($item['gravity'] != GRAVITY_PARENT) { if ($item['gravity'] != GRAVITY_PARENT) {
$parent = Item::selectFirstForUser($item_user, $fields, ['id' => $item['parent']]); $parent = Post::selectFirstForUser($item_user, $fields, ['id' => $item['parent']]);
$item = $parent ?: $item; $item = $parent ?: $item;
} }
@ -206,7 +206,7 @@ function display_content(App $a, $update = false, $update_uid = 0)
if (local_user()) { if (local_user()) {
$condition = ['guid' => $a->argv[1], 'uid' => local_user()]; $condition = ['guid' => $a->argv[1], 'uid' => local_user()];
$item = Item::selectFirstForUser(local_user(), $fields, $condition); $item = Post::selectFirstForUser(local_user(), $fields, $condition);
if (DBA::isResult($item)) { if (DBA::isResult($item)) {
$item_id = $item['id']; $item_id = $item['id'];
$item_parent = $item['parent']; $item_parent = $item['parent'];
@ -225,7 +225,7 @@ function display_content(App $a, $update = false, $update_uid = 0)
if ($item_parent == 0) { if ($item_parent == 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 = Item::selectFirstForUser(local_user(), $fields, $condition); $item = Post::selectFirstForUser(local_user(), $fields, $condition);
if (DBA::isResult($item)) { if (DBA::isResult($item)) {
$item_id = $item['id']; $item_id = $item['id'];
$item_parent = $item['parent']; $item_parent = $item['parent'];
@ -315,9 +315,9 @@ function display_content(App $a, $update = false, $update_uid = 0)
return ''; return '';
} }
$condition = ["`id` = ? AND `item`.`uid` IN (0, ?) " . $sql_extra, $item_id, $item_uid]; $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']; $fields = ['parent-uri', 'body', 'title', 'author-name', 'author-avatar', 'plink', 'author-id', 'owner-id', 'contact-id'];
$item = Item::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.'));

View file

@ -28,6 +28,7 @@ use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\FileTag; use Friendica\Model\FileTag;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
function editpost_content(App $a) function editpost_content(App $a)
@ -49,7 +50,7 @@ function editpost_content(App $a)
$fields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', $fields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'type', 'body', 'title', 'file', 'wall', 'post-type', 'guid']; 'type', 'body', 'title', 'file', 'wall', 'post-type', 'guid'];
$item = Item::selectFirstForUser(local_user(), $fields, ['id' => $post_id, 'uid' => local_user()]); $item = Post::selectFirstForUser(local_user(), $fields, ['id' => $post_id, 'uid' => local_user()]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
notice(DI::l10n()->t('Item not found')); notice(DI::l10n()->t('Item not found'));

View file

@ -861,7 +861,7 @@ function drop_item(int $id, string $return = '')
{ {
// locate item to be deleted // locate item to be deleted
$fields = ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent']; $fields = ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent'];
$item = Item::selectFirstForUser(local_user(), $fields, ['id' => $id]); $item = Post::selectFirstForUser(local_user(), $fields, ['id' => $id]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
notice(DI::l10n()->t('Item not found.')); notice(DI::l10n()->t('Item not found.'));
@ -881,7 +881,7 @@ function drop_item(int $id, string $return = '')
if ((local_user() == $item['uid']) || $contact_id) { if ((local_user() == $item['uid']) || $contact_id) {
if (!empty($item['parent'])) { if (!empty($item['parent'])) {
$parentitem = Item::selectFirstForUser(local_user(), ['guid'], ['id' => $item['parent']]); $parentitem = Post::selectFirstForUser(local_user(), ['guid'], ['id' => $item['parent']]);
} }
// delete the item // delete the item

View file

@ -86,7 +86,7 @@ function notes_content(App $a, $update = false)
$count = 0; $count = 0;
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
$notes = Item::inArray($r); $notes = Item::toArray($r);
$count = count($notes); $count = count($notes);

View file

@ -1276,13 +1276,12 @@ function photos_content(App $a)
if (!empty($link_item['parent']) && !empty($link_item['uid'])) { if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
$condition = ["`parent` = ? AND `gravity` != ?", $link_item['parent'], GRAVITY_PARENT]; $condition = ["`parent` = ? AND `gravity` != ?", $link_item['parent'], GRAVITY_PARENT];
$total = DBA::count('item', $condition); $total = Post::count($condition);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString()); $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
$result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params); $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
$items = Item::inArray($result);
if (local_user() == $link_item['uid']) { if (local_user() == $link_item['uid']) {
Item::update(['unseen' => false], ['parent' => $link_item['parent']]); Item::update(['unseen' => false], ['parent' => $link_item['parent']]);

View file

@ -28,8 +28,8 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Notify\Type; use Friendica\Model\Notify\Type;
use Friendica\Model\Post;
use Friendica\Model\Verb; use Friendica\Model\Verb;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -137,9 +137,9 @@ function ping_init(App $a)
$condition = ["`unseen` AND `uid` = ? AND NOT `origin` AND (`vid` != ? OR `vid` IS NULL)", $condition = ["`unseen` AND `uid` = ? AND NOT `origin` AND (`vid` != ? OR `vid` IS NULL)",
local_user(), Verb::getID(Activity::FOLLOW)]; local_user(), Verb::getID(Activity::FOLLOW)];
$items = Item::selectForUser(local_user(), ['wall', 'uid', 'uri-id'], $condition); $items = Post::selectForUser(local_user(), ['wall', 'uid', 'uri-id'], $condition);
if (DBA::isResult($items)) { if (DBA::isResult($items)) {
$items_unseen = Item::inArray($items); $items_unseen = Post::toArray($items);
$arr = ['items' => $items_unseen]; $arr = ['items' => $items_unseen];
Hook::callAll('network_ping', $arr); Hook::callAll('network_ping', $arr);

View file

@ -69,14 +69,14 @@ class Status extends BaseFactory
$account = DI::mstdnAccount()->createFromContactId($item['author-id']); $account = DI::mstdnAccount()->createFromContactId($item['author-id']);
$counts = new \Friendica\Object\Api\Mastodon\Status\Counts( $counts = new \Friendica\Object\Api\Mastodon\Status\Counts(
DBA::count('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_COMMENT]), Post::count(['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_COMMENT]),
DBA::count('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)]), Post::count(['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)]),
DBA::count('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)]) Post::count(['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)])
); );
$userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes( $userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes(
DBA::exists('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)]), Post::exists(['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)]),
DBA::exists('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)]), Post::exists(['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)]),
DBA::exists('thread', ['iid' => $item['id'], 'uid' => $item['uid'], 'ignored' => true]), DBA::exists('thread', ['iid' => $item['id'], 'uid' => $item['uid'], 'ignored' => true]),
(bool)$item['starred'], (bool)$item['starred'],
DBA::exists('user-item', ['iid' => $item['id'], 'uid' => $item['uid'], 'pinned' => true]) DBA::exists('user-item', ['iid' => $item['id'], 'uid' => $item['uid'], 'pinned' => true])

View file

@ -32,7 +32,7 @@ use Friendica\Core\PConfig\IPConfig;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Session\ISession; use Friendica\Core\Session\ISession;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Model\Item; use Friendica\Model\Post;
use Friendica\Module\BaseNotifications; use Friendica\Module\BaseNotifications;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Object\Api\Friendica\Notification as ApiNotification; use Friendica\Object\Api\Friendica\Notification as ApiNotification;
@ -278,7 +278,7 @@ class Notification extends BaseFactory
$formattedNotifications = []; $formattedNotifications = [];
try { try {
$items = Item::selectForUser(local_user(), $fields, $conditions, $params); $items = Post::selectForUser(local_user(), $fields, $conditions, $params);
while ($item = $this->dba->fetch($items)) { while ($item = $this->dba->fetch($items)) {
$formattedNotifications[] = $this->createFromItem($item); $formattedNotifications[] = $this->createFromItem($item);
@ -319,7 +319,7 @@ class Notification extends BaseFactory
$formattedNotifications = []; $formattedNotifications = [];
try { try {
$items = Item::selectForUser(local_user(), $fields, $condition, $params); $items = Post::selectForUser(local_user(), $fields, $condition, $params);
while ($item = $this->dba->fetch($items)) { while ($item = $this->dba->fetch($items)) {
$formattedNotifications[] = $this->createFromItem($item); $formattedNotifications[] = $this->createFromItem($item);
@ -356,7 +356,7 @@ class Notification extends BaseFactory
$formattedNotifications = []; $formattedNotifications = [];
try { try {
$items = Item::selectForUser(local_user(), $fields, $condition, $params); $items = Post::selectForUser(local_user(), $fields, $condition, $params);
while ($item = $this->dba->fetch($items)) { while ($item = $this->dba->fetch($items)) {
$item = $this->formatItem($item); $item = $this->formatItem($item);

View file

@ -1296,9 +1296,9 @@ class Contact
} }
if (empty($contact["network"]) || in_array($contact["network"], Protocol::FEDERATED)) { if (empty($contact["network"]) || in_array($contact["network"], Protocol::FEDERATED)) {
$sql = "(`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))"; $sql = "(`uid` = 0 OR (`uid` = ? AND NOT `global`))";
} else { } else {
$sql = "`item`.`uid` = ?"; $sql = "`uid` = ?";
} }
$contact_field = ((($contact["contact-type"] == self::TYPE_COMMUNITY) || ($contact['network'] == Protocol::MAIL)) ? 'owner-id' : 'author-id'); $contact_field = ((($contact["contact-type"] == self::TYPE_COMMUNITY) || ($contact['network'] == Protocol::MAIL)) ? 'owner-id' : 'author-id');
@ -1340,18 +1340,11 @@ class Contact
} }
if ($thread_mode) { if ($thread_mode) {
$r = Item::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri', 'thr-parent-id', 'author-id'], $condition, $params); $items = Post::toArray(Post::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri', 'thr-parent-id', 'author-id'], $condition, $params));
$items = [];
while ($item = DBA::fetch($r)) {
$items[] = $item;
}
DBA::close($r);
$o .= conversation($a, $items, 'contacts', $update, false, 'commented', local_user()); $o .= conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
} else { } else {
$r = Item::selectForUser(local_user(), [], $condition, $params); $items = Post::toArray(Post::selectForUser(local_user(), [], $condition, $params));
$items = Item::inArray($r);
$o .= conversation($a, $items, 'contact-posts', $update); $o .= conversation($a, $items, 'contact-posts', $update);
} }

View file

@ -353,7 +353,7 @@ class Item
* @param bool $do_close * @param bool $do_close
* @return array Data array * @return array Data array
*/ */
public static function inArray($stmt, $do_close = true) { public static function toArray($stmt, $do_close = true) {
if (is_bool($stmt)) { if (is_bool($stmt)) {
return $stmt; return $stmt;
} }
@ -390,28 +390,6 @@ class Item
return $retval; return $retval;
} }
/**
* Retrieve a single record from the item table for a given user and returns it in an associative array
*
* @param integer $uid User ID
* @param array $selected
* @param array $condition
* @param array $params
* @return bool|array
* @throws \Exception
* @see DBA::select
*/
public static function selectFirstForUser($uid, array $selected = [], array $condition = [], $params = [])
{
$params['uid'] = $uid;
if (empty($selected)) {
$selected = self::DISPLAY_FIELDLIST;
}
return self::selectFirst($selected, $condition, $params);
}
/** /**
* Select rows from the item table for a given user * Select rows from the item table for a given user
* *
@ -1518,7 +1496,7 @@ class Item
'wall', 'private', 'forum_mode', 'origin', 'author-id']; 'wall', 'private', 'forum_mode', 'origin', 'author-id'];
$condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid']]; $condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid']];
$params = ['order' => ['id' => false]]; $params = ['order' => ['id' => false]];
$parent = self::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' => $item['thr-parent'], 'uid' => $item['uid']]);
@ -1533,7 +1511,7 @@ class Item
'parent-uri' => $parent['parent-uri'], 'parent-uri' => $parent['parent-uri'],
'uid' => $parent['uid']]; 'uid' => $parent['uid']];
$params = ['order' => ['id' => false]]; $params = ['order' => ['id' => false]];
$toplevel_parent = self::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' => $parent['parent-uri'], 'uid' => $parent['uid']]);
return []; return [];
@ -2019,7 +1997,7 @@ class Item
$transmit = $notify || ($item['visible'] && ($parent_origin || $item['origin'])); $transmit = $notify || ($item['visible'] && ($parent_origin || $item['origin']));
if ($transmit) { if ($transmit) {
$transmit_item = self::selectFirst(['verb', 'origin'], ['id' => $item['id']]); $transmit_item = Post::selectFirst(['verb', 'origin'], ['id' => $item['id']]);
// Don't relay participation messages // Don't relay participation messages
if (($transmit_item['verb'] == Activity::FOLLOW) && if (($transmit_item['verb'] == Activity::FOLLOW) &&
(!$transmit_item['origin'] || ($item['author-id'] != Contact::getPublicIdByUserId($uid)))) { (!$transmit_item['origin'] || ($item['author-id'] != Contact::getPublicIdByUserId($uid)))) {
@ -3492,7 +3470,7 @@ class Item
* *
* default permissions - anonymous user * default permissions - anonymous user
*/ */
$sql = sprintf(" AND `item`.`private` != %d", self::PRIVATE); $sql = sprintf(" AND `private` != %d", self::PRIVATE);
// Profile owner - everything is visible // Profile owner - everything is visible
if ($local_user && ($local_user == $owner_id)) { if ($local_user && ($local_user == $owner_id)) {
@ -3508,12 +3486,12 @@ class Item
$set = PermissionSet::get($owner_id, $remote_user); $set = PermissionSet::get($owner_id, $remote_user);
if (!empty($set)) { if (!empty($set)) {
$sql_set = sprintf(" OR (`item`.`private` = %d AND `item`.`wall` AND `item`.`psid` IN (", self::PRIVATE) . implode(',', $set) . "))"; $sql_set = sprintf(" OR (`private` = %d AND `wall` AND `psid` IN (", self::PRIVATE) . implode(',', $set) . "))";
} else { } else {
$sql_set = ''; $sql_set = '';
} }
$sql = sprintf(" AND (`item`.`private` != %d", self::PRIVATE) . $sql_set . ")"; $sql = sprintf(" AND (`private` != %d", self::PRIVATE) . $sql_set . ")";
} }
return $sql; return $sql;

View file

@ -56,7 +56,7 @@ class ItemContent
'limit' => [$start, $limit] 'limit' => [$start, $limit]
]; ];
$tags = DBA::select('item', ['uri-id'], $condition, $params); $tags = Post::select(['uri-id'], $condition, $params);
$uriids = []; $uriids = [];
while ($tag = DBA::fetch($tags)) { while ($tag = DBA::fetch($tags)) {
@ -73,7 +73,7 @@ class ItemContent
AND (NOT `private` OR (`private` AND `uid` = ?)) AND (NOT `private` OR (`private` AND `uid` = ?))
AND `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `network` IN (?, ?, ?, ?))", AND `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `network` IN (?, ?, ?, ?))",
$search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; $search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
return DBA::count('item', $condition); return Post::count($condition);
} }
/** /**

View file

@ -89,7 +89,7 @@ class Post
* @param bool $do_close * @param bool $do_close
* @return array Data array * @return array Data array
*/ */
public static function inArray($stmt, $do_close = true) { public static function toArray($stmt, $do_close = true) {
if (is_bool($stmt)) { if (is_bool($stmt)) {
return $stmt; return $stmt;
} }
@ -213,4 +213,83 @@ class Post
return DBA::select('post-view', $selected, $condition, $params); return DBA::select('post-view', $selected, $condition, $params);
} }
/**
* Select rows from the post view for a given user
*
* @param integer $uid User ID
* @param array $selected Array of selected fields, empty for all
* @param array $condition Array of fields for condition
* @param array $params Array of several parameters
*
* @return boolean|object
* @throws \Exception
*/
public static function selectForUser($uid, array $selected = [], array $condition = [], $params = [])
{
if (empty($selected)) {
$selected = Item::DISPLAY_FIELDLIST;
}
$selected = array_unique(array_merge($selected, ['internal-uri-id', 'internal-uid', 'internal-file-count']));
$condition = DBA::mergeConditions($condition,
["`visible` AND NOT `deleted` AND NOT `moderated`
AND NOT `author-blocked` AND NOT `owner-blocked`
AND (NOT `causer-blocked` OR `causer-id` = ?) AND NOT `contact-blocked`
AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
OR `self` OR `gravity` != ? OR `contact-uid` = ?)
AND NOT EXISTS (SELECT `iid` FROM `user-item` WHERE `hidden` AND `iid` = `id` AND `uid` = ?)
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `author-id` AND `blocked`)
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `owner-id` AND `blocked`)
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `author-id` AND `ignored` AND `gravity` = ?)
AND NOT EXISTS (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `owner-id` AND `ignored` AND `gravity` = ?)",
0, Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, 0, $uid, $uid, $uid, $uid, GRAVITY_PARENT, $uid, GRAVITY_PARENT]);
$select_string = '';
if (in_array('pinned', $selected)) {
$selected = array_flip($selected);
unset($selected['pinned']);
$selected = array_flip($selected);
$select_string = '(SELECT `pinned` FROM `user-item` WHERE `iid` = `post-view`.`id` AND uid=`post-view`.`uid`) AS `pinned`, ';
}
$select_string .= implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));
$condition_string = DBA::buildCondition($condition);
$param_string = DBA::buildParameter($params);
$sql = "SELECT " . $select_string . " FROM `post-view` " . $condition_string . $param_string;
$sql = DBA::cleanQuery($sql);
return DBA::p($sql, $condition);
}
/**
* Retrieve a single record from the post view for a given user and returns it in an associative array
*
* @param integer $uid User ID
* @param array $selected
* @param array $condition
* @param array $params
* @return bool|array
* @throws \Exception
* @see DBA::select
*/
public static function selectFirstForUser($uid, array $selected = [], array $condition = [], $params = [])
{
$params['limit'] = 1;
$result = self::selectForUser($uid, $selected, $condition, $params);
if (is_bool($result)) {
return $result;
} else {
$row = self::fetch($result);
DBA::close($result);
return $row;
}
}
} }

View file

@ -26,6 +26,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Verb; use Friendica\Model\Verb;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -82,10 +83,10 @@ class Statuses extends BaseApi
$params['order'] = ['uri-id']; $params['order'] = ['uri-id'];
} }
$items = Item::selectForUser(0, ['uri-id', 'uid'], $condition, $params); $items = Post::selectForUser(0, ['uri-id', 'uid'], $condition, $params);
$statuses = []; $statuses = [];
while ($item = Item::fetch($items)) { while ($item = Post::fetch($items)) {
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $item['uid']); $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $item['uid']);
} }
DBA::close($items); DBA::close($items);

View file

@ -26,6 +26,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -81,7 +82,7 @@ class PublicTimeline extends BaseApi
$params['order'] = ['uri-id']; $params['order'] = ['uri-id'];
} }
$items = Item::selectForUser(0, ['uri-id', 'uid'], $condition, $params); $items = Post::selectForUser(0, ['uri-id', 'uid'], $condition, $params);
$statuses = []; $statuses = [];
while ($item = Item::fetch($items)) { while ($item = Item::fetch($items)) {

View file

@ -183,7 +183,7 @@ class Status extends BaseProfile
(`gravity` = ? AND `vid` = ? AND `origin` AND `thr-parent-id` IN (`gravity` = ? AND `vid` = ? AND `origin` AND `thr-parent-id` IN
(SELECT `uri-id` FROM `item` AS `i` (SELECT `uri-id` FROM `item` AS `i`
WHERE `gravity` = ? AND `network` IN (?, ?, ?, ?) AND `uid` IN (?, ?) WHERE `gravity` = ? AND `network` IN (?, ?, ?, ?) AND `uid` IN (?, ?)
AND `i`.`uri-id` = `item`.`thr-parent-id`)))", AND `i`.`uri-id` = `thr-parent-id`)))",
GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT, GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT,
Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::OSTATUS,
0, $a->profile['uid']]); 0, $a->profile['uid']]);
@ -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 = DBA::select('item', ['uri', 'thr-parent-id', 'gravity', 'author-id', 'received'], $condition, $params); $items_stmt = Post::select(['uri', '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)
@ -213,7 +213,7 @@ class Status extends BaseProfile
} }
} }
$items = DBA::toArray($items_stmt); $items = Post::toArray($items_stmt);
if ($pager->getStart() == 0 && !empty($a->profile['uid'])) { if ($pager->getStart() == 0 && !empty($a->profile['uid'])) {
$condition = ['private' => [Item::PUBLIC, Item::UNLISTED]]; $condition = ['private' => [Item::PUBLIC, Item::UNLISTED]];
@ -229,7 +229,7 @@ class Status extends BaseProfile
} }
$pinned_items = Item::selectPinned($a->profile['uid'], ['uri', 'pinned'], $condition); $pinned_items = Item::selectPinned($a->profile['uid'], ['uri', 'pinned'], $condition);
$pinned = Item::inArray($pinned_items); $pinned = Item::toArray($pinned_items);
$items = array_merge($items, $pinned); $items = array_merge($items, $pinned);
} }

View file

@ -332,9 +332,9 @@ class Acl extends BaseModule
$condition = ["`parent` = ?", $conv_id]; $condition = ["`parent` = ?", $conv_id];
$params = ['order' => ['author-name' => true]]; $params = ['order' => ['author-name' => true]];
$authors = Item::selectForUser(local_user(), ['author-link'], $condition, $params); $authors = Post::selectForUser(local_user(), ['author-link'], $condition, $params);
$item_authors = []; $item_authors = [];
while ($author = Item::fetch($authors)) { while ($author = Post::fetch($authors)) {
$item_authors[$author['author-link']] = $author['author-link']; $item_authors[$author['author-link']] = $author['author-link'];
} }
DBA::close($authors); DBA::close($authors);

View file

@ -9,7 +9,7 @@ use Friendica\Content\Widget;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Post;
use Friendica\Model\Post\Category; use Friendica\Model\Post\Category;
use Friendica\Module\BaseSearch; use Friendica\Module\BaseSearch;
use Friendica\Module\Security\Login; use Friendica\Module\Security\Login;
@ -69,8 +69,7 @@ class Filed extends BaseSearch
$item_condition = ['uid' => local_user(), 'uri-id' => $posts]; $item_condition = ['uid' => local_user(), 'uri-id' => $posts];
$item_params = ['order' => ['uri-id' => true]]; $item_params = ['order' => ['uri-id' => true]];
$result = Item::selectForUser(local_user(), [], $item_condition, $item_params); $items = Post::toArray(Post::selectForUser(local_user(), [], $item_condition, $item_params));
$items = Item::inArray($result);
$o .= conversation(DI::app(), $items, 'filed', false, false, '', local_user()); $o .= conversation(DI::app(), $items, 'filed', false, false, '', local_user());

View file

@ -172,7 +172,7 @@ class Index extends BaseSearch
if (!empty($uriids)) { if (!empty($uriids)) {
$params = ['order' => ['id' => true], 'group_by' => ['uri-id']]; $params = ['order' => ['id' => true], 'group_by' => ['uri-id']];
$items = Item::inArray(Item::selectForUser(local_user(), [], ['uri-id' => $uriids], $params)); $items = Post::toArray(Post::selectForUser(local_user(), [], ['uri-id' => $uriids], $params));
} }
if (empty($items)) { if (empty($items)) {

View file

@ -24,6 +24,7 @@ namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post;
/** /**
* Toggle starred items * Toggle starred items
@ -42,7 +43,7 @@ class Starred extends BaseModule
$itemId = intval($parameters['item']); $itemId = intval($parameters['item']);
$item = Item::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $itemId]); $item = Post::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $itemId]);
if (empty($item)) { if (empty($item)) {
throw new \Friendica\Network\HTTPException\NotFoundException(); throw new \Friendica\Network\HTTPException\NotFoundException();
} }

View file

@ -260,7 +260,7 @@ class Transmitter
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
'deleted' => false, 'visible' => true, 'moderated' => false]); 'deleted' => false, 'visible' => true, 'moderated' => false]);
$count = DBA::count('item', $condition); $count = Post::count($condition);
$data = ['@context' => ActivityPub::CONTEXT]; $data = ['@context' => ActivityPub::CONTEXT];
$data['id'] = DI::baseUrl() . '/outbox/' . $owner['nickname']; $data['id'] = DI::baseUrl() . '/outbox/' . $owner['nickname'];

View file

@ -892,7 +892,7 @@ class Feed
$ret = Item::select([], $condition, $params); $ret = Item::select([], $condition, $params);
} }
$items = Item::inArray($ret); $items = Item::toArray($ret);
$doc = new DOMDocument('1.0', 'utf-8'); $doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true; $doc->formatOutput = true;

View file

@ -2129,7 +2129,7 @@ class OStatus
$ret = Item::select([], $condition, $params); $ret = Item::select([], $condition, $params);
} }
$items = Item::inArray($ret); $items = Item::toArray($ret);
$doc = new DOMDocument('1.0', 'utf-8'); $doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true; $doc->formatOutput = true;

View file

@ -125,7 +125,7 @@ class Notifier
return; return;
} }
$items = Post::inArray($items_stmt); $items = Post::toArray($items_stmt);
// avoid race condition with deleting entries // avoid race condition with deleting entries
if ($items[0]['deleted']) { if ($items[0]['deleted']) {

View file

@ -55,7 +55,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1386); define('DB_UPDATE_VERSION', 1387);
} }
return [ return [

View file

@ -120,6 +120,7 @@
"avatar-date" => ["contact", "avatar-date"], "avatar-date" => ["contact", "avatar-date"],
"thumb" => ["contact", "thumb"], "thumb" => ["contact", "thumb"],
"dfrn-id" => ["contact", "dfrn-id"], "dfrn-id" => ["contact", "dfrn-id"],
"group-id" => ["group_member", "gid"],
"author-id" => ["item", "author-id"], "author-id" => ["item", "author-id"],
"author-link" => ["author", "url"], "author-link" => ["author", "url"],
"author-addr" => ["author", "addr"], "author-addr" => ["author", "addr"],
@ -128,6 +129,7 @@
"author-avatar" => "IF (`contact`.`url` = `author`.`url`, `contact`.`thumb`, `author`.`thumb`)", "author-avatar" => "IF (`contact`.`url` = `author`.`url`, `contact`.`thumb`, `author`.`thumb`)",
"author-network" => ["author", "network"], "author-network" => ["author", "network"],
"author-blocked" => ["author", "blocked"], "author-blocked" => ["author", "blocked"],
"author-hidden" => ["author", "hidden"],
"owner-id" => ["item", "owner-id"], "owner-id" => ["item", "owner-id"],
"owner-link" => ["owner", "url"], "owner-link" => ["owner", "url"],
"owner-addr" => ["owner", "addr"], "owner-addr" => ["owner", "addr"],
@ -136,6 +138,7 @@
"owner-avatar" => "IF (`contact`.`url` = `owner`.`url`, `contact`.`thumb`, `owner`.`thumb`)", "owner-avatar" => "IF (`contact`.`url` = `owner`.`url`, `contact`.`thumb`, `owner`.`thumb`)",
"owner-network" => ["owner", "network"], "owner-network" => ["owner", "network"],
"owner-blocked" => ["owner", "blocked"], "owner-blocked" => ["owner", "blocked"],
"owner-hidden" => ["owner", "hidden"],
"causer-id" => ["item", "causer-id"], "causer-id" => ["item", "causer-id"],
"causer-link" => ["causer", "url"], "causer-link" => ["causer", "url"],
"causer-addr" => ["causer", "addr"], "causer-addr" => ["causer", "addr"],
@ -144,6 +147,7 @@
"causer-avatar" => ["causer", "thumb"], "causer-avatar" => ["causer", "thumb"],
"causer-network" => ["causer", "network"], "causer-network" => ["causer", "network"],
"causer-blocked" => ["causer", "blocked"], "causer-blocked" => ["causer", "blocked"],
"causer-hidden" => ["causer", "hidden"],
"causer-contact-type" => ["causer", "contact-type"], "causer-contact-type" => ["causer", "contact-type"],
"postopts" => ["post-delivery-data", "postopts"], "postopts" => ["post-delivery-data", "postopts"],
"inform" => ["post-delivery-data", "inform"], "inform" => ["post-delivery-data", "inform"],
@ -179,6 +183,7 @@
STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id` STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id`
STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id` STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id`
STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id` STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id`
LEFT JOIN `group_member` ON `group_member`.`contact-id` = `item`.`contact-id`
LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid`
LEFT JOIN `event` ON `event`.`id` = `item`.`event-id` LEFT JOIN `event` ON `event`.`id` = `item`.`event-id`
LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id` LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id`

View file

@ -12,6 +12,7 @@ return [
'password' => 'testpw', 'password' => 'testpw',
'database' => 'testdb', 'database' => 'testdb',
'charset' => 'utf8mb4', 'charset' => 'utf8mb4',
'pdo_emulate_prepares' => true,
], ],
'config' => [ 'config' => [

View file

@ -12,6 +12,7 @@ return [
'password' => 'testpw', 'password' => 'testpw',
'database' => 'testdb', 'database' => 'testdb',
'charset' => 'utf8mb4', 'charset' => 'utf8mb4',
'pdo_emulate_prepares' => true,
], ],
'config' => [ 'config' => [

View file

@ -447,6 +447,7 @@ return [
'password' => '{$conf('database', 'password')}', 'password' => '{$conf('database', 'password')}',
'database' => '{$conf('database', 'database')}', 'database' => '{$conf('database', 'database')}',
'charset' => 'utf8mb4', 'charset' => 'utf8mb4',
'pdo_emulate_prepares' => true,
], ],
// **************************************************************** // ****************************************************************