}
/**
- * @param int $uriId Uri-ID of the item
- * @param int $uid Item user
+ * @param int $uriId Uri-ID of the item
+ * @param int $uid Item user
+ * @param bool $reblog Check for reblogged post
*
* @return \Friendica\Object\Api\Mastodon\Status
* @throws HTTPException\InternalServerErrorException
* @throws ImagickException|HTTPException\NotFoundException
*/
- public function createFromUriId(int $uriId, int $uid = 0): \Friendica\Object\Api\Mastodon\Status
+ public function createFromUriId(int $uriId, int $uid = 0, bool $reblog = true): \Friendica\Object\Api\Mastodon\Status
{
- $fields = ['uri-id', 'uid', 'author-id', 'author-uri-id', 'author-link', 'starred', 'app', 'title', 'body', 'raw-body', 'content-warning', 'question-id',
- 'created', 'network', 'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity', 'featured', 'has-media'];
+ $fields = ['uri-id', 'uid', 'author-id', 'causer-id', 'author-uri-id', 'author-link', 'causer-uri-id', 'post-reason', 'starred', 'app', 'title', 'body', 'raw-body', 'content-warning', 'question-id',
+ 'created', 'network', 'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity', 'featured', 'has-media', 'quote-uri-id'];
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
if (!$item) {
$mail = DBA::selectFirst('mail', ['id'], ['uri-id' => $uriId, 'uid' => $uid]);
}
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
}
- $account = $this->mstdnAccountFactory->createFromUriId($item['author-uri-id'], $uid);
+
+ if (($item['gravity'] == Item::GRAVITY_ACTIVITY) && ($item['vid'] == Verb::getID(Activity::ANNOUNCE))) {
+ $is_reshare = true;
+ $account = $this->mstdnAccountFactory->createFromUriId($item['author-uri-id'], $uid);
+ $uriId = $item['thr-parent-id'];
+ $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
+ if (!$item) {
+ throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
+ }
+ } else {
+ $is_reshare = $reblog && !is_null($item['causer-uri-id']) && ($item['causer-id'] != $item['author-id']) && ($item['post-reason'] == Item::PR_ANNOUNCEMENT);
+ $account = $this->mstdnAccountFactory->createFromUriId($is_reshare ? $item['causer-uri-id'] : $item['author-uri-id'], $uid);
+ }
$count_announce = Post::countPosts([
'thr-parent-id' => $uriId,
'gravity' => Item::GRAVITY_ACTIVITY,
'vid' => Verb::getID(Activity::ANNOUNCE),
'deleted' => false
- ], []);
+ ]) + Post::countPosts([
+ 'quote-uri-id' => $uriId,
+ 'body' => '',
+ 'deleted' => false
+ ]);
+
$count_like = Post::countPosts([
'thr-parent-id' => $uriId,
'gravity' => Item::GRAVITY_ACTIVITY,
'vid' => Verb::getID(Activity::LIKE),
'deleted' => false
- ], []);
+ ]);
$counts = new \Friendica\Object\Api\Mastodon\Status\Counts(
Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => Item::GRAVITY_COMMENT, 'deleted' => false], []),
'gravity' => Item::GRAVITY_ACTIVITY,
'vid' => Verb::getID(Activity::ANNOUNCE),
'deleted' => false
+ ]) || Post::exists([
+ 'quote-uri-id' => $uriId,
+ 'uid' => $uid,
+ 'origin' => true,
+ 'body' => '',
+ 'deleted' => false
]);
$userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes(
$origin_like,
if (!empty($shared)) {
$shared_uri_id = $shared['post']['uri-id'];
- $mentions = array_merge($mentions, $this->mstdnMentionFactory->createFromUriId($shared_uri_id)->getArrayCopy());
- $tags = array_merge($tags, $this->mstdnTagFactory->createFromUriId($shared_uri_id));
- $attachments = array_merge($attachments, $this->mstdnAttachementFactory->createFromUriId($shared_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 ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
- $reshare = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
- $reshared_item = Post::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'],'uid' => [0, $uid]]);
- $item['title'] = $reshared_item['title'] ?? $item['title'];
- $item['body'] = $reshared_item['body'] ?? $item['body'];
+ $item['body'] = $this->contentItem->addSharedPost($item);
+
+ if (!is_null($item['raw-body'])) {
+ $item['raw-body'] = $this->contentItem->addSharedPost($item, $item['raw-body']);
+ }
+
+ if ($is_reshare) {
+ $reshare = $this->createFromUriId($uriId, $uid, false)->toArray();
} else {
$reshare = [];
}