Профиль, редактирование без аватара
This commit is contained in:
@@ -11,7 +11,18 @@ class ActiveChatTracker @Inject constructor() {
|
||||
private val _currentChatId = MutableStateFlow<String?>(null)
|
||||
val currentChatId: StateFlow<String?> = _currentChatId.asStateFlow()
|
||||
|
||||
private val _totalUnreadCount = MutableStateFlow(0)
|
||||
val totalUnreadCount: StateFlow<Int> = _totalUnreadCount.asStateFlow()
|
||||
|
||||
fun setChatId(chatId: String?) {
|
||||
_currentChatId.value = chatId
|
||||
}
|
||||
|
||||
fun setTotalUnreadCount(count: Int) {
|
||||
_totalUnreadCount.value = count
|
||||
}
|
||||
|
||||
fun incrementUnreadCount() {
|
||||
_totalUnreadCount.value += 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ class ForkFirebaseMessagingService : FirebaseMessagingService() {
|
||||
@Inject
|
||||
lateinit var authApi: AuthApi
|
||||
|
||||
@Inject
|
||||
lateinit var activeChatTracker: ActiveChatTracker
|
||||
|
||||
private val job = SupervisorJob()
|
||||
private val scope = CoroutineScope(Dispatchers.IO + job)
|
||||
|
||||
@@ -48,11 +51,11 @@ class ForkFirebaseMessagingService : FirebaseMessagingService() {
|
||||
val chatId = message.data["chatId"]
|
||||
val messageId = message.data["id"] ?: message.messageId
|
||||
|
||||
NotificationHelper.showNotification(this, title, body, type, chatId, messageId?.hashCode())
|
||||
NotificationHelper.showNotification(this, title, body, type, chatId, messageId?.hashCode(), activeChatTracker.totalUnreadCount.value)
|
||||
}
|
||||
|
||||
private fun showNotification(title: String?, body: String?, type: String?) {
|
||||
NotificationHelper.showNotification(this, title, body, type)
|
||||
NotificationHelper.showNotification(this, title, body, type, totalCount = activeChatTracker.totalUnreadCount.value)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
||||
@@ -11,7 +11,7 @@ import androidx.core.app.NotificationCompat
|
||||
object NotificationHelper {
|
||||
private const val CHANNEL_ID = "fork_notifications_channel"
|
||||
|
||||
fun showNotification(context: Context, title: String?, body: String?, type: String?, chatId: String? = null, notificationId: Int? = null) {
|
||||
fun showNotification(context: Context, title: String?, body: String?, type: String?, chatId: String? = null, notificationId: Int? = null, totalCount: Int = 0) {
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
val finalNotificationId = notificationId ?: (System.currentTimeMillis() % Int.MAX_VALUE).toInt()
|
||||
@@ -48,6 +48,7 @@ object NotificationHelper {
|
||||
.setAutoCancel(true)
|
||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
||||
.setNumber(totalCount)
|
||||
.setContentIntent(pendingIntent)
|
||||
|
||||
notificationManager.notify(finalNotificationId, notificationBuilder.build())
|
||||
|
||||
Reference in New Issue
Block a user