From 4025cbceecd1912bdc3039bdce173617339c87ab Mon Sep 17 00:00:00 2001 From: dalbodeule <11470513+dalbodeule@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:51:41 +0900 Subject: [PATCH] add /user/{uid} call on web module. - fix some bug with use Pair --- .../mori/chzzk_bot/chatbot/chzzk/Connector.kt | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/Connector.kt b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/Connector.kt index 9577585..886aea8 100644 --- a/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/Connector.kt +++ b/chatbot/src/main/kotlin/space/mori/chzzk_bot/chatbot/chzzk/Connector.kt @@ -30,7 +30,6 @@ object Connector { private val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java) fun getChannel(channelId: String): ChzzkChannel? = chzzk.getChannel(channelId) - fun getChannelAndUser(channelId: String): Pair? = pair(chzzk.getChannel(channelId), UserService.getUser(channelId)) init { @@ -38,17 +37,22 @@ object Connector { dispatcher.subscribe(GetUserEvents::class) { if (it.type == GetUserType.REQUEST) { CoroutineScope(Dispatchers.Default).launch { - val channel = getChannelAndUser(it.uid ?: "") + val channel = getChannel(it.uid ?: "") if(channel == null) dispatcher.post(GetUserEvents( GetUserType.NOTFOUND, null, null, null, null )) - else dispatcher.post(GetUserEvents( - GetUserType.RESPONSE, - channel.first.channelId, - channel.first.channelName, - LiveStatusService.getLiveStatus(channel.second!!)?.status ?: false, - channel.first.channelImageUrl - )) + else { + val user = UserService.getUser(channel.channelId) + dispatcher.post( + GetUserEvents( + GetUserType.RESPONSE, + channel.channelId, + channel.channelName, + LiveStatusService.getLiveStatus(user!!)?.status ?: false, + channel.channelImageUrl + ) + ) + } } } }