# Likes Extension

Lets users like and dislike notes.

Extension name: `pub.versia:likes`

The Likes extension adds support for users to like and dislike notes.

This extension requires [`pub.versia:social@1`](/extensions/social), which defines [Notes](/extensions/social#note).

## Definition

### Like

Likes are a way for users to show appreciation for a note.

- Type: `"pub.versia:likes/Like"`
- Fetch: `GET /.versia/v0.7/entities/pub.versia:likes/Like/{id}`

**Fields**

- `type` (`string`, required): **MUST** be `pub.versia:likes/Like`.
- `author` (`Reference`, required): [Reference](/entities#reference) to the [User](/entities/user) who created the Like.
- `target` (`Reference`, required): [Reference](/entities#reference) to the note being liked.

Inherited from [Entity](/entities):

- [`id`](/entities#entity-id) (`string`, required)
- [`created_at`](/entities#entity-created-at) (`RFC3339`, required)
- [`updated_at`](/entities#entity-updated-at) (`RFC3339`)
- [`extensions`](/entities#entity-extensions) (`Extensions`)

```jsonc title="Example Like"
{
    "id": "033gs6adpp000",
    "type": "pub.versia:likes/Like",
    "created_at": "2021-01-01T00:00:00Z",
    "author": "example.com:033wv9k6n0007",
    "target": "example.org:033w19vsgr000"
}
```

### Dislike

Dislikes are a way for users to show disapproval for a note.

- Type: `"pub.versia:likes/Dislike"`
- Fetch: `GET /.versia/v0.7/entities/pub.versia:likes/Dislike/{id}`

**Fields**

- `type` (`string`, required): **MUST** be `pub.versia:likes/Dislike`.
- `author` (`Reference`, required): [Reference](/entities#reference) to the [User](/entities/user) who created the Dislike.
- `target` (`Reference`, required): [Reference](/entities#reference) to the note being disliked.

Inherited from [Entity](/entities):

- [`id`](/entities#entity-id) (`string`, required)
- [`created_at`](/entities#entity-created-at) (`RFC3339`, required)
- [`updated_at`](/entities#entity-updated-at) (`RFC3339`)
- [`extensions`](/entities#entity-extensions) (`Extensions`)

```jsonc title="Example Dislike"
{
    "id": "033gs6adpp000",
    "type": "pub.versia:likes/Dislike",
    "created_at": "2021-01-01T00:00:00Z",
    "author": "example.com:033wv9k6n0007",
    "target": "example.org:033w19vsgr000"
}
```

## Behavior

Implementations **SHOULD** make sure that users cannot like and dislike the same note at the same time. If a user dislikes a note they have already liked, the like **SHOULD** be removed, and vice versa.

To undo a like or dislike, a [Delete](/entities/delete) entity **MUST** be used. The `deleted` property of the Delete entity **MUST** be a [Reference](/entities#reference) to the Like or Dislike entity to be removed.

## Delivery and Access

A sender **MUST** [deliver](/federation#delivery) Likes and Dislikes to the author of the [Note](/extensions/social#note) and, if the Note is public, to the subscribers of the user who sent them.

Any instance that [may fetch](/extensions/social#delivery-and-access) the Note, and the instance of the Note's author, may fetch a Like or Dislike.

## Collections

### User Collections

The Likes extension adds the following collections to the [User](/entities/user) entity:

- `pub.versia:likes/Likes`: [Reference Collection](/structures/collection#reference-collection) of all the notes the user has liked.
- `pub.versia:likes/Dislikes`: [Reference Collection](/structures/collection#reference-collection) of all the notes the user has disliked.

### Note Collections

The Likes extension adds the following collections to the [Note](/extensions/social#note) entity:

- `pub.versia:likes/Likes`: [Reference Collection](/structures/collection#reference-collection) of all the likes the note has received.
- `pub.versia:likes/Dislikes`: [Reference Collection](/structures/collection#reference-collection) of all the dislikes the note has received.

## Interaction Types

This extension registers the following [interaction types](/extensions/interaction-controls#interaction-types):

- `pub.versia:likes/like`, for liking a Note
- `pub.versia:likes/dislike`, for disliking a Note
