Skip to content

Instantly share code, notes, and snippets.

@skydoves
Last active August 1, 2022 02:10
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 skydoves/466dd0e99e3d18b162e728527bca164e to your computer and use it in GitHub Desktop.
Save skydoves/466dd0e99e3d18b162e728527bca164e to your computer and use it in GitHub Desktop.
stream_chat_initializer
class StreamChatInitializer : Initializer<Unit> {
override fun create(context: Context) {
val logLevel = if (BuildConfig.DEBUG) ChatLogLevel.ALL else ChatLogLevel.NOTHING
val offlinePluginFactory = StreamOfflinePluginFactory(
config = Config(
backgroundSyncEnabled = true,
userPresence = true,
persistenceEnabled = true,
uploadAttachmentsNetworkType = UploadAttachmentsNetworkType.NOT_ROAMING
),
appContext = context
)
val chatClient = ChatClient.Builder(**YOUR API KEY**, context)
.withPlugin(offlinePluginFactory)
.logLevel(logLevel)
.build()
val user = User(
id = "stream",
name = "stream",
image = "https://placekitten.com/200/300"
)
val token = chatClient.devToken(user.id)
chatClient.connectUser(user, token).enqueue()
}
override fun dependencies(): List<Class<out Initializer<*>>> = emptyList()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment