feat(#116): add direct reply action to background notifications

This commit is contained in:
Hy4ri committed 2026-06-19 23:44:40 +03:00
1 parent ad508be0fa
commit ce5428f66b
3 files changed
+93 -10

No files matched your search

@@ -0,0 +1,43 @@
package com.m57.hermescontrol.notification
import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.app.RemoteInput
import com.m57.hermescontrol.R
import com.m57.hermescontrol.data.ws.HermesWsClient
class NotificationReplyReceiver : BroadcastReceiver() {
companion object {
const val KEY_TEXT_REPLY = "key_text_reply"
const val EXTRA_SESSION_ID = "extra_session_id"
}
override fun onReceive(
context: Context,
intent: Intent,
) {
val remoteInput = RemoteInput.getResultsFromIntent(intent)
val replyText = remoteInput?.getCharSequence(KEY_TEXT_REPLY)?.toString()
val sessionId = intent.getStringExtra(EXTRA_SESSION_ID)
if (!replyText.isNullOrBlank() && !sessionId.isNullOrBlank()) {
HermesWsClient.sendMessage(sessionId, replyText)
val repliedNotification =
NotificationCompat
.Builder(context, ChatNotificationService.CHAT_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Hermes")
.setContentText("Replied")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.build()
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.notify(ChatNotificationService.PENDING_NOTIFICATION_ID, repliedNotification)
}
}
}