Return `disliked` in Mastodon API

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2023-03-26 09:08:03 +02:00
parent 87f8e7dcca
commit bdafe063d8
4 changed files with 29 additions and 12 deletions

View File

@ -135,7 +135,7 @@ Alias of [`api/conversation/show`](#GET+api%2Fconversation%2Fshow).
### GET api/statusnet/config ### GET api/statusnet/config
Returns the public Friendica node configuration. Returns the public Friendica node configuration.
### GET api/gnusocial/config ### GET api/gnusocial/config
@ -604,7 +604,7 @@ Sets item table entries for this photo to deleted = 1.
On success: On success:
* JSON return * JSON return
```json ```json
{ {
@ -633,7 +633,7 @@ Deletes all images with the specified album name, is not reversible -> ensure th
On success: On success:
* JSON return * JSON return
```json ```json
{ {
@ -682,7 +682,7 @@ Get a list of photo albums for the user
#### Parameters #### Parameters
None None
#### Return values #### Return values
On success a list of photo album objects: On success a list of photo album objects:
@ -839,7 +839,8 @@ A Mastodon [Status Entity](https://docs.joinmastodon.org/entities/Status/)
"poll": null, "poll": null,
"friendica": { "friendica": {
"title": "", "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/) A Mastodon [Status Entity](https://docs.joinmastodon.org/entities/Status/)
#### Example: #### Example:
`https://<server_name>/api/friendica/statuses/341/dislike` `https://<server_name>/api/friendica/statuses/341/undislike`
```json ```json
{ {
@ -913,7 +914,8 @@ A Mastodon [Status Entity](https://docs.joinmastodon.org/entities/Status/)
"poll": null, "poll": null,
"friendica": { "friendica": {
"title": "", "title": "",
"dislikes_count": 0 "dislikes_count": 0,
"disliked": false
} }
} }
``` ```

View File

@ -39,7 +39,7 @@ Extensions to the [Mastodon Instance::V2 Entities](https://docs.joinmastodon.org
* `codename`: The Friendica version code name * `codename`: The Friendica version code name
* `db_version`: The database schema version number * `db_version`: The database schema version number
Example: Example:
```json ```json
{ {
"domain": "friendicadevtest1.myportal.social", "domain": "friendicadevtest1.myportal.social",
@ -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_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. * `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. * `dislikes_count`: The number of dislikes that a status has accumulated according to the server.
* `disliked`: Whethere the user disliked the status.
Example: Example:
```json ```json
@ -117,7 +118,7 @@ Example:
"title": "", "title": "",
"delivery_data": { "delivery_data": {
"delivery_queue_count": 10, "delivery_queue_count": 10,
"delivery_queue_done": 3, "delivery_queue_done": 3,
"delivery_queue_failed": 0 "delivery_queue_failed": 0
}, },
"dislikes_count": 0 "dislikes_count": 0
@ -213,7 +214,7 @@ Example:
- Additionally to the static values `public`, `unlisted` and `private`, the `visibility` parameter can contain a numeric value with a group id. - Additionally to the static values `public`, `unlisted` and `private`, the `visibility` parameter can contain a numeric value with a group id.
- Additional field `quote_id` for the post that is being quote reshared - Additional field `quote_id` for the post that is being quote reshared
- Additional fields `friendica` for Friendica specific parameters: - Additional fields `friendica` for Friendica specific parameters:
- `title`: Explicitly sets the title for a post status, ignored if used on a comment status. For post statuses the legacy behavior is to use any "spoiler text" as the title if it is provided. If both the title and spoiler text are provided for a post status then they will each be used for their respective roles. If no title is provided then the legacy behavior will persist. If you want to create a post with no title but spoiler text then explicitly set the title but set it to an empty string `""`. - `title`: Explicitly sets the title for a post status, ignored if used on a comment status. For post statuses the legacy behavior is to use any "spoiler text" as the title if it is provided. If both the title and spoiler text are provided for a post status then they will each be used for their respective roles. If no title is provided then the legacy behavior will persist. If you want to create a post with no title but spoiler text then explicitly set the title but set it to an empty string `""`.
- [`GET /api/v1/statuses/:id`](https://docs.joinmastodon.org/methods/statuses/#get) - [`GET /api/v1/statuses/:id`](https://docs.joinmastodon.org/methods/statuses/#get)
- [`DELETE /api/v1/statuses/:id`](https://docs.joinmastodon.org/methods/statuses/#delete) - [`DELETE /api/v1/statuses/:id`](https://docs.joinmastodon.org/methods/statuses/#delete)
- [`GET /api/v1/statuses/:id/context`](https://docs.joinmastodon.org/methods/statuses/#context) - [`GET /api/v1/statuses/:id/context`](https://docs.joinmastodon.org/methods/statuses/#context)

View File

@ -177,6 +177,14 @@ class Status extends BaseFactory
'vid' => Verb::getID(Activity::LIKE), 'vid' => Verb::getID(Activity::LIKE),
'deleted' => false 'deleted' => false
]); ]);
$origin_dislike = ($count_like == 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([ $origin_announce = ($count_announce == 0) ? false : Post::exists([
'thr-parent-id' => $uriId, 'thr-parent-id' => $uriId,
'uid' => $uid, 'uid' => $uid,
@ -295,7 +303,7 @@ class Status extends BaseFactory
$aclFormatter = DI::aclFormatter(); $aclFormatter = DI::aclFormatter();
$delivery_data = $uid != $item['uid'] ? null : new FriendicaDeliveryData($item['delivery_queue_count'], $item['delivery_queue_done'], $item['delivery_queue_failed']); $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'])); $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); 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 = []; $attachments = [];
$in_reply = []; $in_reply = [];
$reshare = []; $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); return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $in_reply, $reshare, $friendica);
} }

View File

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