Open automatically chat or call history screen when baresip icon with notification dot is touuched

This commit is contained in:
Juha Heinanen
2026-07-09 11:40:13 +03:00
parent bc4659859a
commit a5b2c14bdf
2 changed files with 29 additions and 4 deletions

View File

@ -102,7 +102,8 @@ class MainActivity : ComponentActivity() {
else else
exitProcess(0) exitProcess(0)
} }
} else }
else
handleServiceEvent(this, viewModel, first.event, first.params) handleServiceEvent(this, viewModel, first.event, first.params)
} }
} }
@ -254,6 +255,9 @@ class MainActivity : ComponentActivity() {
val route = "calls/${command.aor}" val route = "calls/${command.aor}"
navController.navigate(route) navController.navigate(route)
} }
is NavigationCommand.NavigateToChats -> {
navController.navigate("chats")
}
is NavigationCommand.NavigateToHome -> is NavigationCommand.NavigateToHome ->
navController.navigate("main") { navController.navigate("main") {
popUpTo("main") { inclusive = true } popUpTo("main") { inclusive = true }
@ -302,6 +306,21 @@ class MainActivity : ComponentActivity() {
intent.removeExtra("action") intent.removeExtra("action")
handleIntent(applicationContext, viewModel, intent, action) handleIntent(applicationContext, viewModel, intent, action)
} }
else if (intent.action == Intent.ACTION_MAIN && !atStartup) {
val activeNotifications = nm.activeNotifications
if (activeNotifications.any { it.id == CALL_MISSED_NOTIFICATION_ID }) {
val ua = BaresipService.uas.value.find { it.account.missedCalls }
if (ua != null)
viewModel.navigateToCalls(ua.account.aor)
}
else if (activeNotifications.any { it.id == MESSAGE_NOTIFICATION_ID }) {
val lastUnread = BaresipService.messages.lastOrNull { it.new }
if (lastUnread != null)
viewModel.onNewMessageReceived(lastUnread.aor, lastUnread.peerUri)
else
viewModel.navigateToChats()
}
}
} }
override fun onResume() { override fun onResume() {

View File

@ -16,6 +16,7 @@ import kotlinx.coroutines.launch
// Sealed class for type-safe navigation events // Sealed class for type-safe navigation events
sealed class NavigationCommand { sealed class NavigationCommand {
object NavigateToHome : NavigationCommand() object NavigateToHome : NavigationCommand()
object NavigateToChats : NavigationCommand()
data class NavigateToCalls(val aor: String) : NavigationCommand() data class NavigateToCalls(val aor: String) : NavigationCommand()
data class NavigateToChat(val aor: String, val peerUri: String) : NavigationCommand() data class NavigateToChat(val aor: String, val peerUri: String) : NavigationCommand()
} }
@ -31,11 +32,10 @@ class ViewModel: ViewModel() {
fun updateAorPeerMessage(aor: String, peerUri: String, message: String) { fun updateAorPeerMessage(aor: String, peerUri: String, message: String) {
val key = "$aor:$peerUri" val key = "$aor:$peerUri"
if (message.isEmpty()) { if (message.isEmpty())
messageDrafts.remove(key) messageDrafts.remove(key)
} else { else
messageDrafts[key] = message messageDrafts[key] = message
}
} }
data class DialerState( data class DialerState(
@ -162,4 +162,10 @@ class ViewModel: ViewModel() {
} }
} }
fun navigateToChats() {
viewModelScope.launch {
_navigationCommand.emit(NavigationCommand.NavigateToChats)
}
}
} }