Bluesky app fork with some witchin' additions 💫

patch `expo-notifications` to clear badge (#4475)

authored by hailey.at and committed by

GitHub 808dd356 d85c8a09

+51 -21
+46 -21
patches/expo-notifications+0.28.7.patch
··· 1 1 diff --git a/node_modules/expo-notifications/android/build.gradle b/node_modules/expo-notifications/android/build.gradle 2 - index d233e1f..cc2f856 100644 2 + index b863077..8b5209e 100644 3 3 --- a/node_modules/expo-notifications/android/build.gradle 4 4 +++ b/node_modules/expo-notifications/android/build.gradle 5 5 @@ -32,6 +32,7 @@ dependencies { 6 6 api 'com.google.firebase:firebase-messaging:22.0.0' 7 - 7 + 8 8 api 'me.leolin:ShortcutBadger:1.1.22@aar' 9 9 + implementation project(':expo-background-notification-handler') 10 - 10 + 11 11 if (project.findProject(':expo-modules-test-core')) { 12 12 testImplementation project(':expo-modules-test-core') 13 + diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/badge/BadgeHelper.kt b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/badge/BadgeHelper.kt 14 + index 63a46c5..f911834 100644 15 + --- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/badge/BadgeHelper.kt 16 + +++ b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/badge/BadgeHelper.kt 17 + @@ -1,5 +1,6 @@ 18 + package expo.modules.notifications.badge 19 + 20 + +import android.app.NotificationManager 21 + import android.content.Context 22 + import android.util.Log 23 + import me.leolin.shortcutbadger.ShortcutBadgeException 24 + @@ -12,7 +13,12 @@ object BadgeHelper { 25 + 26 + fun setBadgeCount(context: Context, badgeCount: Int): Boolean { 27 + return try { 28 + - ShortcutBadger.applyCountOrThrow(context.applicationContext, badgeCount) 29 + + if (badgeCount == 0) { 30 + + val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager 31 + + notificationManager.cancelAll() 32 + + } else { 33 + + ShortcutBadger.applyCountOrThrow(context.applicationContext, badgeCount) 34 + + } 35 + BadgeHelper.badgeCount = badgeCount 36 + true 37 + } catch (e: ShortcutBadgeException) { 13 38 diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/JSONNotificationContentBuilder.java b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/JSONNotificationContentBuilder.java 14 39 index 0af7fe0..8f2c8d8 100644 15 40 --- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/JSONNotificationContentBuilder.java 16 41 +++ b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/JSONNotificationContentBuilder.java 17 42 @@ -14,6 +14,7 @@ import expo.modules.notifications.notifications.enums.NotificationPriority; 18 43 import expo.modules.notifications.notifications.model.NotificationContent; 19 - 44 + 20 45 public class JSONNotificationContentBuilder extends NotificationContent.Builder { 21 46 + private static final String CHANNEL_ID_KEY = "channelId"; 22 47 private static final String TITLE_KEY = "title"; 23 48 private static final String TEXT_KEY = "message"; 24 49 private static final String SUBTITLE_KEY = "subtitle"; 25 50 @@ -36,6 +37,7 @@ public class JSONNotificationContentBuilder extends NotificationContent.Builder 26 - 51 + 27 52 public NotificationContent.Builder setPayload(JSONObject payload) { 28 53 this.setTitle(getTitle(payload)) 29 54 + .setChannelId(getChannelId(payload)) ··· 33 58 @@ -60,6 +62,14 @@ public class JSONNotificationContentBuilder extends NotificationContent.Builder 34 59 return this; 35 60 } 36 - 61 + 37 62 + protected String getChannelId(JSONObject payload) { 38 63 + try { 39 64 + return payload.getString(CHANNEL_ID_KEY); ··· 46 71 try { 47 72 return payload.getString(TITLE_KEY); 48 73 diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java 49 - index f1fed19..80afe9e 100644 74 + index f1fed19..012757b 100644 50 75 --- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java 51 76 +++ b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/model/NotificationContent.java 52 77 @@ -20,6 +20,7 @@ import expo.modules.notifications.notifications.enums.NotificationPriority; ··· 60 85 @@ -50,6 +51,11 @@ public class NotificationContent implements Parcelable, Serializable { 61 86 } 62 87 }; 63 - 88 + 64 89 + @Nullable 65 90 + public String getChannelId() { 66 91 + return mChannelId; ··· 71 96 return mTitle; 72 97 @@ -121,6 +127,7 @@ public class NotificationContent implements Parcelable, Serializable { 73 98 } 74 - 99 + 75 100 protected NotificationContent(Parcel in) { 76 101 + mChannelId = in.readString(); 77 102 mTitle = in.readString(); 78 103 mText = in.readString(); 79 104 mSubtitle = in.readString(); 80 105 @@ -146,6 +153,7 @@ public class NotificationContent implements Parcelable, Serializable { 81 - 106 + 82 107 @Override 83 108 public void writeToParcel(Parcel dest, int flags) { 84 109 + dest.writeString(mChannelId); ··· 87 112 dest.writeString(mSubtitle); 88 113 @@ -166,6 +174,7 @@ public class NotificationContent implements Parcelable, Serializable { 89 114 private static final long serialVersionUID = 397666843266836802L; 90 - 115 + 91 116 private void writeObject(java.io.ObjectOutputStream out) throws IOException { 92 117 + out.writeObject(mChannelId); 93 118 out.writeObject(mTitle); ··· 95 120 out.writeObject(mSubtitle); 96 121 @@ -190,6 +199,7 @@ public class NotificationContent implements Parcelable, Serializable { 97 122 } 98 - 123 + 99 124 private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { 100 125 + mChannelId = (String) in.readObject(); 101 126 mTitle = (String) in.readObject(); ··· 103 128 mSubtitle = (String) in.readObject(); 104 129 @@ -240,6 +250,7 @@ public class NotificationContent implements Parcelable, Serializable { 105 130 } 106 - 131 + 107 132 public static class Builder { 108 133 + private String mChannelId; 109 134 private String mTitle; ··· 112 137 @@ -260,6 +271,11 @@ public class NotificationContent implements Parcelable, Serializable { 113 138 useDefaultVibrationPattern(); 114 139 } 115 - 140 + 116 141 + public Builder setChannelId(String channelId) { 117 142 + mChannelId = channelId; 118 143 + return this; ··· 122 147 mTitle = title; 123 148 return this; 124 149 @@ -336,6 +352,7 @@ public class NotificationContent implements Parcelable, Serializable { 125 - 150 + 126 151 public NotificationContent build() { 127 152 NotificationContent content = new NotificationContent(); 128 153 + content.mChannelId = mChannelId; ··· 134 159 --- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ExpoNotificationBuilder.java 135 160 +++ b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/presentation/builders/ExpoNotificationBuilder.java 136 161 @@ -48,6 +48,10 @@ public class ExpoNotificationBuilder extends ChannelAwareNotificationBuilder { 137 - 162 + 138 163 NotificationContent content = getNotificationContent(); 139 - 164 + 140 165 + if (content.getChannelId() != null) { 141 166 + builder.setChannelId(content.getChannelId()); 142 167 + } 143 168 + 144 169 builder.setAutoCancel(content.isAutoDismiss()); 145 170 builder.setOngoing(content.isSticky()); 146 - 171 + 147 172 diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/delegates/FirebaseMessagingDelegate.kt b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/delegates/FirebaseMessagingDelegate.kt 148 173 index 55b3a8d..1b99d5b 100644 149 174 --- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/delegates/FirebaseMessagingDelegate.kt ··· 158 183 import org.json.JSONObject 159 184 import java.lang.ref.WeakReference 160 185 import java.util.* 161 - 186 + 162 187 -open class FirebaseMessagingDelegate(protected val context: Context) : FirebaseMessagingDelegate { 163 188 +open class FirebaseMessagingDelegate(protected val context: Context) : FirebaseMessagingDelegate, BackgroundNotificationHandlerInterface { 164 189 companion object { ··· 166 191 // than by static properties. Fortunately, using weak references we can 167 192 @@ -89,12 +92,21 @@ open class FirebaseMessagingDelegate(protected val context: Context) : FirebaseM 168 193 fun getBackgroundTasks() = sBackgroundTaskConsumerReferences.values.mapNotNull { it.get() } 169 - 194 + 170 195 override fun onMessageReceived(remoteMessage: RemoteMessage) { 171 196 - NotificationsService.receive(context, createNotification(remoteMessage)) 172 197 - getBackgroundTasks().forEach { ··· 181 206 + } 182 207 } 183 208 } 184 - 209 + 185 210 + override fun showMessage(remoteMessage: RemoteMessage) { 186 211 + NotificationsService.receive(context, createNotification(remoteMessage)) 187 212 + }
+5
patches/expo-notifications-0.28.7.patch.md
··· 7 7 8 8 It also allows us to set the Android notification channel ID from the notification `data`, rather 9 9 than the `notification` object in the payload. 10 + 11 + ### `setBadgeCountAsync` fix on Android 12 + 13 + `ShortcutBadger`'s `setCount` doesn't work for clearing the badge on Android for some reason. Instead, let's use the 14 + Android API for clearing the badge.