Chat object
Once you initialize the Chat SDK and create its instance, you'll get immediate access to the Chat
entity from which you can call the PubNub server.
To communicate with PubNub, you can use various methods. For example, you can use deleteChannel()
to remove a given channel or wherePresent()
to check which channels a given user is subscribed to.
By calling methods on the Chat
entity, you create chat objects like Channel
, User
, Message
, Membership
, ThreadChannel
, and ThreadMessage
. These objects also expose Chat API under various methods, letting you perform CRUD operations on messages, channels, users, the related user-channel membership, and many more.
Each of these entities comes with a set of "read-only" parameters you define when creating, modifying, and deleting specific channels, users, messages, or memberships in your chat app.
Properties
The Chat
interface has the following properties:
interface Chat {
val config: ChatConfiguration
val pubNub: PubNub
val currentUser: User
...
}
Parameter | Description |
---|---|
config Type: ChatConfiguration | ChatConfiguration contains chat app configuration settings, such as logLevel or typingTimeout that you can provide when initializing your chat app with the init() method. You can later directly access these properties, like: chat.storeUserActivityInterval . |
pubNub Type: PubNub | pubNub lets you access any Kotlin SDK method. For example, if you want to call a method available in the App Context API, you'd use chat.pubNub.getAllUUIDMetadata() . |
currentUser Type: User | User object representing current user. |
ChatConfiguration
includes these properties:
interface ChatConfiguration {
val logLevel: LogLevel
val typingTimeout: Duration
val storeUserActivityInterval: Duration
val storeUserActivityTimestamps: Boolean
val pushNotifications: PushNotificationsConfig
val rateLimitFactor: Int
val rateLimitPerChannel: Map<ChannelType, Duration>
val customPayloads: CustomPayloads?
}
PushNotificationsConfig
includes these properties:
class PushNotificationsConfig(
val sendPushes: Boolean,
val deviceToken: String?,
val deviceGateway: PNPushType,
val apnsTopic: String?,
val apnsEnvironment: PNPushEnvironment
)
To initialize the Chat SDK, you must provide two parameters: subscribeKey
, and userId
, while all other settings (mentioned above) are optional. Read the Configuration page for details.
Methods
You can call the following methods on the Chat
object.
Click on each method for more details.
createUser()
createDirectConversation()
createGroupConversation()
createPublicConversation()
currentUser
deleteChannel()
deleteUser()
emitEvent()
getEventsHistory()
getChannel()
getChannels()
getCurrentUserMentions()
getUnreadMessagesCounts()
getUser()
getUsers()
getPushChannels()
init()
isPresent()
listenForEvents()
markAllMessagesAsRead
registerPushChannels()
setRestrictions()
unregisterPushChannels()
unregisterAllPushChannels()
updateChannel()
updateUser()
wherePresent()
whoIsPresent()
Use case
For example, you can use the Chat
object methods to: