Graceful failures
This commit is contained in:
1 parent
d2c2892f05
commit
0321729598
1 file changed
+11
-1
+11
-1
@@ -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.ChatRoom
|
||||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalChatRoom
|
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalChatRoom
|
||||||
import ac.cord.auxiliary.compose.repository.ChatRepository
|
import ac.cord.auxiliary.compose.repository.ChatRepository
|
||||||
|
import co.touchlab.kermit.Logger
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
|
||||||
class DatabaseChatRepository(
|
class DatabaseChatRepository(
|
||||||
private val database: AuxDatabase,
|
private val database: AuxDatabase,
|
||||||
private val scope: CoroutineScope
|
private val scope: CoroutineScope
|
||||||
): ChatRepository {
|
): ChatRepository {
|
||||||
|
val logger = Logger.withTag(TAG)
|
||||||
|
|
||||||
override suspend fun getChatRoomByIdentifier(id: String): LocalChatRoom? {
|
override suspend fun getChatRoomByIdentifier(id: String): LocalChatRoom? {
|
||||||
return database.chatRoomDao().findChatRoomById(id)
|
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(
|
return database.nostrNip17Dao().getOrCreateChatRoom(
|
||||||
publicKey,
|
publicKey,
|
||||||
defaultSubject = defaultSubject
|
defaultSubject = defaultSubject
|
||||||
)
|
)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
logger.e("Error getting or creating chat", e)
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateChatRoomSubject(
|
override fun updateChatRoomSubject(
|
||||||
@@ -27,4 +33,8 @@ class DatabaseChatRepository(
|
|||||||
): ChatRoom? {
|
): ChatRoom? {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "DatabaseChatRepository"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user