diff --git a/apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/ChatCoordinator.kt b/apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/ChatCoordinator.kt index f82f28b2a..bc0020cad 100644 --- a/apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/ChatCoordinator.kt +++ b/apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/ChatCoordinator.kt @@ -82,7 +82,6 @@ class ChatCoordinator @Inject constructor( private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob()) private val cluster = MutableStateFlow(null) private val _state = MutableStateFlow(ChatState()) - private var syncJob: Job? = null private var eventStreamCollectJob: Job? = null private var eventStreamRetryJob: Job? = null @@ -264,6 +263,14 @@ class ChatCoordinator @Inject constructor( return messagingController.advancePointer(chatId, PointerType.READ, messageId) } + fun setActiveChatId(chatId: ChatId?) { + _state.update { it.copy(activeChat = chatId) } + } + + fun isActiveChat(chatId: ChatId): Boolean { + return _state.value.activeChat == chatId + } + fun dismissNotifications(chatId: ChatId) { notificationManager.cancel(chatId.hashCode()) } diff --git a/apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/ChatState.kt b/apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/ChatState.kt index e07850d72..8ea8c2119 100644 --- a/apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/ChatState.kt +++ b/apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/ChatState.kt @@ -9,6 +9,7 @@ data class ChatState( val feed: List = emptyList(), val typingIndicators: Map> = emptyMap(), val feedSyncState: FeedSyncState = FeedSyncState.Idle, + val activeChat: ChatId? = null, ) data class ChatSummary( diff --git a/apps/flipcash/shared/notifications/build.gradle.kts b/apps/flipcash/shared/notifications/build.gradle.kts index 1d805dcf9..c371850af 100644 --- a/apps/flipcash/shared/notifications/build.gradle.kts +++ b/apps/flipcash/shared/notifications/build.gradle.kts @@ -9,6 +9,7 @@ android { dependencies { implementation(project(":apps:flipcash:shared:authentication")) + implementation(project(":apps:flipcash:shared:chat")) implementation(project(":apps:flipcash:shared:contacts")) implementation(project(":apps:flipcash:shared:persistence:sources")) implementation(project(":apps:flipcash:shared:phone")) diff --git a/apps/flipcash/shared/notifications/src/main/kotlin/com/flipcash/app/notifications/NotificationService.kt b/apps/flipcash/shared/notifications/src/main/kotlin/com/flipcash/app/notifications/NotificationService.kt index 89581aa14..af575e5d5 100644 --- a/apps/flipcash/shared/notifications/src/main/kotlin/com/flipcash/app/notifications/NotificationService.kt +++ b/apps/flipcash/shared/notifications/src/main/kotlin/com/flipcash/app/notifications/NotificationService.kt @@ -24,6 +24,7 @@ import com.flipcash.app.auth.AuthManager import com.flipcash.app.contacts.ContactCoordinator import com.flipcash.app.contacts.ContactResolver import com.flipcash.app.core.util.Linkify +import com.flipcash.shared.chat.ChatCoordinator import com.flipcash.app.tokens.TokenCoordinator import com.flipcash.services.controllers.PushController import com.flipcash.services.models.NavigationTrigger @@ -74,6 +75,9 @@ class NotificationService : FirebaseMessagingService(), @Inject lateinit var contactResolver: ContactResolver + @Inject + lateinit var chatCoordinator: ChatCoordinator + override fun onNewToken(token: String) { super.onNewToken(token) authenticateIfNeeded { @@ -142,6 +146,8 @@ class NotificationService : FirebaseMessagingService(), notificationManager.createNotificationChannel(channel) val chatId = (payload?.navigation as? NavigationTrigger.Chat)?.chatId + if (chatId != null && chatCoordinator.isActiveChat(chatId)) return + val groupKey = payload?.groupKey?.takeIf { it.isNotEmpty() } val builder = NotificationCompat.Builder(this, channel.id)