-
-
Save skydoves/849afbef9efa31b6431dd43076c51046 to your computer and use it in GitHub Desktop.
channel_repository_impl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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