$poll = null;
}
- $shared = $this->contentItem->getSharedPost($item, ['uri-id']);
- if (!empty($shared)) {
- $shared_uri_id = $shared['post']['uri-id'];
-
- foreach ($this->mstdnMentionFactory->createFromUriId($shared_uri_id)->getArrayCopy() as $mention) {
- if (!in_array($mention, $mentions)) {
- $mentions[] = $mention;
- }
- }
-
- foreach ($this->mstdnTagFactory->createFromUriId($shared_uri_id) as $tag) {
- if (!in_array($tag, $tags)) {
- $tags[] = $tag;
- }
- }
-
- foreach ($this->mstdnAttachementFactory->createFromUriId($shared_uri_id) as $attachment) {
- if (!in_array($attachment, $attachments)) {
- $attachments[] = $attachment;
- }
- }
-
- if (empty($card->toArray())) {
- $card = $this->mstdnCardFactory->createFromUriId($shared_uri_id);
- }
- }
-
if ($display_quote) {
$quote = self::createQuote($item, $uid);
$quote = self::createQuote($item, $uid);
}
+ $shared = $this->contentItem->getSharedPost($item, ['uri-id']);
+ if (!empty($shared)) {
+ $shared_uri_id = $shared['post']['uri-id'];
+
+ foreach ($this->mstdnMentionFactory->createFromUriId($shared_uri_id)->getArrayCopy() as $mention) {
+ if (!in_array($mention, $mentions)) {
+ $mentions[] = $mention;
+ }
+ }
+
+ foreach ($this->mstdnTagFactory->createFromUriId($shared_uri_id) as $tag) {
+ if (!in_array($tag, $tags)) {
+ $tags[] = $tag;
+ }
+ }
+
+ foreach ($this->mstdnAttachementFactory->createFromUriId($shared_uri_id) as $attachment) {
+ if (!in_array($attachment, $attachments)) {
+ $attachments[] = $attachment;
+ }
+ }
+
+ if (empty($card->toArray())) {
+ $card = $this->mstdnCardFactory->createFromUriId($shared_uri_id);
+ }
+ }
+
$item['body'] = $this->contentItem->addSharedPost($item);
if (!is_null($item['raw-body'])) {
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
}
+ $display_quotes = self::appSupportsQuotes();
+
$statuses = [];
while ($item = Post::fetch($items)) {
self::setBoundaries($item['uri-id']);
try {
- $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
+ $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, true, true, $display_quotes);
} catch (\Throwable $th) {
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]);
}
$items = Post::selectThreadForUser($uid, ['uri-id'], $condition, $params);
+ $display_quotes = self::appSupportsQuotes();
+
$statuses = [];
while ($item = Post::fetch($items)) {
self::setBoundaries($item['uri-id']);
- $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
+ $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, true, true, $display_quotes);
}
DBA::close($items);
$request = $this->getRequest([
'limit' => 20, // Maximum number of results to return. Defaults to 20.
- 'min_id' => 0, // Return results immediately newer than id
'max_id' => 0, // Return results older than id
+ 'since_id' => 0, // Return results newer than this ID. Use HTTP Link header to paginate.
+ 'min_id' => 0, // Return results immediately newer than id
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
], $request);
$condition = DBA::mergeConditions($condition, ["`thr-parent-id` < ?", $request['max_id']]);
}
+ if (!empty($request['since_id'])) {
+ $condition = DBA::mergeConditions($condition, ["`thr-parent-id` > ?", $request['since_id']]);
+ }
+
if (!empty($request['min_id'])) {
$condition = DBA::mergeConditions($condition, ["`thr-parent-id` > ?", $request['min_id']]);
$items = Post::selectForUser($uid, ['thr-parent-id'], $condition, $params);
+ $display_quotes = self::appSupportsQuotes();
+
$statuses = [];
while ($item = Post::fetch($items)) {
self::setBoundaries($item['thr-parent-id']);
- $statuses[] = DI::mstdnStatus()->createFromUriId($item['thr-parent-id'], $uid);
+ $statuses[] = DI::mstdnStatus()->createFromUriId($item['thr-parent-id'], $uid, true, true, $display_quotes);
}
DBA::close($items);
// If the user-specific search failed, we search and probe a public post
$item_id = Item::fetchByLink($q, $uid) ?: Item::fetchByLink($q);
if ($item_id && $item = Post::selectFirst(['uri-id'], ['id' => $item_id])) {
- return DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
+ return DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, true, true, self::appSupportsQuotes());
}
}
$items = DBA::select($table, ['uri-id'], $condition, $params);
+ $display_quotes = self::appSupportsQuotes();
+
$statuses = [];
while ($item = Post::fetch($items)) {
self::setBoundaries($item['uri-id']);
- $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
+ $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, true, true, $display_quotes);
}
DBA::close($items);
Item::update($item, ['id' => $post['id']]);
Item::updateDisplayCache($post['uri-id']);
- System::jsonExit(DI::mstdnStatus()->createFromUriId($post['uri-id'], $uid));
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($post['uri-id'], $uid, true, true, self::appSupportsQuotes()));
}
protected function post(array $request = [])
if (!empty($id)) {
$item = Post::selectFirst(['uri-id'], ['id' => $id]);
if (!empty($item['uri-id'])) {
- System::jsonExit(DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid));
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, true, true, self::appSupportsQuotes()));
}
}
DI::mstdnError()->UnprocessableEntity();
}
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, false));
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, false, true, self::appSupportsQuotes()));
}
private function getApp(): string
Item::update(['starred' => true], ['id' => $item['id']]);
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, true, true, self::appSupportsQuotes())->toArray());
}
}
}
$request = $this->getRequest([
+ 'max_id' => 0, // Return results older than this id
+ 'since_id' => 0, // Return results newer than this id
+ 'min_id' => 0, // Return results immediately newer than this id
'limit' => 40, // Maximum number of results to return. Defaults to 40.
], $request);
$parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
if (DBA::isResult($parent)) {
- $posts = Post::selectPosts(['uri-id', 'thr-parent-id'],
- ['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]]);
+ $params = ['order' => ['uri-id' => true]];
+ $condition = ['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]];
+
+ if (!empty($request['max_id'])) {
+ $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]);
+ }
+
+ if (!empty($request['since_id'])) {
+ $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['since_id']]);
+ }
+
+ if (!empty($request['min_id'])) {
+ $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]);
+ $params['order'] = ['uri-id'];
+ }
+
+ $posts = Post::selectPosts(['uri-id', 'thr-parent-id'], $condition, $params);
while ($post = Post::fetch($posts)) {
if ($post['uri-id'] == $post['thr-parent-id']) {
continue;
}
+ self::setBoundaries($post['uri-id']);
+
$parents[$post['uri-id']] = $post['thr-parent-id'];
$children[$post['thr-parent-id']][] = $post['uri-id'];
}
DBA::close($posts);
+
+ self::setLinkHeader();
} else {
$parent = DBA::selectFirst('mail', ['parent-uri-id'], ['uri-id' => $id, 'uid' => $uid]);
if (DBA::isResult($parent)) {
asort($ancestors);
+ $display_quotes = self::appSupportsQuotes();
+
foreach (array_slice($ancestors, 0, $request['limit']) as $ancestor) {
- $statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid);;
+ $statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid, true, true, $display_quotes);;
}
$descendants = self::getChildren($id, $children);
asort($descendants);
foreach (array_slice($descendants, 0, $request['limit']) as $descendant) {
- $statuses['descendants'][] = DI::mstdnStatus()->createFromUriId($descendant, $uid);
+ $statuses['descendants'][] = DI::mstdnStatus()->createFromUriId($descendant, $uid, true, true, $display_quotes);
}
System::jsonExit($statuses);
Item::performActivity($item['id'], 'like', $uid);
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid,true, true, self::appSupportsQuotes())->toArray());
}
}
Post\ThreadUser::setIgnored($this->parameters['id'], $uid, true);
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, true, true, self::appSupportsQuotes())->toArray());
}
}
Post\Collection::add($this->parameters['id'], Post\Collection::FEATURED, $item['author-id'], $uid);
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, true, true, self::appSupportsQuotes())->toArray());
}
}
Item::performActivity($item['id'], 'announce', $uid);
}
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, true, true, self::appSupportsQuotes())->toArray());
}
}
Item::update(['starred' => false], ['id' => $item['id']]);
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, true, true, self::appSupportsQuotes())->toArray());
}
}
Item::performActivity($item['id'], 'unlike', $uid);
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, true, true, self::appSupportsQuotes())->toArray());
}
}
Post\ThreadUser::setIgnored($this->parameters['id'], $uid, false);
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, true, true, self::appSupportsQuotes())->toArray());
}
}
Post\Collection::remove($this->parameters['id'], Post\Collection::FEATURED, $uid);
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, true, true, self::appSupportsQuotes())->toArray());
}
}
Item::performActivity($item['id'], 'unannounce', $uid);
}
- System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
+ System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, true, true, self::appSupportsQuotes())->toArray());
}
}
namespace Friendica\Module\Api\Mastodon\Timelines;
+use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
+ $display_quotes = self::appSupportsQuotes();
+
$statuses = [];
while ($item = Post::fetch($items)) {
self::setBoundaries($item['uri-id']);
- $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
+ $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, true, true, $display_quotes);
}
DBA::close($items);
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
+ $display_quotes = self::appSupportsQuotes();
+
$statuses = [];
while ($item = Post::fetch($items)) {
self::setBoundaries($item['uri-id']);
- $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
+ $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, true, true, $display_quotes);
}
DBA::close($items);
$items = Post::selectPostsForUser($uid, ['uri-id'], $condition, $params);
+ $display_quotes = self::appSupportsQuotes();
+
$statuses = [];
while ($item = Post::fetch($items)) {
self::setBoundaries($item['uri-id']);
try {
- $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
+ $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, true, true, $display_quotes);
} catch (\Throwable $th) {
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]);
}
$items = DBA::select('tag-search-view', ['uri-id'], $condition, $params);
+ $display_quotes = self::appSupportsQuotes();
+
$statuses = [];
while ($item = Post::fetch($items)) {
self::setBoundaries($item['uri-id']);
- $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
+ $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, true, true, $display_quotes);
}
DBA::close($items);
$condition = ["NOT `private` AND `commented` > ? AND `created` > ?", DateTimeFormat::utc('now -1 day'), DateTimeFormat::utc('now -1 week')];
$condition = DBA::mergeConditions($condition, ['network' => Protocol::FEDERATED]);
+ $display_quotes = self::appSupportsQuotes();
+
$trending = [];
$statuses = Post::selectPostThread(['uri-id'], $condition, ['limit' => $request['limit'], 'order' => ['total-actors' => true]]);
while ($status = Post::fetch($statuses)) {
- $trending[] = DI::mstdnStatus()->createFromUriId($status['uri-id'], $uid);
+ $trending[] = DI::mstdnStatus()->createFromUriId($status['uri-id'], $uid, true, true, $display_quotes);
}
DBA::close($statuses);
}
}
+ /**
+ * Check if the app is known to support quoted posts
+ *
+ * @return bool
+ */
+ public static function appSupportsQuotes(): bool
+ {
+ $token = self::getCurrentApplication();
+ return (!empty($token['name']) && in_array($token['name'], ['Fedilab']));
+ }
+
/**
* Get current application token
*