Skip to content

Instantly share code, notes, and snippets.

@supertopoz
Created November 1, 2021 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supertopoz/36e93bfee367b315c3e0d01073d1f30e to your computer and use it in GitHub Desktop.
Save supertopoz/36e93bfee367b315c3e0d01073d1f30e to your computer and use it in GitHub Desktop.
How to implement read receipts in Sendbird Chat
sb.GroupChannel.getChannel(CHANNEL_URL, function(groupChannel, error) {
if (error) {}
groupChannel.markAsRead()
});
[
{
"nickname": "UserA",
"plainProfileUrl": "https://static.sendbird.com/sample/user_sdk/user_sdk_04.png",
"userId": "UserA",
"connectionStatus": "online",
"lastSeenAt": 0,
"metaData": {
"marriage": "N",
"location": "Washingtonx",
"hasSomeone": "Y"
},
"isActive": true,
"friendDiscoveryKey": null,
"friendName": null,
"_preferredLanguages": null,
"requireAuth": false,
"state": "joined",
"role": "none",
"isMuted": false,
"isBlockedByMe": false,
"isBlockingMe": false
}
]
var sb = new SendBird({appId: APP_ID});
var channelHandler = new sb.ChannelHandler();
channelHandler.onReadReceiptUpdated = function(groupChannel) {
//For each message in the message view
var readMembers = groupChannel.getReadMembers(MESSAGE);
};
sb.addChannelHandler(UNIQUE_HANDLER_ID, channelHandler);
// There should only be one single instance per channel view.
var listQuery = groupChannel.createPreviousMessageListQuery();
var myMessageObjects = []
// Retrieving previous messages.
listQuery.load(function(messages, error) {
if (error) {}
// Retrieving previous messages.
messages.forEach(message => {
const readMembers = groupChannel.getReadMembers(message);
myMessageObjects.push(
{
message: message,
readMembers: readMembers
}
)
})
});
var sb = new SendBird({appId: APP_ID});
var channelHandler = new sb.ChannelHandler();
channelHandler.onMessageReceived = function(channel, message) {
//if message view is visible and user is shown the message incoming message
channel.markAsRead()
};
// Add this channel event handler to the `SendBird` instance.
sb.addChannelHandler(UNIQUE_HANDLER_ID, channelHandler);
groupChannel.refresh(function(response, error) {
if (error) {}
groupChannel.markAsRead()
});
const params = new sb.UserMessageParams();
params.message = TEXT_MESSAGE;
groupChannel.sendUserMessage(params, function(userMessage, error) {
if (error) {}
groupChannel.markAsRead()
const messageId = userMessage.messageId;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment