<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Model\User;
-use Friendica\Model\UserItem;
use Friendica\Model\Verb;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\BadRequestException;
if ($throttle_day > 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);
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);
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);
$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 `iid` <= ?";
+ $condition[0] .= " AND `id` <= ?";
$condition[] = $max_id;
}
- $params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
- $statuses = Post::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
+ $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $statuses = Post::selectForUser(api_user(), [], $condition, $params);
$r = Post::toArray($statuses);
} else {
$start = max(0, ($page - 1) * $count);
- $condition = ["`uid` = 0 AND `gravity` IN (?, ?) AND `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 `iid` <= ?";
+ $condition[0] .= " AND `id` <= ?";
$condition[] = $max_id;
}
- $params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
- $statuses = Post::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(Post::toArray($statuses), $user_info, false, $type);
+ $ret = api_format_items($statuses, $user_info, false, $type);
bindComments($ret);
$start = max(0, ($page - 1) * $count);
- $query = "`gravity` IN (?, ?) AND `uri-id` IN (SELECT `uri-id` FROM `post-user`
- WHERE (`hidden` IS NULL OR NOT `hidden`) AND
- `uid` = ? AND `notification-type` & ? != 0)
- AND `id` > ?";
+ $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 `id` <= ?";
$condition[0] .= " AND `id` <= ?";
$condition[] = $max_id;
}
-
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser(api_user(), [], $condition, $params);
$ret = [];
+ if (empty($items)) {
+ return $ret;
+ }
+
foreach ((array)$items as $item) {
list($status_user, $author_user, $owner_user) = api_item_get_user($a, $item);
}
// 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.');
$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);
}
$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);