From 8b08b057ed843c787fb3163af6c7262bf331621e Mon Sep 17 00:00:00 2001 From: Infi Date: Sun, 13 Oct 2024 12:44:26 +0200 Subject: [PATCH] fix: do not crash when attempting unread sync Signed-off-by: Infi --- .../java/chat/revolt/api/unreads/Unreads.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/chat/revolt/api/unreads/Unreads.kt b/app/src/main/java/chat/revolt/api/unreads/Unreads.kt index 15ef1533..f93dc8a3 100644 --- a/app/src/main/java/chat/revolt/api/unreads/Unreads.kt +++ b/app/src/main/java/chat/revolt/api/unreads/Unreads.kt @@ -1,5 +1,6 @@ package chat.revolt.api.unreads +import android.util.Log import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateOf import chat.revolt.api.RevoltAPI @@ -17,12 +18,17 @@ class Unreads { suspend fun sync() { channels.clear() channels.putAll( - syncUnreads().associate { - it.id.channel to ChannelUnread( - id = it.id.channel, - last_id = it.last_id, - mentions = it.mentions - ) + try { + syncUnreads().associate { + it.id.channel to ChannelUnread( + id = it.id.channel, + last_id = it.last_id, + mentions = it.mentions + ) + } + } catch (e: Exception) { + Log.e("Unreads", "Failed to sync unreads", e) + emptyMap() } ) hasLoaded.value = true