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?))

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 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 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?))

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?))

Update the current user.

  • Parameters:
    • count: The new JWT token
    • isGuest: Indicates whether the user is a guest.
    • callback: An optional callback function to be invoked upon completion.
Chat.updateUser(jwt, isGuest) { errorMessage, userTokenModel -> }

clean()

Cleans all the connections involved with chat.

Chat.clean()

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)?)

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)

Called when a new message is received.

  • Parameters:
    • message: The MessageModel instance containing the message details.
Chat.subscribe(object : Chat.ChatCallback { override fun onMessageReceived(message: MessageModel) {})

onMessageDeleted(messageId: Int)

Called when a message is deleted.

  • Parameters:
    • messageId: The id of the message that has been deleted.
Chat.subscribe(object : Chat.ChatCallback { override fun onMessageDeleted(messageId: Int) {})

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) {})