Created
November 1, 2021 02:17
-
-
Save supertopoz/36e93bfee367b315c3e0d01073d1f30e to your computer and use it in GitHub Desktop.
How to implement read receipts in Sendbird Chat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sb.GroupChannel.getChannel(CHANNEL_URL, function(groupChannel, error) { | |
if (error) {} | |
groupChannel.markAsRead() | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"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 | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
) | |
}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
groupChannel.refresh(function(response, error) { | |
if (error) {} | |
groupChannel.markAsRead() | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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