X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fapi.php;h=115869fe27baeb96ba65138e868e62a23cb7433f;hb=3e2fa7867c20a7b2abaf2f1c4f9c452654c0fbab;hp=4aa4b21e29199e4a0c339cb884d94b251f2062fd;hpb=73ca1096ecc9d8b26cc0f768e81477b7b3e6fe0d;p=friendica.git diff --git a/include/api.php b/include/api.php index 4aa4b21e29..115869fe27 100644 --- a/include/api.php +++ b/include/api.php @@ -1,6 +1,6 @@ 0) { $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60); - $condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom]; - $posts_day = DBA::count('thread', $condition); + $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, api_user(), $datefrom]; + $posts_day = Post::count($condition); if ($posts_day > $throttle_day) { Logger::log('Daily posting limit reached for user '.api_user(), Logger::DEBUG); @@ -1134,8 +1132,8 @@ function api_statuses_update($type) if ($throttle_week > 0) { $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7); - $condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom]; - $posts_week = DBA::count('thread', $condition); + $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, api_user(), $datefrom]; + $posts_week = Post::count($condition); if ($posts_week > $throttle_week) { Logger::log('Weekly posting limit reached for user '.api_user(), Logger::DEBUG); @@ -1148,8 +1146,8 @@ function api_statuses_update($type) if ($throttle_month > 0) { $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30); - $condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom]; - $posts_month = DBA::count('thread', $condition); + $condition = ["`gravity` = ? AND `uid` = ? AND `wall` AND `received` > ?", GRAVITY_PARENT, api_user(), $datefrom]; + $posts_month = Post::count($condition); if ($posts_month > $throttle_month) { Logger::log('Monthly posting limit reached for user '.api_user(), Logger::DEBUG); @@ -1733,18 +1731,18 @@ function api_statuses_public_timeline($type) $start = max(0, ($page - 1) * $count); if ($exclude_replies && !$conversation_id) { - $condition = ["`gravity` IN (?, ?) AND `iid` > ? AND `private` = ? AND `wall` AND NOT `author`.`hidden`", - GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC]; + $condition = ["`gravity` = ? AND `id` > ? AND `private` = ? AND `wall` AND NOT `author-hidden`", + GRAVITY_PARENT, $since_id, Item::PUBLIC]; if ($max_id > 0) { - $condition[0] .= " AND `thread`.`iid` <= ?"; + $condition[0] .= " AND `id` <= ?"; $condition[] = $max_id; } - $params = ['order' => ['iid' => true], 'limit' => [$start, $count]]; - $statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params); + $params = ['order' => ['id' => true], 'limit' => [$start, $count]]; + $statuses = Post::selectForUser(api_user(), [], $condition, $params); - $r = Item::toArray($statuses); + $r = Post::toArray($statuses); } else { $condition = ["`gravity` IN (?, ?) AND `id` > ? AND `private` = ? AND `wall` AND `origin` AND NOT `author-hidden`", GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC]; @@ -1812,18 +1810,18 @@ function api_statuses_networkpublic_timeline($type) $start = max(0, ($page - 1) * $count); - $condition = ["`uid` = 0 AND `gravity` IN (?, ?) AND `thread`.`iid` > ? AND `private` = ?", + $condition = ["`uid` = 0 AND `gravity` IN (?, ?) AND `id` > ? AND `private` = ?", GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC]; if ($max_id > 0) { - $condition[0] .= " AND `thread`.`iid` <= ?"; + $condition[0] .= " AND `id` <= ?"; $condition[] = $max_id; } - $params = ['order' => ['iid' => true], 'limit' => [$start, $count]]; - $statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params); + $params = ['order' => ['id' => true], 'limit' => [$start, $count]]; + $statuses = Post::toArray(Post::selectForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params)); - $ret = api_format_items(Item::toArray($statuses), $user_info, false, $type); + $ret = api_format_items($statuses, $user_info, false, $type); bindComments($ret); @@ -2171,24 +2169,21 @@ function api_statuses_mentions($type) $start = max(0, ($page - 1) * $count); - $query = "`gravity` IN (?, ?) AND `id` IN (SELECT `iid` FROM `user-item` - WHERE (`hidden` IS NULL OR NOT `hidden`) AND - `uid` = ? AND `notification-type` & ? != 0 - AND `iid` > ?"; + $query = "`gravity` IN (?, ?) AND `uri-id` IN + (SELECT `uri-id` FROM `post-user-notification` WHERE `uid` = ? AND `notification-type` & ? != 0 ORDER BY `uri-id`) + AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `id` > ?"; $condition = [GRAVITY_PARENT, GRAVITY_COMMENT, api_user(), - UserItem::NOTIF_EXPLICIT_TAGGED | UserItem::NOTIF_IMPLICIT_TAGGED | - UserItem::NOTIF_THREAD_COMMENT | UserItem::NOTIF_DIRECT_COMMENT | - UserItem::NOTIF_DIRECT_THREAD_COMMENT, - $since_id]; + Post\UserNotification::NOTIF_EXPLICIT_TAGGED | Post\UserNotification::NOTIF_IMPLICIT_TAGGED | + Post\UserNotification::NOTIF_THREAD_COMMENT | Post\UserNotification::NOTIF_DIRECT_COMMENT | + Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT, + api_user(), $since_id]; if ($max_id > 0) { - $query .= " AND `iid` <= ?"; + $query .= " AND `id` <= ?"; $condition[] = $max_id; } - $query .= ")"; - array_unshift($condition, $query); $params = ['order' => ['id' => true], 'limit' => [$start, $count]]; @@ -2267,7 +2262,6 @@ function api_statuses_user_timeline($type) $condition[0] .= " AND `id` <= ?"; $condition[] = $max_id; } - $params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $statuses = Post::selectForUser(api_user(), [], $condition, $params); @@ -2936,6 +2930,10 @@ function api_format_items($items, $user_info, $filter_user = false, $type = "jso $ret = []; + if (empty($items)) { + return $ret; + } + foreach ((array)$items as $item) { list($status_user, $author_user, $owner_user) = api_item_get_user($a, $item); @@ -3297,8 +3295,10 @@ function api_lists_statuses($type) $start = max(0, ($page - 1) * $count); - $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `group-id` = ?", - api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $_REQUEST['list_id']]; + $groups = DBA::selectToArray('group_member', ['contact-id'], ['gid' => 1]); + $gids = array_column($groups, 'contact-id'); + $condition = ['uid' => api_user(), 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'group-id' => $gids]; + $condition = DBA::mergeConditions($condition, ["`id` > ?", $since_id]); if ($max_id > 0) { $condition[0] .= " AND `id` <= ?"; @@ -4872,7 +4872,7 @@ function prepare_photo_data($type, $scale, $photo_id) } // retrieve item element for getting activities (like, dislike etc.) related to photo - $condition = ['uid' => api_user(), 'resource-id' => $photo_id, 'type' => 'photo']; + $condition = ['uid' => api_user(), 'resource-id' => $photo_id]; $item = Post::selectFirst(['id', 'uid', 'uri', 'parent', 'allow_cid', 'deny_cid', 'allow_gid', 'deny_gid'], $condition); if (!DBA::isResult($item)) { throw new NotFoundException('Photo-related item not found.'); @@ -4881,7 +4881,7 @@ function prepare_photo_data($type, $scale, $photo_id) $data['photo']['friendica_activities'] = api_format_items_activities($item, $type); // retrieve comments on photo - $condition = ["`parent` = ? AND `uid` = ? AND (`gravity` IN (?, ?) OR `type`='photo')", + $condition = ["`parent` = ? AND `uid` = ? AND `gravity` IN (?, ?)", $item['parent'], api_user(), GRAVITY_PARENT, GRAVITY_COMMENT]; $statuses = Post::selectForUser(api_user(), [], $condition); @@ -5807,7 +5807,7 @@ function api_friendica_notification_seen($type) $notify = DI::notify()->getByID($id, api_user()); DI::notify()->setSeen(true, $notify); - if ($notify->otype === Notify\ObjectType::ITEM) { + if ($notify->otype === Notification\ObjectType::ITEM) { $item = Post::selectFirstForUser(api_user(), [], ['id' => $notify->iid, 'uid' => api_user()]); if (DBA::isResult($item)) { // we found the item, return it to the user @@ -6007,7 +6007,7 @@ function bindComments(&$data) } $idStr = DBA::escape(implode(', ', $ids)); - $sql = "SELECT `parent`, COUNT(*) as comments FROM `post-view` WHERE `parent` IN ($idStr) AND `deleted` = ? AND `gravity`= ? GROUP BY `parent`"; + $sql = "SELECT `parent`, COUNT(*) as comments FROM `post-user-view` WHERE `parent` IN ($idStr) AND `deleted` = ? AND `gravity`= ? GROUP BY `parent`"; $items = DBA::p($sql, 0, GRAVITY_COMMENT); $itemsData = DBA::toArray($items);