* @param int $uriId Uri-ID of the item
* @param int $uid Item user
*
- * @return \Friendica\Object\Api\Mastodon\Status
+ * @return \Friendica\Object\Api\Twitter\Status
* @throws HTTPException\InternalServerErrorException
* @throws ImagickException|HTTPException\NotFoundException
*/
* @param int $uriId Uri-ID of the item
* @param int $uid Item user
*
- * @return \Friendica\Object\Api\Mastodon\Status
+ * @return \Friendica\Object\Api\Twitter\Status
* @throws HTTPException\InternalServerErrorException
* @throws ImagickException|HTTPException\NotFoundException
*/
public function createFromUriId(int $uriId, $uid = 0, $include_entities = false): \Friendica\Object\Api\Twitter\Status
{
- $fields = ['id', 'parent', 'uri-id', 'uid', 'author-id', 'author-link', 'author-network', 'owner-id', 'starred', 'app', 'title', 'body', 'raw-body', 'created', 'network',
+ $fields = ['parent-uri-id', 'uri-id', 'uid', 'author-id', 'author-link', 'author-network', 'owner-id', 'starred', 'app', 'title', 'body', 'raw-body', 'created', 'network',
'thr-parent-id', 'parent-author-id', 'parent-author-nick', 'language', 'uri', 'plink', 'private', 'vid', 'gravity', 'coord'];
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
if (!$item) {
* @param array $item item array
* @param int $uid Item user
*
- * @return \Friendica\Object\Api\Mastodon\Status
+ * @return \Friendica\Object\Api\Twitter\Status
* @throws HTTPException\InternalServerErrorException
* @throws ImagickException|HTTPException\NotFoundException
*/
namespace Friendica\Module\Api\Friendica;
-use Friendica\DI;
use Friendica\Model\Item;
+use Friendica\Model\Post;
use Friendica\Module\BaseApi;
+use Friendica\Network\HTTPException\BadRequestException;
/**
* API endpoints:
'id' => 0, // Id of the post
], $request);
- $res = Item::performActivity($request['id'], $this->parameters['verb'], $uid);
+ $post = Post::selectFirst(['id'], ['uri-id' => $request['id'], 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
+ if (empty($post['id'])) {
+ throw new BadRequestException('Item id not found');
+ }
+
+ $res = Item::performActivity($post['id'], $this->parameters['verb'], $uid);
if ($res) {
if (($this->parameters['extension'] ?? '') == 'xml') {
use Friendica\Content\Text\BBCode;
use Friendica\Database\DBA;
-use Friendica\DI;
use Friendica\Module\BaseApi;
/**
$request = $this->getRequest([
'since_id' => 0,
- 'count' => 0,
+ 'count' => 50,
], $request);
$condition = ["`id` > ? AND `uid` = ?", $request['since_id'], $uid];
*/
class Show extends BaseApi
{
- protected function post(array $request = [])
+ protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
$this->friendicaPhoto = $friendicaPhoto;
}
- protected function post(array $request = [])
+ protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
Logger::info(BaseApi::LOG_PREFIX . '{subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $id]);
// try to fetch the item for the local user - or the public item, if there is no local one
- $item = Post::selectFirst(['parent-uri-id'], ['id' => $id]);
+ $item = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
if (!DBA::isResult($item)) {
throw new BadRequestException("There is no status with the id $id.");
}
$id = $parent['id'];
- $condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `id` > ?",
+ $condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `uri-id` > ?",
$id, $uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
+ $condition[0] .= " AND `uri-id` <= ?";
$condition[] = $max_id;
}
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params);
if (!DBA::isResult($statuses)) {
$start = max(0, ($page - 1) * $count);
- $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `starred`",
+ $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `uri-id` > ? AND `starred`",
$uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];
if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
+ $condition[0] .= " AND `uri-id` <= ?";
$condition[] = $max_id;
}
use Friendica\DI;
use Friendica\Model\Item;
+use Friendica\Model\Post;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\BadRequestException;
throw new BadRequestException('Item id not specified');
}
- Item::performActivity($id, 'like', $uid);
+ $post = Post::selectFirst(['id'], ['uri-id' => $request['id'], 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
+ if (empty($post['id'])) {
+ throw new BadRequestException('Item id not found');
+ }
+
+ Item::performActivity($post['id'], 'like', $uid);
- $status_info = DI::twitterStatus()->createFromItemId($id, $uid)->toArray();
+ $status_info = DI::twitterStatus()->createFromUriId($id, $uid)->toArray();
$this->response->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null);
}
use Friendica\DI;
use Friendica\Model\Item;
+use Friendica\Model\Post;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\BadRequestException;
throw new BadRequestException('Item id not specified');
}
- Item::performActivity($id, 'unlike', $uid);
+ $post = Post::selectFirst(['id'], ['uri-id' => $request['id'], 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
+ if (empty($post['id'])) {
+ throw new BadRequestException('Item id not found');
+ }
+
+ Item::performActivity($post['id'], 'unlike', $uid);
- $status_info = DI::twitterStatus()->createFromItemId($id, $uid)->toArray();
+ $status_info = DI::twitterStatus()->createFromUriId($id, $uid)->toArray();
$this->response->exit('status', ['status' => $status_info], $this->parameters['extension'] ?? null);
}
$groups = $this->dba->selectToArray('group_member', ['contact-id'], ['gid' => $request['list_id']]);
$gids = array_column($groups, 'contact-id');
$condition = ['uid' => $uid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'contact-id' => $gids];
- $condition = DBA::mergeConditions($condition, ["`id` > ?", $since_id]);
+ $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $since_id]);
if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
+ $condition[0] .= " AND `uri-id` <= ?";
$condition[] = $max_id;
}
if ($exclude_replies) {
$condition[] = GRAVITY_PARENT;
}
if ($conversation_id > 0) {
- $condition[0] .= " AND `parent` = ?";
+ $condition[0] .= " AND `parent-uri-id` = ?";
$condition[] = $conversation_id;
}
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params);
$items = [];
$start = max(0, ($page - 1) * $count);
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];
if (preg_match('/^#(\w+)$/', $searchTerm, $matches) === 1 && isset($matches[1])) {
$searchTerm = $matches[1];
- $condition = ["`iid` > ? AND `name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $since_id, $searchTerm, $uid];
+ $condition = ["`uri-id` > ? AND `name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $since_id, $searchTerm, $uid];
$tags = DBA::select('tag-search-view', ['uri-id'], $condition);
$uriids = [];
$params['group_by'] = ['uri-id'];
} else {
- $condition = ["`id` > ?
+ $condition = ["`uri-id` > ?
" . ($exclude_replies ? " AND `gravity` = " . GRAVITY_PARENT : ' ') . "
AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))
AND `body` LIKE CONCAT('%',?,'%')",
$since_id, $uid, $_REQUEST['q']];
if ($max_id > 0) {
- $condition[0] .= ' AND `id` <= ?';
+ $condition[0] .= ' AND `uri-id` <= ?';
$condition[] = $max_id;
}
}
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
+use Friendica\Model\Post;
use Friendica\Network\HTTPException\BadRequestException;
/**
throw new BadRequestException('An id is missing.');
}
+ $post = Post::selectFirst(['id'], ['uri-id' => $request['id'], 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
+ if (empty($post['id'])) {
+ throw new BadRequestException('Item id not found');
+ }
+
$this->logger->notice('API: api_statuses_destroy: ' . $id);
$include_entities = $this->getRequestValue($request, 'include_entities', false);
- $ret = DI::twitterStatus()->createFromItemId($id, $uid, $include_entities)->toArray();
+ $ret = DI::twitterStatus()->createFromUriId($id, $uid, $include_entities)->toArray();
- Item::deleteForUser(['id' => $id], $uid);
+ Item::deleteForUser(['id' => $post['id']], $uid);
$this->response->exit('status', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}
$start = max(0, ($page - 1) * $count);
- $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ?",
+ $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `uri-id` > ?",
$uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
+ $condition[0] .= " AND `uri-id` <= ?";
$condition[] = $max_id;
}
if ($exclude_replies) {
$condition[] = GRAVITY_PARENT;
}
if ($conversation_id > 0) {
- $condition[0] .= " AND `parent` = ?";
+ $condition[0] .= " AND `parent-uri-id` = ?";
$condition[] = $conversation_id;
}
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params);
$ret = [];
$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` > ?";
+ AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `uri-id` > ?";
$condition = [
GRAVITY_PARENT, GRAVITY_COMMENT,
];
if ($max_id > 0) {
- $query .= " AND `id` <= ?";
+ $query .= " AND `uri-id` <= ?";
$condition[] = $max_id;
}
array_unshift($condition, $query);
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params);
$ret = [];
$start = max(0, ($page - 1) * $count);
- $condition = ["`uid` = 0 AND `gravity` IN (?, ?) AND `id` > ? AND `private` = ?",
+ $condition = ["`uid` = 0 AND `gravity` IN (?, ?) AND `uri-id` > ? AND `private` = ?",
GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC];
if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
+ $condition[0] .= " AND `uri-id` <= ?";
$condition[] = $max_id;
}
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, Item::DISPLAY_FIELDLIST, $condition, $params);
$ret = [];
$start = max(0, ($page - 1) * $count);
if ($exclude_replies && !$conversation_id) {
- $condition = ["`gravity` = ? AND `id` > ? AND `private` = ? AND `wall` AND NOT `author-hidden`",
+ $condition = ["`gravity` = ? AND `uri-id` > ? AND `private` = ? AND `wall` AND NOT `author-hidden`",
GRAVITY_PARENT, $since_id, Item::PUBLIC];
if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
+ $condition[0] .= " AND `uri-id` <= ?";
$condition[] = $max_id;
}
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params);
} else {
- $condition = ["`gravity` IN (?, ?) AND `id` > ? AND `private` = ? AND `wall` AND `origin` AND NOT `author-hidden`",
+ $condition = ["`gravity` IN (?, ?) AND `uri-id` > ? AND `private` = ? AND `wall` AND `origin` AND NOT `author-hidden`",
GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC];
if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
+ $condition[0] .= " AND `uri-id` <= ?";
$condition[] = $max_id;
}
if ($conversation_id > 0) {
- $condition[0] .= " AND `parent` = ?";
+ $condition[0] .= " AND `parent-uri-id` = ?";
$condition[] = $conversation_id;
}
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params);
}
throw new BadRequestException('An id is missing.');
}
- $fields = ['uri-id', 'network', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
- $item = Post::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
+ $fields = ['id', 'uri-id', 'network', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
+ $item = Post::selectFirst($fields, ['uri-id' => $id, 'uid' => [0, $uid], 'private' => [Item::PUBLIC, Item::UNLISTED]], ['order' => ['uid' => true]]);
if (DBA::isResult($item) && !empty($item['body'])) {
if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::TWITTER])) {
throw new InternalServerErrorException();
}
- $item_id = $id;
+ $item_id = $item['id'];
} else {
$item_id = Diaspora::performReshare($item['uri-id'], $uid);
}
$conversation = !empty($request['conversation']);
// try to fetch the item for the local user - or the public item, if there is no local one
- $uri_item = Post::selectFirst(['uri-id'], ['id' => $id]);
- if (!DBA::isResult($uri_item)) {
- throw new BadRequestException(sprintf("There is no status with the id %d", $id));
- }
-
- $item = Post::selectFirst(['id'], ['uri-id' => $uri_item['uri-id'], 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
+ $item = Post::selectFirst(['id'], ['uri-id' => $id, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
if (!DBA::isResult($item)) {
- throw new BadRequestException(sprintf("There is no status with the uri-id %d for the given user.", $uri_item['uri-id']));
+ throw new BadRequestException(sprintf("There is no status with the uri-id %d for the given user.", $id));
}
- $id = $item['id'];
+ $item_id = $item['id'];
if ($conversation) {
- $condition = ['parent' => $id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
- $params = ['order' => ['id' => true]];
+ $condition = ['parent' => $item_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
+ $params = ['order' => ['uri-id' => true]];
} else {
- $condition = ['id' => $id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
+ $condition = ['id' => $item_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
$params = [];
}
$start = max(0, ($page - 1) * $count);
- $condition = ["(`uid` = ? OR (`uid` = ? AND NOT `global`)) AND `gravity` IN (?, ?) AND `id` > ? AND `author-id` = ?",
+ $condition = ["(`uid` = ? OR (`uid` = ? AND NOT `global`)) AND `gravity` IN (?, ?) AND `uri-id` > ? AND `author-id` = ?",
0, $uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $cid];
if ($exclude_replies) {
}
if ($conversation_id > 0) {
- $condition[0] .= " AND `parent` = ?";
+ $condition[0] .= " AND `parent-uri-id` = ?";
$condition[] = $conversation_id;
}
if ($max_id > 0) {
- $condition[0] .= " AND `id` <= ?";
+ $condition[0] .= " AND `uri-id` <= ?";
$condition[] = $max_id;
}
- $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
+ $params = ['order' => ['uri-id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params);
$ret = [];
$this->logger->info('Diaspora: Receiving post.');
$importer = User::getByGuid($this->parameters['guid']);
+ if (empty($importer)) {
+ // We haven't found the user.
+ // To avoid the remote system trying again we send the message that we accepted the content.
+ throw new HTTPException\AcceptedException();
+ }
if ($importer['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
// Communities aren't working with the Diaspora protoccol
throw new HTTPException\AcceptedException();
}
- $msg = $this->decodePost(false, $importer['prvkey'] ?? '');
+ $msg = $this->decodePost(false, $importer['prvkey']);
$this->logger->info('Diaspora: Dispatching.');
*/
public function __construct(string $text, string $statusnetHtml, string $friendicaHtml, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, array $attachments, int $friendica_comments, bool $liked)
{
- $this->id = (int)$item['id'];
- $this->id_str = (string)$item['id'];
- $this->statusnet_conversation_id = (int)$item['parent'];
+ $this->id = (int)$item['uri-id'];
+ $this->id_str = (string)$item['uri-id'];
+ $this->statusnet_conversation_id = (int)$item['parent-uri-id'];
$this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::API);
=> [Module\Api\Friendica\Activity::class, [ R::POST]],
'/notification/seen[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Notification\Seen::class, [ R::POST]],
'/notification[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Notification::class, [R::GET ]],
+ '/notifications[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Notification::class, [R::GET ]],
'/direct_messages_setseen[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\DirectMessages\Setseen::class, [ R::POST]],
'/direct_messages_search[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\DirectMessages\Search ::class, [R::GET ]],
'/events[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Events\Index::class, [R::GET ]],