Skip to content

Commit

Permalink
just close clients in getClients
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 committed Feb 2, 2024
1 parent d0af7af commit dc13484
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions app/src/main/java/com/example/moderatedchat/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ fun ModeratedChatLayout(
val tokenExpiresInSecs = tokenExpiresAt - (System.currentTimeMillis() / 1000)
println("token expires in $tokenExpiresInSecs")
if (topicClient == null || tokenExpiresInSecs < 10) {
topicClient?.close()
cacheClient?.close()
getClients(userName, userId)
}
}
Expand Down Expand Up @@ -267,8 +265,6 @@ fun ModeratedChatLayout(
val resubscribeAfterSecs = 180L
delay(resubscribeAfterSecs * 1000)
subscribeJob?.cancelAndJoin()
topicClient?.close()
cacheClient?.close()
getClients(userName, userId)
print("resubscribing")
}
Expand Down Expand Up @@ -497,6 +493,9 @@ private fun getClients(
userName: String,
userId: UUID
) {
topicClient?.close()
cacheClient?.close()

// TODO: move api token to remember and pass in callback
getApiToken(userName, userId)
val credentialProvider =
Expand Down Expand Up @@ -581,8 +580,6 @@ private suspend fun publishMessage(
val tokenExpiresInSecs = tokenExpiresAt - (System.currentTimeMillis() / 1000)
if (tokenExpiresInSecs < 10) {
withContext(Dispatchers.IO) {
topicClient?.close()
cacheClient?.close()
getClients(userName, userId)
}
}
Expand Down

0 comments on commit dc13484

Please sign in to comment.