Skip to content

Instantly share code, notes, and snippets.

@skydoves
Last active February 1, 2024 06:09
Show Gist options
  • Save skydoves/849afbef9efa31b6431dd43076c51046 to your computer and use it in GitHub Desktop.
Save skydoves/849afbef9efa31b6431dd43076c51046 to your computer and use it in GitHub Desktop.
channel_repository_impl
internal class ChannelRepositoryImpl @Inject constructor(
private val chatClient: ChatClient,
private val service: ChannelService,
private val geminiDao: GeminiDao,
) : ChannelRepository {
override suspend fun joinDefaultChannels(user: User): ApiResponse<List<GeminiChannel>> {
val response = service.geminiChannels()
.suspendOnSuccess {
data.forEach { geminiChannel ->
val channelClient = chatClient.channel(geminiChannel.id)
channelClient.create(
memberIds = listOf(geminiUser.id, user.id),
extraData = mapOf(
"name" to geminiChannel.name,
"image" to "https://avatars.githubusercontent.com/u/8597527?s=200&v=4.png",
)
).await().onSuccessSuspend {
geminiDao.insertGeminiChannel(geminiChannel.toEntity())
}
}
}
return response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment