Skip to send message when device is offline

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2025-01-02 15:07:53 +01:00
parent f62941f6aa
commit cca4e69cea
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -803,8 +803,14 @@ class OfflineFirstChatRepository @Inject constructor(
replyTo: Int,
sendWithoutNotification: Boolean,
referenceId: String
): Flow<Result<ChatMessage?>> =
flow {
): Flow<Result<ChatMessage?>> {
if (!monitor.isOnline.first()) {
return flow {
emit(Result.failure(IOException("Skipped to send message as device is offline")))
}
}
return flow {
val response = network.sendChatMessage(
credentials,
url,
@ -842,6 +848,7 @@ class OfflineFirstChatRepository @Inject constructor(
emit(Result.failure(e))
}
}
override suspend fun resendChatMessage(
credentials: String,
@ -932,7 +939,7 @@ class OfflineFirstChatRepository @Inject constructor(
it.referenceId.orEmpty()
).collect { result ->
if (result.isSuccess) {
Log.d(TAG, "sent temp message")
Log.d(TAG, "Sent temp message")
} else {
Log.e(TAG, "Failed to send temp message")
}