Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class ChatCoordinator @Inject constructor(
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private val cluster = MutableStateFlow<AccountCluster?>(null)
private val _state = MutableStateFlow(ChatState())

private var syncJob: Job? = null
private var eventStreamCollectJob: Job? = null
private var eventStreamRetryJob: Job? = null
Expand Down Expand Up @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class ChatState(
val feed: List<ChatMetadata> = emptyList(),
val typingIndicators: Map<ChatId, Set<ActiveTypist>> = emptyMap(),
val feedSyncState: FeedSyncState = FeedSyncState.Idle,
val activeChat: ChatId? = null,
)

data class ChatSummary(
Expand Down
1 change: 1 addition & 0 deletions apps/flipcash/shared/notifications/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Loading