Issue 11915: Show reshared posts for contacts
This commit is contained in:
parent
62f982cf7e
commit
4f98d2c74a
3 changed files with 27 additions and 23 deletions
|
@ -86,7 +86,7 @@ class Status extends BaseFactory
|
||||||
*/
|
*/
|
||||||
public function createFromUriId(int $uriId, int $uid = 0, bool $reblog = true): \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', 'causer-uri-id', 'post-reason', 'starred', 'app', 'title', 'body', 'raw-body', 'content-warning', 'question-id',
|
$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'];
|
'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]]);
|
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
|
||||||
if (!$item) {
|
if (!$item) {
|
||||||
|
@ -97,9 +97,18 @@ class Status extends BaseFactory
|
||||||
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
|
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_reshare = $reblog && !is_null($item['causer-uri-id']) && ($item['post-reason'] == Item::PR_ANNOUNCEMENT);
|
if (($item['gravity'] == Item::GRAVITY_ACTIVITY) && ($item['vid'] == Verb::getID(Activity::ANNOUNCE))) {
|
||||||
|
$is_reshare = true;
|
||||||
$account = $this->mstdnAccountFactory->createFromUriId($is_reshare ? $item['causer-uri-id']:$item['author-uri-id'], $uid);
|
$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([
|
$count_announce = Post::countPosts([
|
||||||
'thr-parent-id' => $uriId,
|
'thr-parent-id' => $uriId,
|
||||||
|
@ -190,19 +199,13 @@ class Status extends BaseFactory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
|
$item['body'] = $this->contentItem->addSharedPost($item);
|
||||||
$reshare = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
|
$item['raw-body'] = $this->contentItem->addSharedPost($item, $item['raw-body']);
|
||||||
$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'];
|
|
||||||
} else {
|
|
||||||
$item['body'] = $this->contentItem->addSharedPost($item);
|
|
||||||
$item['raw-body'] = $this->contentItem->addSharedPost($item, $item['raw-body']);
|
|
||||||
$reshare = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($is_reshare) {
|
if ($is_reshare) {
|
||||||
$reshare = $this->createFromUriId($uriId, $uid, false)->toArray();
|
$reshare = $this->createFromUriId($uriId, $uid, false)->toArray();
|
||||||
|
} else {
|
||||||
|
$reshare = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $reshare, $poll);
|
return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $reshare, $poll);
|
||||||
|
|
|
@ -80,8 +80,15 @@ class Statuses extends BaseApi
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$request['pinned'] && !$request['only_media']) {
|
if (!$request['pinned'] && !$request['only_media']) {
|
||||||
$condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
|
if ($request['exclude_replies']) {
|
||||||
Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
|
$condition = DBA::mergeConditions($condition, ["(`gravity` = ? OR (`gravity` = ? AND `vid` = ?))",
|
||||||
|
Item::GRAVITY_PARENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
|
||||||
|
} else {
|
||||||
|
$condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
|
||||||
|
Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
|
||||||
|
}
|
||||||
|
} elseif ($request['exclude_replies']) {
|
||||||
|
$condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($request['max_id'])) {
|
if (!empty($request['max_id'])) {
|
||||||
|
@ -97,16 +104,10 @@ class Statuses extends BaseApi
|
||||||
$params['order'] = ['uri-id'];
|
$params['order'] = ['uri-id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($request['pinned'] || $request['only_media']) && $request['exclude_replies']) {
|
|
||||||
$condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request['pinned']) {
|
if ($request['pinned']) {
|
||||||
$items = DBA::select('collection-view', ['uri-id'], $condition, $params);
|
$items = DBA::select('collection-view', ['uri-id'], $condition, $params);
|
||||||
} elseif ($request['only_media']) {
|
} elseif ($request['only_media']) {
|
||||||
$items = DBA::select('media-view', ['uri-id'], $condition, $params);
|
$items = DBA::select('media-view', ['uri-id'], $condition, $params);
|
||||||
} elseif ($request['exclude_replies']) {
|
|
||||||
$items = Post::selectThreadForUser($uid, ['uri-id'], $condition, $params);
|
|
||||||
} else {
|
} else {
|
||||||
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
|
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,7 @@ class Status extends BaseProfile
|
||||||
|
|
||||||
$condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
|
$condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
|
||||||
(`gravity` = ? AND `vid` = ? AND `origin`
|
(`gravity` = ? AND `vid` = ? AND `origin`
|
||||||
AND `thr-parent-id` IN (SELECT `uri-id` FROM `post` WHERE `gravity` = ? AND `network` IN (?, ?))))",
|
AND EXISTS(SELECT `uri-id` FROM `post` WHERE `uri-id` = `post-user-view`.`thr-parent-id` AND `gravity` = ? AND `network` IN (?, ?))))",
|
||||||
Item::GRAVITY_PARENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Item::GRAVITY_PARENT, Protocol::ACTIVITYPUB, Protocol::DFRN]);
|
Item::GRAVITY_PARENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Item::GRAVITY_PARENT, Protocol::ACTIVITYPUB, Protocol::DFRN]);
|
||||||
|
|
||||||
$condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED,
|
$condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED,
|
||||||
|
|
Loading…
Reference in a new issue