Chat
The TSL Android SDK provides methods for fetching user and chat details of a specific show, enabling you to chat as a guest or as a registered user in your app.
Methods
Chat(jwt: String, isGuest: Boolean, callback: ((String?, UserTokenModel?))
Chat(jwt: String, isGuest: Boolean, callback: ((String?, UserTokenModel?))
Initialize the Chat feature.
- Parameters:
context
: The application context.jwt
: The JWT token for authentication.isGuest
: Indicates whether the user is a guest.showKey
: The unique identifier of the show.callback
: An optional callback function to be invoked upon completion.
Chat(jwt, isGuest, showKey) { errorMessage, userTokenModel -> }
publish(message: String, callback: ((String?, String?)))
publish(message: String, callback: ((String?, String?)))
Publish a message to chat.
- Parameters:
message
: The message that the user wants to send.callback
: A optional callback that will be called once the message is sent or an error is thrown.
Chat.publish(message) { error, timetoken -> }
subscribe(callback: ChatCallback)
subscribe(callback: ChatCallback)
Subscribe to a chat to get notified when there are changes.
- Parameters:
callback
: A callback that will be called once there's a change.
Chat.subscribe(object : Chat.ChatCallback {
override fun onMessageReceived(message: MessageModel) {}
})
getChatMessages(count: Int, start: Long?, callback: (List<MessageModel>?, Long?, String?))
getChatMessages(count: Int, start: Long?, callback: (List<MessageModel>?, Long?, String?))
Get the chat history.
- Parameters:
count
: The number of messages to fetch. Defaults to 25.start
: The starting time token for fetching messages. Used for pagination.callback
: An optional callback to return messages, the next start token, or an error.
Chat.getChatMessages { messageList, nextStartToken, error -> }
updateUser(newJwt: String, isGuest: Boolean, callback: ((String?, UserTokenModel?))
updateUser(newJwt: String, isGuest: Boolean, callback: ((String?, UserTokenModel?))
Update the current user.
- Parameters:
count
: The new JWT tokenisGuest
: Indicates whether the user is a guest.callback
: An optional callback function to be invoked upon completion.
Chat.updateUser(jwt, isGuest) { errorMessage, userTokenModel -> }
clean()
clean()
Cleans all the connections involved with chat.
Chat.clean()
countMessages(callback: (Map<String, Long>?) -> Unit)
countMessages(callback: (Map<String, Long>?) -> Unit)
Count unread messages.
- Parameters:
callback
: Callback to return the count of unread messages.
Chat.countMessages { unreadCount -> }
deleteMessage(timeToken: String, callback: ((Boolean, String?) -> Unit)?)
deleteMessage(timeToken: String, callback: ((Boolean, String?) -> Unit)?)
Delete a message.
- Parameters:
timeToken
: The time token of the message to be deleted.callback
: An optional callback to return success or error.
Chat.deleteMessage(timeToken) { isSuccess, error -> }
Listeners
onMessageReceived(message: MessageModel)
onMessageReceived(message: MessageModel)
Called when a new message is received.
- Parameters:
message
: TheMessageModel
instance containing the message details.
Chat.subscribe(object : Chat.ChatCallback { override fun onMessageReceived(message: MessageModel) {})
onMessageDeleted(messageId: Int)
onMessageDeleted(messageId: Int)
Called when a message is deleted.
- Parameters:
messageId
: Theid
of the message that has been deleted.
Chat.subscribe(object : Chat.ChatCallback { override fun onMessageDeleted(messageId: Int) {})
onStatusChange(error: String)
onStatusChange(error: String)
Called when a there is an error.
- Parameters:
error
: The error message as a string.
Chat.subscribe(object : Chat.ChatCallback { override fun onStatusChange(error: String) {})
Updated 4 months ago