Learn how to send and receive messages, mark messages as delivered or read, etc.
addDialogMessageListener()
method. The listener enables the app to listen to the incoming message.
join()
method before you start chatting in a dialog. Once the dialog is joined, you can receive/send messages. See this section to learn how to join the dialog.saveToHistory
as true
to save the message on the server. If the saveToHistory
is set as false
, the message won’t be saved on the server. However, the message will be delivered to the user in either case.message
. Using these items, you can implement the ability for a user to send self-location information to another user or notification messages signifying that a user has left a group, etc.
Argument | Required | Description |
---|---|---|
qbChatMessage | yes | Specifies message fields that should be set. |
qbChatMessage
:
Field | Required | Description |
---|---|---|
saveToHistory | no | Specifies if the message will be saved on the server. Set the saveToHistory as true to save the message on the server. |
body | no | A message text. |
property | no | Extra data. Specify any key-value pairs. In each pair, the key and value are both string values. |
getDialogMessages()
method. The request below will return messages for a specific dialog limited to the 100 dialogs on the page.
markAsRead
parameter as true
. If you decide not to mark chat messages as read, just set markAsRead
parameter as false
.QBMessageGetBuilder
class.
If you want to get a paginated list of messages from the server, you can set the following pagination parameters in the QBMessageGetBuilder
class.
Pagination parameter | Description |
---|---|
skip | Skip N records in search results. Useful for pagination. Default (if not specified): 0. |
limit | Limit search results to N records. Useful for pagination. Default value: 100. |
Search operators | Applicable to types | Applicable to fields | Description |
---|---|---|---|
lt(field, searchValue) | number, string, date | date_sent, sender_id, recipient_id, updated_at | Less Than operator. |
lte(field, searchValue) | number, string, date | date_sent, sender_id, recipient_id, updated_at | Less Than or Equal to operator. |
gt(field, searchValue) | number, string, date | date_sent, sender_id, recipient_id, updated_at | Greater Than operator. |
gte(field, searchValue) | number, string, date | date_sent, sender_id, recipient_id, updated_at | Greater Than or Equal to operator. |
ne(field, searchValue) | number, string, date | _id, message, date_sent, sender_id, recipient_id | Not Equal to operator. |
in(field, searchValue) | number, string, date | date_sent, sender_id, recipient_id | IN array operator. |
nin(field, searchValue) | number, string, date | date_sent, sender_id, recipient_id | Not IN array operator. |
or(field, searchValue) | number, string, date | date_sent, sender_id, recipient_id | All records that contain a value 1 or value 2. |
ctn(field, searchValue) | string | message | All records that contain a particular substring. |
Sort operator | Applicable to types | Description |
---|---|---|
sortAsc(field) | All types | Search results will be sorted in ascending order by the specified field. |
sortDesc(field) | All types | Search results will be sorted in descending order by the specified field. |
updateMessage()
method below.
updateMessage()
method to mark message as delivered or read on the server. As a result, the ID of the user who has received the message or read it will be added to the array of delivered_ids
/read_ids
field, in the message model. However, the server won’t notify the sender with delivery or read receipt that informs about the change in the message model.occupantIDs
can delete a message from the dialog. As a result, the message will be deleted from the current user history, without affecting the histories of other users.
The owner of the dialog can completely remove messages from all users’ histories. This is achieved by setting the forceDelete
parameter to true
.
Argument | Required | Description |
---|---|---|
messagesIDs | yes | A set of strings with messages IDs. |
forceDelete | yes | A boolean parameter. Delete message for everyone. Set it as true to perform. Only the owner can do it. |
QBChatDialogMessageSentListener
.
chatService.login()
because the Stream Management is initialized while Chat login is performed.The Stream Management defines an extension for active management of a stream between a client and server, including features for stanza acknowledgments.QBMessageStatusListener()
.
deliverMessage()
method to mark a message as delivered. As a result, the server will notify a sender about the delivery receipt.
markable
as true
using the sendMessage()
method if you want, as a sender, to receive message delivery receipts from other recipients. Thus, the markable
parameter enables the sender to request the delivery receipt. It also enables the recipient to confirm the message delivery. However, if markable
is false
or omitted, then you can notify a sender about the delivery receipt using the deliverMessage()
method.
getDialogMessages()
method. See this section to learn how to retrieve chat history.QBMessageStatusListener()
.
readMessage()
method to mark a message as read. As a result, the server will notify a sender about the read receipt.
getDialogMessages()
method. See this section to learn how to retrieve chat history.QBChatDialogTypingListener()
.
QBChatDialogTypingListener()
.
sendIsTyping()
method.
sendStopTypingNotification()
method.
QBSystemMessageListener
listener. See how to add the listener in the snippet below.
System messages are also not shown in the dialog history and, consequently, are not stored on the server. This means that these messages will be delivered only to online users. Send system messages using the sendSystemMessage()
method.
Argument | Description |
---|---|
qbChatMessage | Specifies system message fields that should be set. |
qbChatMessage
:
Field | Required | Description |
---|---|---|
recipientId | yes | ID of the recipient. |
dialogId | no | ID of the dialog. |
property | no | Extra data. Specify any key-value pairs. In each pair, the key and value are both string values. |