fix: do not crash when attempting unread sync

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2024-10-13 12:44:26 +02:00
parent a302c2d13c
commit 8b08b057ed
1 changed files with 12 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package chat.revolt.api.unreads package chat.revolt.api.unreads
import android.util.Log
import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import chat.revolt.api.RevoltAPI import chat.revolt.api.RevoltAPI
@ -17,6 +18,7 @@ class Unreads {
suspend fun sync() { suspend fun sync() {
channels.clear() channels.clear()
channels.putAll( channels.putAll(
try {
syncUnreads().associate { syncUnreads().associate {
it.id.channel to ChannelUnread( it.id.channel to ChannelUnread(
id = it.id.channel, id = it.id.channel,
@ -24,6 +26,10 @@ class Unreads {
mentions = it.mentions mentions = it.mentions
) )
} }
} catch (e: Exception) {
Log.e("Unreads", "Failed to sync unreads", e)
emptyMap()
}
) )
hasLoaded.value = true hasLoaded.value = true
} }