Merge pull request #239 from Hy4ri/fix/issue-214-notification-tap-navigation
fix(#214): notification tap now navigates to the correct session
This commit is contained in:
4 files changed
+28
-3
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package com.m57.hermescontrol
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
@@ -9,17 +10,22 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.m57.hermescontrol.data.local.AuthManager
|
||||
import com.m57.hermescontrol.notification.NotificationReplyReceiver
|
||||
import com.m57.hermescontrol.theme.HermesControlTheme
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
// Observable state so both onCreate and onNewIntent updates flow to Compose
|
||||
private var notificationSessionId by mutableStateOf<String?>(null)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Read notification tap sessionId (if any) from the intent that launched us
|
||||
val notificationSessionId = intent?.getStringExtra(NotificationReplyReceiver.EXTRA_SESSION_ID)
|
||||
notificationSessionId = intent?.getStringExtra(NotificationReplyReceiver.EXTRA_SESSION_ID)
|
||||
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
@@ -40,4 +46,13 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
// When a notification tap arrives while the app is already running
|
||||
// (task exists in background), Android delivers the intent here instead
|
||||
// of onCreate. Update the observable state so Compose recomposes
|
||||
// and ChatScreen's LaunchedEffect switches to the correct session.
|
||||
notificationSessionId = intent.getStringExtra(NotificationReplyReceiver.EXTRA_SESSION_ID)
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,7 @@ class ChatNotificationService : Service() {
|
||||
|
||||
private fun buildContentIntent(sessionId: String?): PendingIntent {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
if (!sessionId.isNullOrBlank()) {
|
||||
intent.putExtra(NotificationReplyReceiver.EXTRA_SESSION_ID, sessionId)
|
||||
}
|
||||
|
||||
@@ -62,7 +62,13 @@ class ChannelsViewModel : ViewModel() {
|
||||
}
|
||||
when (result) {
|
||||
is NetworkResult.Success -> {
|
||||
_uiState.update { it.copy(isLoading = false, toastMessage = "$platformId configured successfully") }
|
||||
val message = "$platformId configured successfully — restart the gateway for changes to take effect"
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
isLoading = false,
|
||||
toastMessage = message,
|
||||
)
|
||||
}
|
||||
loadPlatforms()
|
||||
}
|
||||
|
||||
|
||||
@@ -915,7 +915,10 @@ class E2eIntegrationTest {
|
||||
viewModel.configurePlatform("telegram", mapOf("bot_token" to "xyz"))
|
||||
advanceUntilIdle()
|
||||
|
||||
assertEquals("telegram configured successfully", viewModel.uiState.value.toastMessage)
|
||||
assertEquals(
|
||||
"telegram configured successfully — restart the gateway for changes to take effect",
|
||||
viewModel.uiState.value.toastMessage,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user