> For the complete documentation index, see [llms.txt](https://geekyants-5.gitbook.io/flatandflatmates/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://geekyants-5.gitbook.io/flatandflatmates/api-server/routes/messages.md).

# Messages

**File Name** : messages.js\
**File Path** : /server/routes/messages.js\
This route is used to handle user's chat (messages) related queries. For example: fetching favourite users and messages, fetching specific user messages, loading more messages etc

## Fetch Users and Messages

<mark style="color:blue;">`GET`</mark> `/api/messages/usersMessages`

Fetches the users's chat list (named as Favourites) of users and messages&#x20;

#### Headers

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| Authorization | string | Authentication Token |

{% tabs %}
{% tab title="200 " %}

```javascript
{
   success: true,
   data: [
   {
      text,
      image,
      location,
      createdAt,
      senderId,
      receiverId,
   }
   . . . 
   . . .
   ]

}

or 
{
      success: true,
       message: 'No favourite users',
       data: null

}
```

{% endtab %}
{% endtabs %}

## Fetch Specific User Messages

<mark style="color:blue;">`GET`</mark> `/api/messages/?id=${_id}`

#### Headers

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| Authorization | string | Authentication Token |

{% tabs %}
{% tab title="200 " %}

```javascript
{
     success: true,
     data: {
     _id,
      profileUrl,
      fname,
      lname,
      messages: [
      {
      text,
      image,
      location,
      createdAt,
      senderId,
      receiverId,
      }
      . . . 
      . . . 
     ]
     }
}
```

{% endtab %}
{% endtabs %}

## Load More Messages

<mark style="color:blue;">`GET`</mark> `/api/messages/loadMoreMessages`

this loads the messages when user scrolls for older messages. initially only 20 messages are loaded.

#### Headers

| Name          | Type   | Description                                                    |
| ------------- | ------ | -------------------------------------------------------------- |
| msgBody       | object | msgBody contains length (messages length), userId, receiverId. |
| Authorization | string | Authentication Token                                           |

{% tabs %}
{% tab title="200 " %}

```
{
 messages : [
  {
  text,
  image,
  location,
  createdAt,
  senderId,
  receiverId,
  }
  . . . 
  . . . 
 ]
}
```

{% endtab %}
{% endtabs %}
