# Namespace: chat

## QB. chat

### Namespaces

dialog
helpers
message
muc
privacylist
roster

### Methods

#### staticQB.chat.connect(params, callback)

modules/chat/qbChat.js, line 707
  self.connection to the chat(read more)

  Name | Type | Description
  --- | --- | ---
  `params` | Object | Connect to the chat parameters.
  Name | Type | Description
  --- | --- | ---
  `userId` | Number | Connect to the chat by user id (use instead params.email and params.jid).
  `jid` | String | Connect to the chat by user jid (use instead params.userId and params.email).
  `email` | String | Connect to the chat by user's email (use instead params.userId and params.jid).
  `password` | String | The user's password or session token.
  `callback` | chatConnectCallback | The chatConnectCallback callback.

#### staticQB.chat.disconnect()

modules/chat/qbChat.js, line 1530
  Disconnect from the Chat(read more).

#### staticQB.chat.getLastUserActivity(jid_or_user_id)

modules/chat/qbChat.js, line 1324
  Send query to get last user activity by QB.chat.onLastUserActivityListener(userId, seconds)(read more).

  Name | Type | Description
  --- | --- | ---
  `jid_or_user_id` | Number | String | The user id or jid, that the last activity we want to know.

#### staticQB.chat.onConfirmSubscribeListener(userId)

modules/chat/qbChat.js, line 257
  Receive confirm request(read more).

  Name | Type | Description
  --- | --- | ---
  `userId` | Number | The sender ID

#### staticQB.chat.onContactListListener(userId, type)

modules/chat/qbChat.js, line 242
  Receive user status (online / offline)(read more).

  Name | Type | Description
  --- | --- | ---
  `userId` | Number | The sender ID.
  `type` | String | If user leave the chat, type will be 'unavailable'.

#### staticQB.chat.onDeliveredStatusListener(messageId, dialogId, userId)

modules/chat/qbChat.js, line 193
  Receive delivery confirmations(read more).

  Name | Type | Description
  --- | --- | ---
  `messageId` | String | Delivered message id.
  `dialogId` | String | The dialog id.
  `userId` | Number | User id.

#### staticQB.chat.onDisconnectedListener()

