Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
9.7 kB · 178 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179diff --git a/android/build.gradle b/android/build.gradleindex a19d7fc4efd78269350c0fa528d4602807df83fb..e3f2d8c469329a82a1c1c4dac4330c81459b08a5 100644--- a/android/build.gradle+++ b/android/build.gradle@@ -43,6 +43,7 @@ dependencies { implementation 'com.google.firebase:firebase-messaging:25.0.1' implementation 'me.leolin:ShortcutBadger:1.1.22@aar'+ implementation project(':bsky-app-expo-background-notification-handler') if (project.findProject(':expo-modules-test-core')) { testImplementation project(':expo-modules-test-core')diff --git a/android/src/main/java/expo/modules/notifications/notifications/interfaces/INotificationContent.kt b/android/src/main/java/expo/modules/notifications/notifications/interfaces/INotificationContent.ktindex 86a74490089368b8cdf8d874341ee02857623da5..968d8bb4c0493c803b262330cda1ebea1d0fbe81 100644--- a/android/src/main/java/expo/modules/notifications/notifications/interfaces/INotificationContent.kt+++ b/android/src/main/java/expo/modules/notifications/notifications/interfaces/INotificationContent.kt@@ -15,6 +15,7 @@ import org.json.JSONObject * This interface exists to provide a common API for both classes. * */ interface INotificationContent : Parcelable {+ val channelId: String? val title: String? val text: String? val subText: String?diff --git a/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java b/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.javaindex ae6d3927f1df283ab976f086201d189ae8de3299..1dd8d724b8756a48456cc538f6876bac3fde855b 100644--- a/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java+++ b/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java@@ -30,6 +30,7 @@ import kotlin.coroutines.Continuation; * Refactoring this class may require a migration strategy for the data stored in SharedPreferences. */ public class NotificationContent implements Parcelable, Serializable, INotificationContent {+ private String mChannelId; private String mTitle; private String mText; private String mSubtitle;@@ -61,6 +62,11 @@ public class NotificationContent implements Parcelable, Serializable, INotificat } }; + @Nullable+ public String getChannelId() {+ return mChannelId;+ }+ @Nullable public String getTitle() { return mTitle;@@ -150,6 +156,7 @@ public class NotificationContent implements Parcelable, Serializable, INotificat } protected NotificationContent(Parcel in) {+ mChannelId = in.readString(); mTitle = in.readString(); mText = in.readString(); mSubtitle = in.readString();@@ -176,6 +183,7 @@ public class NotificationContent implements Parcelable, Serializable, INotificat @Override public void writeToParcel(Parcel dest, int flags) {+ dest.writeString(mChannelId); dest.writeString(mTitle); dest.writeString(mText); dest.writeString(mSubtitle);@@ -197,6 +205,7 @@ public class NotificationContent implements Parcelable, Serializable, INotificat private static final long serialVersionUID = 397666843266836802L; private void writeObject(java.io.ObjectOutputStream out) throws IOException {+ out.writeObject(mChannelId); out.writeObject(mTitle); out.writeObject(mText); out.writeObject(mSubtitle);@@ -222,6 +231,7 @@ public class NotificationContent implements Parcelable, Serializable, INotificat } private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {+ mChannelId = (String) in.readObject(); mTitle = (String) in.readObject(); mText = (String) in.readObject(); mSubtitle = (String) in.readObject();@@ -285,6 +295,11 @@ public class NotificationContent implements Parcelable, Serializable, INotificat useDefaultVibrationPattern(); } + public Builder setChannelId(String channelId) {+ content.mChannelId = channelId;+ return this;+ }+ public Builder setTitle(String title) { content.mTitle = title; return this;diff --git a/android/src/main/java/expo/modules/notifications/notifications/model/NotificationData.kt b/android/src/main/java/expo/modules/notifications/notifications/model/NotificationData.ktindex ffdd8aa5ca63ae642de4c532e9e5de70c3baa87a..82472beef844e193779169276e1b5d174e58fbb1 100644--- a/android/src/main/java/expo/modules/notifications/notifications/model/NotificationData.kt+++ b/android/src/main/java/expo/modules/notifications/notifications/model/NotificationData.kt@@ -11,6 +11,9 @@ import org.json.JSONObject * */ @JvmInline value class NotificationData(private val data: Map<String, String>) {+ val channelId: String?+ get() = data["channelId"]+ val title: String? get() = data["title"] diff --git a/android/src/main/java/expo/modules/notifications/notifications/model/RemoteNotificationContent.kt b/android/src/main/java/expo/modules/notifications/notifications/model/RemoteNotificationContent.ktindex cc9e5592b63e83dcdc7307c7d44f87c76e0db136..bd078086f3860279df4efadbd13e691a075a2ebd 100644--- a/android/src/main/java/expo/modules/notifications/notifications/model/RemoteNotificationContent.kt+++ b/android/src/main/java/expo/modules/notifications/notifications/model/RemoteNotificationContent.kt@@ -31,6 +31,8 @@ class RemoteNotificationContent(private val remoteMessage: RemoteMessage) : INot return remoteMessage.notification?.imageUrl != null } + override val channelId = remoteMessage.notification?.channelId ?: notificationData.channelId+ override val title = remoteMessage.notification?.title ?: notificationData.title override val text = remoteMessage.notification?.body ?: notificationData.messagediff --git a/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ExpoNotificationBuilder.kt b/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ExpoNotificationBuilder.ktindex 769b5522b9e20caba4b4bebd50a7817759be1eff..e8b52fb4d095e65a897714923c43165fdc9d9dc3 100644--- a/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ExpoNotificationBuilder.kt+++ b/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ExpoNotificationBuilder.kt@@ -101,6 +101,9 @@ open class ExpoNotificationBuilder( builder.setOngoing(content.isSticky) // see "Notification anatomy" https://developer.android.com/develop/ui/views/notifications#Templates+ content.channelId?.let {+ builder.setChannelId(it)+ } builder.setContentTitle(content.title) builder.setContentText(content.text) builder.setSubText(content.subText)diff --git a/android/src/main/java/expo/modules/notifications/service/delegates/FirebaseMessagingDelegate.kt b/android/src/main/java/expo/modules/notifications/service/delegates/FirebaseMessagingDelegate.ktindex eecdae82e99d2997687e3f3e199c94c3aeffbfe0..216891213fb2eac5a9a382b4f075eadccdcfeb5a 100644--- a/android/src/main/java/expo/modules/notifications/service/delegates/FirebaseMessagingDelegate.kt+++ b/android/src/main/java/expo/modules/notifications/service/delegates/FirebaseMessagingDelegate.kt@@ -3,6 +3,9 @@ package expo.modules.notifications.service.delegates import android.content.Context import android.os.Bundle import com.google.firebase.messaging.RemoteMessage+import expo.modules.backgroundnotificationhandler.BackgroundNotificationHandler+import expo.modules.backgroundnotificationhandler.BackgroundNotificationHandlerInterface+import expo.modules.backgroundnotificationhandler.ExpoBackgroundNotificationHandlerModule import expo.modules.interfaces.taskManager.TaskServiceProviderHelper import expo.modules.notifications.notifications.RemoteMessageSerializer import expo.modules.notifications.notifications.background.BackgroundRemoteNotificationTaskConsumer@@ -17,7 +20,7 @@ import expo.modules.notifications.service.interfaces.FirebaseMessagingDelegate import expo.modules.notifications.tokens.interfaces.FirebaseTokenListener import java.util.* -open class FirebaseMessagingDelegate(protected val context: Context) : FirebaseMessagingDelegate {+open class FirebaseMessagingDelegate(protected val context: Context) : FirebaseMessagingDelegate, BackgroundNotificationHandlerInterface{ companion object { // Unfortunately we cannot save state between instances of a service other way // than by static properties.@@ -109,8 +112,19 @@ open class FirebaseMessagingDelegate(protected val context: Context) : FirebaseM DebugLogging.logRemoteMessage("FirebaseMessagingDelegate.onMessageReceived: message", remoteMessage) val notification = createNotification(remoteMessage) DebugLogging.logNotification("FirebaseMessagingDelegate.onMessageReceived: notification", notification)- NotificationsService.receive(context, notification)- runTaskManagerTasks(context.applicationContext, RemoteMessageSerializer.toBundle(remoteMessage))+ if (!ExpoBackgroundNotificationHandlerModule.isForegrounded) {+ BackgroundNotificationHandler(context, this).handleMessage(remoteMessage)+ } else {+ NotificationsService.receive(context, notification)+ runTaskManagerTasks(+ context.applicationContext,+ RemoteMessageSerializer.toBundle(remoteMessage)+ )+ }+ }++ override fun showMessage(remoteMessage: RemoteMessage) {+ NotificationsService.receive(context, createNotification(remoteMessage)) } protected fun createNotification(remoteMessage: RemoteMessage): Notification {