*/
public function createFromUriId(int $uriId, int $uid): \Friendica\Object\Api\Mastodon\StatusSource
{
- $post = Post::selectFirst(['uri-id', 'raw-body', 'body', 'title'], ['uri-id' => $uriId, 'uid' => [0, $uid]]);
+ $post = Post::selectOriginal(['uri-id', 'raw-body', 'body', 'title'], ['uri-id' => $uriId, 'uid' => [0, $uid]]);
$spoiler_text = $post['title'] ?: BBCode::toPlaintext(BBCode::getAbstract($post['body'], Protocol::ACTIVITYPUB));
$body = BBCode::toMarkdown(Post\Media::removeFromEndOfBody($post['body']));
}
}
+ /**
+ * Retrieve a single record from the post-user-view view and returns it in an associative array
+ * When the requested record is a reshare activity, the system fetches the reshared original post.
+ * Otherwise the function reacts similar to selectFirst
+ *
+ * @param array $fields
+ * @param array $condition
+ * @param array $params
+ * @param bool $user_mode true = post-user-view, false = post-view
+ * @return bool|array
+ * @throws \Exception
+ * @see DBA::select
+ */
+ public static function selectOriginal(array $fields = [], array $condition = [], array $params = [])
+ {
+ $original_fields = $fields;
+ $remove = [];
+ if (!empty($fields)) {
+ foreach (['gravity', 'verb', 'thr-parent-id', 'uid'] as $field) {
+ if (!in_array($field, $fields)) {
+ $fields[] = $field;
+ $remove[] = $field;
+ }
+ }
+ }
+ $result = self::selectFirst($fields, $condition, $params);
+ if (empty($result)) {
+ return $result;
+ }
+
+ if (($result['gravity'] != Item::GRAVITY_ACTIVITY) || ($result['verb'] != Activity::ANNOUNCE)) {
+ foreach ($remove as $field) {
+ unset($result[$field]);
+ }
+ return $result;
+ }
+
+ return self::selectFirst($original_fields, ['uri-id' => $result['thr-parent-id'], 'uid' => [0, $result['uid']]], $params);
+ }
+
/**
* Retrieve a single record from the post-view view and returns it in an associative array
*
}
}
+ /**
+ * Retrieve a single record from the post-user-view view for a given user and returns it in an associative array
+ * When the requested record is a reshare activity, the system fetches the reshared original post.
+ * Otherwise the function reacts similar to selectFirstForUser
+ *
+ * @param integer $uid User ID
+ * @param array $selected
+ * @param array $condition
+ * @param array $params
+ * @return bool|array
+ * @throws \Exception
+ * @see DBA::select
+ */
+ public static function selectOriginalForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
+ {
+ $original_selected = $selected;
+ $remove = [];
+ if (!empty($selected)) {
+ foreach (['gravity', 'verb', 'thr-parent-id'] as $field) {
+ if (!in_array($field, $selected)) {
+ $selected[] = $field;
+ $remove[] = $field;
+ }
+ }
+ }
+ $result = self::selectFirstForUser($uid, $selected, $condition, $params);
+ if (empty($result)) {
+ return $result;
+ }
+
+ if (($result['gravity'] != Item::GRAVITY_ACTIVITY) || ($result['verb'] != Activity::ANNOUNCE)) {
+ foreach ($remove as $field) {
+ unset($result[$field]);
+ }
+ return $result;
+ }
+
+ return self::selectFirstForUser($uid, $original_selected, ['uri-id' => $result['thr-parent-id'], 'uid' => [0, $uid]], $params);
+ }
+
/**
* Update existing post entries
*
}
if ($request['in_reply_to_id']) {
- $parent = Post::selectFirst(['uri'], ['uri-id' => $request['in_reply_to_id'], 'uid' => [0, $uid]]);
+ $parent = Post::selectOriginal(['uri'], ['uri-id' => $request['in_reply_to_id'], 'uid' => [0, $uid]]);
if (empty($parent)) {
throw new HTTPException\NotFoundException('Item with URI ID ' . $request['in_reply_to_id'] . ' not found for user ' . $uid . '.');
}
DI::mstdnError()->UnprocessableEntity();
}
- $item = Post::selectFirst(['uid', 'id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
+ $item = Post::selectOriginal(['uid', 'id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
}
}
if ($item['uid'] == 0) {
- $stored = Item::storeForUserByUriId($this->parameters['id'], $uid, ['post-reason' => Item::PR_ACTIVITY]);
+ $stored = Item::storeForUserByUriId($item['id'], $uid, ['post-reason' => Item::PR_ACTIVITY]);
if (!empty($stored)) {
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
if (!DBA::isResult($item)) {
DI::mstdnError()->UnprocessableEntity();
}
- $id = $this->parameters['id'];
-
- if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) {
- throw new HTTPException\NotFoundException('Item with URI ID ' . $id . ' not found' . ($uid ? ' for user ' . $uid : '.'));
+ if (!$post = Post::selectOriginal(['id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
+ throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found' . ($uid ? ' for user ' . $uid : '.'));
}
- $card = DI::mstdnCard()->createFromUriId($id);
+ $card = DI::mstdnCard()->createFromUriId($post['id']);
System::jsonExit($card->toArray());
}
$parents = [];
$children = [];
- $parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
+ $parent = Post::selectOriginal(['uri-id', 'parent-uri-id'], ['uri-id' => $id]);
if (DBA::isResult($parent)) {
+ $id = $parent['uri-id'];
$params = ['order' => ['uri-id' => true]];
$condition = ['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]];
DI::mstdnError()->UnprocessableEntity();
}
- $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
+ $item = Post::selectOriginalForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
}
DI::mstdnError()->UnprocessableEntity();
}
- $id = $this->parameters['id'];
- if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) {
+ if (!$post = Post::selectOriginal(['id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
DI::mstdnError()->RecordNotFound();
}
- $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'deleted' => false]);
+ $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'deleted' => false]);
$accounts = [];
DI::mstdnError()->UnprocessableEntity();
}
- $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
+ $item = Post::selectOriginalForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
}
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be muted'));
}
- Post\ThreadUser::setIgnored($this->parameters['id'], $uid, true);
+ Post\ThreadUser::setIgnored($item['id'], $uid, true);
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray());
}
DI::mstdnError()->UnprocessableEntity();
}
- $item = Post::selectFirstForUser($uid, ['id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
+ $item = Post::selectOriginalForUser($uid, ['id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
}
- Post\Collection::add($this->parameters['id'], Post\Collection::FEATURED, $item['author-id'], $uid);
+ Post\Collection::add($item['id'], Post\Collection::FEATURED, $item['author-id'], $uid);
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray());
}
DI::mstdnError()->UnprocessableEntity();
}
- $item = Post::selectFirstForUser($uid, ['id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
+ $item = Post::selectOriginalForUser($uid, ['id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
}
DI::mstdnError()->UnprocessableEntity();
}
- $id = $this->parameters['id'];
- if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) {
+ if (!$post = Post::selectOriginal(['id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
DI::mstdnError()->RecordNotFound();
}
- $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]);
+ $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]);
$accounts = [];
DI::mstdnError()->UnprocessableEntity();
}
- $item = Post::selectFirst(['uid', 'id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
+ $item = Post::selectOriginal(['uid', 'id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
}
}
if ($item['uid'] == 0) {
- $stored = Item::storeForUserByUriId($this->parameters['id'], $uid, ['post-reason' => Item::PR_ACTIVITY]);
+ $stored = Item::storeForUserByUriId($item['id'], $uid, ['post-reason' => Item::PR_ACTIVITY]);
if (!empty($stored)) {
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
if (!DBA::isResult($item)) {
DI::mstdnError()->UnprocessableEntity();
}
- $item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
+ $item = Post::selectOriginalForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
}
DI::mstdnError()->UnprocessableEntity();
}
- $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
+ $item = Post::selectOriginalForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
}
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unmuted'));
}
- Post\ThreadUser::setIgnored($this->parameters['id'], $uid, false);
+ Post\ThreadUser::setIgnored($item['id'], $uid, false);
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray());
}
DI::mstdnError()->UnprocessableEntity();
}
- $item = Post::selectFirstForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
+ $item = Post::selectOriginalForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
}
- Post\Collection::remove($this->parameters['id'], Post\Collection::FEATURED, $uid);
+ Post\Collection::remove($item['id'], Post\Collection::FEATURED, $uid);
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray());
}
DI::mstdnError()->UnprocessableEntity();
}
- $item = Post::selectFirstForUser($uid, ['id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
+ $item = Post::selectOriginalForUser($uid, ['id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound();
}