blob: 344508523de829b2a968059d4aca48f578cb6f52 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package expo.modules.backgroundnotificationhandler
import android.content.Context
import com.google.firebase.messaging.RemoteMessage
class BackgroundNotificationHandler(
private val context: Context,
private val notifInterface: BackgroundNotificationHandlerInterface
) {
fun handleMessage(remoteMessage: RemoteMessage) {
if (ExpoBackgroundNotificationHandlerModule.isForegrounded) {
// We'll let expo-notifications handle the notification if the app is foregrounded
return
}
if (remoteMessage.data["reason"] == "chat-message") {
mutateWithChatMessage(remoteMessage)
}
notifInterface.showMessage(remoteMessage)
}
private fun mutateWithChatMessage(remoteMessage: RemoteMessage) {
if (NotificationPrefs(context).getBoolean("playSoundChat")) {
// If oreo or higher
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
remoteMessage.data["channelId"] = "chat-messages"
} else {
remoteMessage.data["sound"] = "dm.mp3"
}
} else {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
remoteMessage.data["channelId"] = "chat-messages-muted"
} else {
remoteMessage.data["sound"] = null
}
}
}
}
|