modules/chat/qbChat.js, line 279
  Run after disconnect from chat({@linkhttps://docs.quickblox.com/docs/js-chat-connection#disconnect-from-chat-server read more}).

#### staticQB.chat.onJoinOccupant(dialogId, userId)

modules/chat/qbChat.js, line 226
  You will receive this callback when some user joined group chat dialog you are in.

  Name | Type | Description
  --- | --- | ---
  `dialogId` | String | An id of chat dialog that user joined.
  `userId` | Number | An id of user who joined chat dialog.

#### staticQB.chat.onKickOccupant(dialogId, initiatorUserId)

modules/chat/qbChat.js, line 218
  You will receive this callback when you are in group chat dialog(joined) and other user (chat dialog's creator) removed you from occupants.

  Name | Type | Description
  --- | --- | ---
  `dialogId` | String | An id of chat dialog where you was kicked from.
  `initiatorUserId` | Number | An id of user who has kicked you.

#### staticQB.chat.onLastUserActivityListener(userId, seconds)

modules/chat/qbChat.js, line 271
  Receive user's last activity (time ago).

  Name | Type | Description
  --- | --- | ---
  `userId` | Number | The user's ID which last activity time we receive.
  `seconds` | Number | Time ago (last activity in seconds or 0 if user online or undefined if user never registered in chat).

#### staticQB.chat.onLeaveOccupant(dialogId, userId)

modules/chat/qbChat.js, line 234
  You will receive this callback when some user left group chat dialog you are in.

  Name | Type | Description
  --- | --- | ---
  `dialogId` | String | An id of chat dialog that user left.
  `userId` | Number | An id of user who left chat dialog.

#### staticQB.chat.onMessageErrorListener(messageId, error)

modules/chat/qbChat.js, line 168
  Blocked entities receive an error when try to chat with a user in a 1-1 chat and receivie nothing in a group chat.

  Name | Type | Description
  --- | --- | ---
  `messageId` | Number | The message id.
  `error` | Object | The error object.

#### staticQB.chat.onMessageListener(userId, message)

modules/chat/qbChat.js, line 160
  You need to set onMessageListener function, to get messages(read more).

  Name | Type | Description
  --- | --- | ---
  `userId` | Number | Sender id.
  `message` | Object | The message model object.

#### staticQB.chat.onMessageTypingListener(isTyping, userId, dialogId)

modules/chat/qbChat.js, line 184
  Show typing status in chat or groupchat(read more).

  Name | Type | Description
  --- | --- | ---
  `isTyping` | Boolean | Typing Status (true - typing, false - stop typing).
  `userId` | Number | Typing user id.
  `dialogId` | String | The dialog id.

#### staticQB.chat.onReadStatusListener(messageId, dialogId, userId)

modules/chat/qbChat.js, line 202
  You can manage 'read' notifications in chat(read more).

  Name | Type | Description
  --- | --- | ---
  `messageId` | String | Read message id.
  `dialogId` | String | The dialog id.
  `userId` | Number | User Id.

#### staticQB.chat.onReconnectListener()

modules/chat/qbChat.js, line 285
  By default Javascript SDK reconnects automatically when connection to server is lost(read more).

#### staticQB.chat.onRejectSubscribeListener(userId)

modules/chat/qbChat.js, line 264
  Receive reject request(read more).

  Name | Type | Description
  --- | --- | ---
  `userId` | Number | The sender ID

#### staticQB.chat.onSentMessageCallback(messageLost, messageSent)

modules/chat/qbChat.js, line 176
  This feature defines an approach for ensuring is the message delivered to the server. This feature is unabled by default(read more).

  Name | Type | Description
  --- | --- | ---
  `messageLost` | Object | The lost message model object (Fail).
  `messageSent` | Object | The sent message model object (Success).

#### staticQB.chat.onSubscribeListener(userId)

modules/chat/qbChat.js, line 250
  Receive subscription request(read more).

  Name | Type | Description
  --- | --- | ---
  `userId` | Number | The sender ID.

#### staticQB.chat.onSystemMessageListener(message)

modules/chat/qbChat.js, line 211
  These messages work over separated channel and won't be mixed with the regular chat messages(read more).

  Name | Type | Description
  --- | --- | ---
  `message` | Object | The system message model object. Always have type: 'headline'.

#### staticQB.chat.send(jid_or_user_id, message){String}

modules/chat/qbChat.js, line 1082
  Send message to 1 to 1 or group dialog(read more).

  Name | Type | Description
  --- | --- | ---
  `jid_or_user_id` | String | Number | Use opponent id for 1 to 1 chat, and room jid for group chat.
  `message` | Object | The message object.

  ##### Returns:

  Type | Description
  --- | ---
  String | messageId - The current message id (was generated by SDK).

#### staticQB.chat.sendIsStopTypingStatus(jid_or_user_id)

modules/chat/qbChat.js, line 1222
  Send is stop typing status(read more).

  Name | Type | Description
  --- | --- | ---
  `jid_or_user_id` | String | Number | Use opponent id for 1 to 1 chat, and room jid for group chat.

#### staticQB.chat.sendIsTypingStatus(jid_or_user_id)

modules/chat/qbChat.js, line 1194
  Send is typing status(read more).

  Name | Type | Description
  --- | --- | ---
  `jid_or_user_id` | String | Number | Use opponent id for 1 to 1 chat, and room jid for group chat.

#### staticQB.chat.sendReadStatus(params)

modules/chat/qbChat.js, line 1290
  Send is read status(read more).

  Name | Type | Description
  --- | --- | ---
  `params` | Object | Object of parameters.
  Name | Type | Description
  --- | --- | ---
  `userId` | Number | The receiver id.
  `messageId` | Number | The delivered message id.
  `dialogId` | Number | The dialog id.

#### staticQB.chat.sendSystemMessage(jid_or_user_id, message){String}

modules/chat/qbChat.js, line 1145
  Send system message (system notification) to 1 to 1 or group dialog(read more).

  Name | Type | Description
  --- | --- | ---
  `jid_or_user_id` | String | Number | Use opponent id for 1 to 1 chat, and room jid for group chat.
  `message` | Object | The message object.

  ##### Returns:

  Type | Description
  --- | ---
  String | messageId - The current message id (was generated by SDK).