add support for mark-read-generic and mark-read-messages
update kotlin stub update js types update the correct badge count clamp single decrements too clamp decrement future proof with `decrementBy` add support for `mark-read-generic` and `mark-read-messages` do nothing when receiving `mark-read-*` is received simplify swift update android with new types add types to `NotificationReason` add logic for decrementing the badge add decrement mutation
This commit is contained in:
+16
-1
@@ -3,6 +3,17 @@ package expo.modules.backgroundnotificationhandler
|
||||
import android.content.Context
|
||||
import com.google.firebase.messaging.RemoteMessage
|
||||
|
||||
enum class NotificationType(val type: String) {
|
||||
Like("like"),
|
||||
Repost("repost"),
|
||||
Follow("follow"),
|
||||
Reply("reply"),
|
||||
Quote("quote"),
|
||||
ChatMessage("chat-message"),
|
||||
MarkReadGeneric("mark-read-generic"),
|
||||
MarkReadMessages("mark-read-messages"),
|
||||
}
|
||||
|
||||
class BackgroundNotificationHandler(
|
||||
private val context: Context,
|
||||
private val notifInterface: BackgroundNotificationHandlerInterface
|
||||
@@ -13,8 +24,12 @@ class BackgroundNotificationHandler(
|
||||
return
|
||||
}
|
||||
|
||||
if (remoteMessage.data["reason"] == "chat-message") {
|
||||
val type = NotificationType.valueOf(remoteMessage.data["reason"] ?: return)
|
||||
|
||||
if (type == NotificationType.ChatMessage) {
|
||||
mutateWithChatMessage(remoteMessage)
|
||||
} else if (type == NotificationType.MarkReadGeneric || type == NotificationType.MarkReadMessages) {
|
||||
return
|
||||
}
|
||||
|
||||
notifInterface.showMessage(remoteMessage)
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ class ExpoBackgroundNotificationHandlerModule : Module() {
|
||||
NotificationPrefs(appContext.reactContext).removeManyFromStringArray(forKey, strings)
|
||||
}
|
||||
|
||||
AsyncFunction("setBadgeCountAsync") { _: Int ->
|
||||
AsyncFunction("setBadgeCountAsync") { _: String, _: Int ->
|
||||
// This does nothing on Android
|
||||
}
|
||||
}
|
||||
|
||||
+16
-2
@@ -114,8 +114,22 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
|
||||
}
|
||||
}
|
||||
|
||||
AsyncFunction("setBadgeCountAsync") { (count: Int) in
|
||||
userDefaults?.setValue(count, forKey: "badgeCount")
|
||||
AsyncFunction("setBadgeCountAsync") { (type: BadgeCountType, count: Int) in
|
||||
userDefaults?.setValue(count, forKey: type.toKeyName())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum BadgeCountType : String, Enumerable {
|
||||
case generic
|
||||
case messages
|
||||
|
||||
func toKeyName() -> String {
|
||||
switch self {
|
||||
case .generic:
|
||||
return "badgeCountGeneric"
|
||||
case .messages:
|
||||
return "badgeCountMessages"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -31,7 +31,10 @@ export type ExpoBackgroundNotificationHandlerModule = {
|
||||
forKey: keyof BackgroundNotificationHandlerPreferences,
|
||||
value: string[],
|
||||
) => Promise<void>
|
||||
setBadgeCountAsync: (count: number) => Promise<void>
|
||||
setBadgeCountAsync: (
|
||||
type: 'generic' | 'messages',
|
||||
count: number,
|
||||
) => Promise<void>
|
||||
}
|
||||
|
||||
// TODO there are more preferences in the native code, however they have not been added here yet.
|
||||
|
||||
+1
-1
@@ -24,5 +24,5 @@ export const BackgroundNotificationHandler = {
|
||||
removeFromStringArrayAsync: async (_: string, __: string) => {},
|
||||
addManyToStringArrayAsync: async (_: string, __: string[]) => {},
|
||||
removeManyFromStringArrayAsync: async (_: string, __: string[]) => {},
|
||||
setBadgeCountAsync: async (_: number) => {},
|
||||
setBadgeCountAsync: async (_: 'generic' | 'messages', __: number) => {},
|
||||
} as ExpoBackgroundNotificationHandlerModule
|
||||
|
||||
Reference in New Issue
Block a user