add android MessagingStyle for chat notifications
Patches expo-notifications to use NotificationCompat.MessagingStyle for chat-message and chat-reaction notifications. Downloads the sender avatar thumbnail and creates a Person with the icon for the conversation-style notification layout. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+23
-1
@@ -1,7 +1,9 @@
|
||||
package expo.modules.backgroundnotificationhandler
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.google.firebase.messaging.RemoteMessage
|
||||
import org.json.JSONObject
|
||||
|
||||
class BackgroundNotificationHandler(
|
||||
private val context: Context,
|
||||
@@ -13,8 +15,12 @@ class BackgroundNotificationHandler(
|
||||
return
|
||||
}
|
||||
|
||||
if (remoteMessage.data["reason"] == "chat-message" || remoteMessage.data["reason"] == "chat-reaction") {
|
||||
val reason = remoteMessage.data["reason"]
|
||||
Log.d(TAG, "handleMessage: reason=$reason")
|
||||
|
||||
if (reason == "chat-message" || reason == "chat-reaction") {
|
||||
mutateWithChatMessage(remoteMessage)
|
||||
packBodyForPresentation(remoteMessage)
|
||||
} else {
|
||||
mutateWithOtherReason(remoteMessage)
|
||||
}
|
||||
@@ -22,6 +28,18 @@ class BackgroundNotificationHandler(
|
||||
notifInterface.showMessage(remoteMessage)
|
||||
}
|
||||
|
||||
private fun packBodyForPresentation(remoteMessage: RemoteMessage) {
|
||||
val body = JSONObject().apply {
|
||||
put("reason", remoteMessage.data["reason"])
|
||||
put("senderDisplayName", remoteMessage.data["senderDisplayName"])
|
||||
put("senderAvatarUrl", remoteMessage.data["senderAvatarUrl"])
|
||||
put("senderHandle", remoteMessage.data["senderHandle"])
|
||||
put("convoId", remoteMessage.data["convoId"])
|
||||
}
|
||||
remoteMessage.data["body"] = body.toString()
|
||||
Log.d(TAG, "packBodyForPresentation: $body")
|
||||
}
|
||||
|
||||
private fun mutateWithChatMessage(remoteMessage: RemoteMessage) {
|
||||
if (NotificationPrefs(context).getBoolean("playSoundChat")) {
|
||||
// If oreo or higher
|
||||
@@ -42,6 +60,10 @@ class BackgroundNotificationHandler(
|
||||
remoteMessage.data["badge"] = null
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "BGNotifHandler"
|
||||
}
|
||||
|
||||
private fun mutateWithOtherReason(remoteMessage: RemoteMessage) {
|
||||
// If oreo or higher
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
|
||||
Reference in New Issue
Block a user