1
1
Fork 0

Merge pull request #12950 from mkljczk/dislikes

Return `disliked` in Mastodon API
This commit is contained in:
Hypolite Petovan 2023-03-26 15:57:46 -04:00 committed by GitHub
commit 368234f5e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 14 deletions

View file

@ -839,7 +839,8 @@ A Mastodon [Status Entity](https://docs.joinmastodon.org/entities/Status/)
"poll": null,
"friendica": {
"title": "",
"dislikes_count": 1
"dislikes_count": 1,
"disliked": true
}
}
```
@ -886,7 +887,7 @@ Removes the dislike mark (if it exists) on this status for this user
A Mastodon [Status Entity](https://docs.joinmastodon.org/entities/Status/)
#### Example:
`https://<server_name>/api/friendica/statuses/341/dislike`
`https://<server_name>/api/friendica/statuses/341/undislike`
```json
{
@ -913,7 +914,8 @@ A Mastodon [Status Entity](https://docs.joinmastodon.org/entities/Status/)
"poll": null,
"friendica": {
"title": "",
"dislikes_count": 0
"dislikes_count": 0,
"disliked": false
}
}
```

View file

@ -68,6 +68,7 @@ Extensions to the [Mastodon Status Entities](https://docs.joinmastodon.org/entit
* `delivery_queue_done`: Total number of remote servers that have successfully been federated to so far.
* `delivery_queue_failed`: Total number of remote servers that have we failed to federate to so far.
* `dislikes_count`: The number of dislikes that a status has accumulated according to the server.
* `disliked`: Whether the API user disliked the status.
Example:
```json

View file

@ -177,6 +177,14 @@ class Status extends BaseFactory
'vid' => Verb::getID(Activity::LIKE),
'deleted' => false
]);
$origin_dislike = ($count_dislike == 0) ? false : Post::exists([
'thr-parent-id' => $uriId,
'uid' => $uid,
'origin' => true,
'gravity' => Item::GRAVITY_ACTIVITY,
'vid' => Verb::getID(Activity::DISLIKE),
'deleted' => false
]);
$origin_announce = ($count_announce == 0) ? false : Post::exists([
'thr-parent-id' => $uriId,
'uid' => $uid,
@ -295,7 +303,7 @@ class Status extends BaseFactory
$aclFormatter = DI::aclFormatter();
$delivery_data = $uid != $item['uid'] ? null : new FriendicaDeliveryData($item['delivery_queue_count'], $item['delivery_queue_done'], $item['delivery_queue_failed']);
$visibility_data = $uid != $item['uid'] ? null : new FriendicaVisibility($aclFormatter->expand($item['allow_cid']), $aclFormatter->expand($item['deny_cid']), $aclFormatter->expand($item['allow_gid']), $aclFormatter->expand($item['deny_gid']));
$friendica = new FriendicaExtension($item['title'], $item['changed'], $item['commented'], $item['received'], $counts->dislikes, $delivery_data, $visibility_data);
$friendica = new FriendicaExtension($item['title'], $item['changed'], $item['commented'], $item['received'], $counts->dislikes, $origin_dislike, $delivery_data, $visibility_data);
return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $in_reply, $reshare, $friendica, $quote, $poll);
}
@ -361,7 +369,7 @@ class Status extends BaseFactory
$attachments = [];
$in_reply = [];
$reshare = [];
$friendica = new FriendicaExtension('', null, null, null, 0, null, null);
$friendica = new FriendicaExtension('', null, null, null, 0, false, null, null);
return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $in_reply, $reshare, $friendica);
}

View file

@ -47,14 +47,18 @@ class FriendicaExtension extends BaseDataTransferObject
/** @var FriendicaDeliveryData|null */
protected $delivery_data;
/** @var int */
protected $dislikes_count;
/** @var bool */
protected $disliked = false;
/**
* @var FriendicaVisibility|null
*/
protected $visibility;
/**
* Creates a FriendicaExtension object
*
@ -64,6 +68,7 @@ class FriendicaExtension extends BaseDataTransferObject
* @param string|null $edited_at
* @param string|null $received_at
* @param int $dislikes_count
* @param bool $disliked
* @param FriendicaDeliveryData|null $delivery_data
* @param FriendicaVisibility|null $visibility
*/
@ -73,6 +78,7 @@ class FriendicaExtension extends BaseDataTransferObject
?string $commented_at,
?string $received_at,
int $dislikes_count,
bool $disliked,
?FriendicaDeliveryData $delivery_data,
?FriendicaVisibility $visibility
) {
@ -82,6 +88,7 @@ class FriendicaExtension extends BaseDataTransferObject
$this->received_at = $received_at ? DateTimeFormat::utc($received_at, DateTimeFormat::JSON) : null;
$this->delivery_data = $delivery_data;
$this->dislikes_count = $dislikes_count;
$this->disliked = $disliked;
$this->visibility = $visibility;
}