mirror of
https://github.com/friendica/friendica
synced 2024-11-18 10:23:41 +00:00
Merge pull request #13066 from annando/issue-13041
Issue 13041: API activities for reshared posts are now performed on the original posts
This commit is contained in:
commit
d425f2eaac
17 changed files with 107 additions and 30 deletions
|
@ -38,7 +38,7 @@ class StatusSource extends BaseFactory
|
|||
*/
|
||||
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']));
|
||||
|
|
|
@ -226,6 +226,46 @@ class Post
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
@ -505,6 +545,46 @@ class Post
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
|
@ -268,7 +268,7 @@ class Statuses extends BaseApi
|
|||
}
|
||||
|
||||
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 . '.');
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class Bookmark extends BaseApi
|
|||
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();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class Bookmark extends BaseApi
|
|||
}
|
||||
|
||||
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)) {
|
||||
|
|
|
@ -43,13 +43,11 @@ class Card extends BaseApi
|
|||
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());
|
||||
}
|
||||
|
|
|
@ -57,8 +57,9 @@ class Context extends BaseApi
|
|||
$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]];
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class Favourite extends BaseApi
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -44,12 +44,11 @@ class FavouritedBy extends BaseApi
|
|||
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 = [];
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class Mute extends BaseApi
|
|||
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();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class Mute extends BaseApi
|
|||
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());
|
||||
}
|
||||
|
|
|
@ -41,12 +41,12 @@ class Pin extends BaseApi
|
|||
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());
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class Reblog extends BaseApi
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -44,12 +44,11 @@ class RebloggedBy extends BaseApi
|
|||
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 = [];
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class Unbookmark extends BaseApi
|
|||
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();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class Unbookmark extends BaseApi
|
|||
}
|
||||
|
||||
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)) {
|
||||
|
|
|
@ -42,7 +42,7 @@ class Unfavourite extends BaseApi
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class Unmute extends BaseApi
|
|||
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();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class Unmute extends BaseApi
|
|||
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());
|
||||
}
|
||||
|
|
|
@ -41,12 +41,12 @@ class Unpin extends BaseApi
|
|||
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());
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class Unreblog extends BaseApi
|
|||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue