[Goto Home](/docs/index.html)

# 🔒 GET `/reactions/:messageId`

## Description

- Returns the current user's reaction for the given message ID
- If no reaction exists, returns `reaction: null`

## Request Params

- **messageId** - MongoDB ObjectId of the message

## Response Body

```json
{
  "reaction": {
    "_id": "68c1a2b3e4d5f6789012345a",
    "user": "688c51572b675be4b88339d1",
    "chat": "68bee79857ab80b69867946b",
    "message": "68bef0d3e6ca043bb7fe353a",
    "reaction": "👍🏻",
    "at": "2025-09-08T15:10:00.000Z"
  }
}
```

Or when no reaction exists:

```json
{
  "reaction": null
}
```

# 🔒 PUT `/reactions/:messageId`

## Description

- Creates or updates the current user's reaction on the given message.
- User must be a participant of the message's chat.
- **If no reaction exists:** creates a new reaction, emits socket `reaction-created` to all chat participants, sends fcm notification to the message creator (if different user), returns **201 Created**.
- **If a reaction already exists with the same emoji:** returns that reaction with **200 OK** and does not send any notification or socket.
- **If a reaction already exists with a different emoji:** replaces the reaction string/emoji, then emits socket `reaction-created` and sends fcm notification as above, returns **200 OK**.

## Request Params

- **messageId** - MongoDB ObjectId of the message

## Request Body

```ts
{
  reaction?: string  // Optional emoji string (e.g. "👍🏻", "❤️", "🔥"). Defaults to "❤️" if not provided
}
```

## Response Body (201 Created)

When a new reaction was created:

```json
{
  "reaction": {
    "_id": "68c1a2b3e4d5f6789012345a",
    "user": "688c51572b675be4b88339d1",
    "chat": "68bee79857ab80b69867946b",
    "message": "68bef0d3e6ca043bb7fe353a",
    "reaction": "👍🏻",
    "at": "2025-09-08T15:10:00.000Z"
  }
}
```

## Response Body (200 OK)

Same shape as above when:
- The user already had a reaction with the **same** emoji (no update, no notification/socket), or
- The user had a reaction with a **different** emoji and it was replaced (notification and socket sent).

# 🔒 DELETE `/reactions/:messageId`

## Description

- Deletes the current user's reaction on the given message (idempotent)
- The reaction must have been created by the current user
- If no reaction exists, returns success (200) with message "reaction already removed"
- Emit socket notification `reaction-deleted` to all chat participants

## Request Params

- **messageId** - MongoDB ObjectId of the message

## Response Body

```json
{
  "message": "reaction deleted successfully"
}
```

Or when reaction was already absent (idempotent):

```json
{
  "message": "reaction already removed"
}
```

# Links

[Goto Home](/docs/index.html)
