feat: update notification handling and improve media selection with captions
This commit is contained in:
@@ -34,10 +34,21 @@ class RosettaFirebaseMessagingService : FirebaseMessagingService() {
|
||||
private const val TAG = "RosettaFCM"
|
||||
private const val CHANNEL_ID = "rosetta_messages"
|
||||
private const val CHANNEL_NAME = "Messages"
|
||||
private const val NOTIFICATION_ID = 1
|
||||
|
||||
// 🔥 Флаг - приложение в foreground (видимо пользователю)
|
||||
@Volatile var isAppInForeground = false
|
||||
|
||||
/** Уникальный notification ID для каждого чата (по publicKey) */
|
||||
fun getNotificationIdForChat(senderPublicKey: String): Int {
|
||||
return senderPublicKey.hashCode() and 0x7FFFFFFF // positive int
|
||||
}
|
||||
|
||||
/** Убрать уведомление конкретного чата из шторки */
|
||||
fun cancelNotificationForChat(context: Context, senderPublicKey: String) {
|
||||
val notificationManager =
|
||||
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.cancel(getNotificationIdForChat(senderPublicKey))
|
||||
}
|
||||
}
|
||||
|
||||
/** Вызывается когда получен новый FCM токен Отправляем его на сервер через протокол */
|
||||
@@ -97,6 +108,8 @@ class RosettaFirebaseMessagingService : FirebaseMessagingService() {
|
||||
|
||||
createNotificationChannel()
|
||||
|
||||
val notifId = getNotificationIdForChat(senderPublicKey ?: "")
|
||||
|
||||
// Intent для открытия чата
|
||||
val intent =
|
||||
Intent(this, MainActivity::class.java).apply {
|
||||
@@ -107,7 +120,7 @@ class RosettaFirebaseMessagingService : FirebaseMessagingService() {
|
||||
val pendingIntent =
|
||||
PendingIntent.getActivity(
|
||||
this,
|
||||
0,
|
||||
notifId,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
@@ -125,7 +138,7 @@ class RosettaFirebaseMessagingService : FirebaseMessagingService() {
|
||||
|
||||
val notificationManager =
|
||||
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(NOTIFICATION_ID, notification)
|
||||
notificationManager.notify(notifId, notification)
|
||||
}
|
||||
|
||||
/** Показать простое уведомление */
|
||||
@@ -162,7 +175,7 @@ class RosettaFirebaseMessagingService : FirebaseMessagingService() {
|
||||
|
||||
val notificationManager =
|
||||
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.notify(NOTIFICATION_ID, notification)
|
||||
notificationManager.notify(System.currentTimeMillis().toInt(), notification)
|
||||
}
|
||||
|
||||
/** Создать notification channel для Android 8+ */
|
||||
|
||||
Reference in New Issue
Block a user