Merge pull request #4867 from nextcloud/bugfix/4866/avoidNpeInSendChatMessage

Avoid Npe in sendChatMessage
This commit is contained in:
Marcel Hibbe 2025-04-14 14:22:04 +00:00 committed by GitHub
commit 29348689a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -42,6 +42,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
@ -847,13 +848,17 @@ class OfflineFirstChatRepository @Inject constructor(
.catch { e -> .catch { e ->
Log.e(TAG, "Error when sending message", e) Log.e(TAG, "Error when sending message", e)
val failedMessage = chatDao.getTempMessageForConversation(internalConversationId, referenceId).first() val failedMessage = chatDao.getTempMessageForConversation(
failedMessage.sendingFailed = true internalConversationId,
chatDao.updateChatMessage(failedMessage) referenceId
).firstOrNull()
val failedMessageModel = failedMessage.asModel() failedMessage?.let {
_updateMessageFlow.emit(failedMessageModel) it.sendingFailed = true
chatDao.updateChatMessage(it)
val failedMessageModel = it.asModel()
_updateMessageFlow.emit(failedMessageModel)
}
emit(Result.failure(e)) emit(Result.failure(e))
} }
} }