Explicit IO context for DB/WS/notify path. replyScope already uses Dispatchers.IO; this makes the offload local and explicit. Keep return@withContext only because nothing follows the withContext block today.
This commit is contained in:
1 file changed
+8
-2
@@ -13,6 +13,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.withTimeout
|
import kotlinx.coroutines.withTimeout
|
||||||
|
|
||||||
open class NotificationReplyReceiver : BroadcastReceiver() {
|
open class NotificationReplyReceiver : BroadcastReceiver() {
|
||||||
@@ -60,13 +61,17 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
|
|||||||
replyScope.launch {
|
replyScope.launch {
|
||||||
try {
|
try {
|
||||||
withTimeout(5000L) {
|
withTimeout(5000L) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
val db =
|
val db =
|
||||||
com.m57.hermescontrol.data.local.HermesDatabase
|
com.m57.hermescontrol.data.local.HermesDatabase
|
||||||
.get(context)
|
.get(context)
|
||||||
val dao = db.chatMessageDao()
|
val dao = db.chatMessageDao()
|
||||||
if (!dao.sessionExists(sessionId)) {
|
if (!dao.sessionExists(sessionId)) {
|
||||||
android.util.Log.w("NotificationReply", "Ignoring reply for unknown session: $sessionId")
|
android.util.Log.w(
|
||||||
return@withTimeout
|
"NotificationReply",
|
||||||
|
"Ignoring reply for unknown session: $sessionId",
|
||||||
|
)
|
||||||
|
return@withContext
|
||||||
}
|
}
|
||||||
|
|
||||||
HermesWsClient.sendMessage(sessionId, replyText)
|
HermesWsClient.sendMessage(sessionId, replyText)
|
||||||
@@ -88,6 +93,7 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
|
|||||||
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
manager.notify(ChatNotificationService.PENDING_NOTIFICATION_ID, repliedNotification)
|
manager.notify(ChatNotificationService.PENDING_NOTIFICATION_ID, repliedNotification)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
android.util.Log.e("NotificationReply", "Failed to process reply", e)
|
android.util.Log.e("NotificationReply", "Failed to process reply", e)
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in new issue
Block a user