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.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.withTimeout
|
||||
|
||||
open class NotificationReplyReceiver : BroadcastReceiver() {
|
||||
@@ -60,13 +61,17 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
|
||||
replyScope.launch {
|
||||
try {
|
||||
withTimeout(5000L) {
|
||||
withContext(Dispatchers.IO) {
|
||||
val db =
|
||||
com.m57.hermescontrol.data.local.HermesDatabase
|
||||
.get(context)
|
||||
val dao = db.chatMessageDao()
|
||||
if (!dao.sessionExists(sessionId)) {
|
||||
android.util.Log.w("NotificationReply", "Ignoring reply for unknown session: $sessionId")
|
||||
return@withTimeout
|
||||
android.util.Log.w(
|
||||
"NotificationReply",
|
||||
"Ignoring reply for unknown session: $sessionId",
|
||||
)
|
||||
return@withContext
|
||||
}
|
||||
|
||||
HermesWsClient.sendMessage(sessionId, replyText)
|
||||
@@ -88,6 +93,7 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
|
||||
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
manager.notify(ChatNotificationService.PENDING_NOTIFICATION_ID, repliedNotification)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("NotificationReply", "Failed to process reply", e)
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user