From 032172959862a01a4a128d7995ab6cc2ec8d02aa Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Mon, 1 Jun 2026 01:06:54 +0200 Subject: [PATCH] Graceful failures --- .../database/repository/DatabaseChatRepository.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/repository/DatabaseChatRepository.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/repository/DatabaseChatRepository.kt index cf67bdf0..d499b35e 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/repository/DatabaseChatRepository.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/repository/DatabaseChatRepository.kt @@ -4,21 +4,27 @@ import ac.cord.auxiliary.compose.database.AuxDatabase import ac.cord.auxiliary.compose.database.model.ChatRoom import ac.cord.auxiliary.compose.database.model.intermdiate.LocalChatRoom import ac.cord.auxiliary.compose.repository.ChatRepository +import co.touchlab.kermit.Logger import kotlinx.coroutines.CoroutineScope class DatabaseChatRepository( private val database: AuxDatabase, private val scope: CoroutineScope ): ChatRepository { + val logger = Logger.withTag(TAG) + override suspend fun getChatRoomByIdentifier(id: String): LocalChatRoom? { return database.chatRoomDao().findChatRoomById(id) } - override suspend fun getOrCreateChatRoom(publicKey: String, defaultSubject: String?): LocalChatRoom? { + override suspend fun getOrCreateChatRoom(publicKey: String, defaultSubject: String?): LocalChatRoom? = try { return database.nostrNip17Dao().getOrCreateChatRoom( publicKey, defaultSubject = defaultSubject ) + } catch (e: Throwable) { + logger.e("Error getting or creating chat", e) + return null } override fun updateChatRoomSubject( @@ -27,4 +33,8 @@ class DatabaseChatRepository( ): ChatRoom? { return null } + + companion object { + const val TAG = "DatabaseChatRepository" + } } \ No newline at end of file