Bluesky app fork with some witchin' additions 💫

Use the proper logic on iOS to increment the badge (#4233)

authored by hailey.at and committed by

GitHub 480a4086 c58aedf0

+34 -15
+7 -1
modules/BlueskyNSE/NotificationService.swift
··· 1 import UserNotifications 2 3 let APP_GROUP = "group.app.bsky" 4 ··· 31 } 32 33 func mutateWithBadge(_ content: UNMutableNotificationContent) { 34 - content.badge = 1 35 } 36 37 func mutateWithChatMessage(_ content: UNMutableNotificationContent) {
··· 1 import UserNotifications 2 + import UIKit 3 4 let APP_GROUP = "group.app.bsky" 5 ··· 32 } 33 34 func mutateWithBadge(_ content: UNMutableNotificationContent) { 35 + var count = prefs?.integer(forKey: "badgeCount") ?? 0 36 + count += 1 37 + 38 + // Set the new badge number for the notification, then store that value for using later 39 + content.badge = NSNumber(value: count) 40 + prefs?.setValue(count, forKey: "badgeCount") 41 } 42 43 func mutateWithChatMessage(_ content: UNMutableNotificationContent) {
+4
modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/ExpoBackgroundNotificationHandlerModule.kt
··· 66 AsyncFunction("removeManyFromStringArrayAsync") { forKey: String, strings: Array<String> -> 67 NotificationPrefs(appContext.reactContext).removeManyFromStringArray(forKey, strings) 68 } 69 } 70 }
··· 66 AsyncFunction("removeManyFromStringArrayAsync") { forKey: String, strings: Array<String> -> 67 NotificationPrefs(appContext.reactContext).removeManyFromStringArray(forKey, strings) 68 } 69 + 70 + AsyncFunction("setBadgeCountAsync") { _: Int -> 71 + // This does nothing on Android 72 + } 73 } 74 }
+6 -1
modules/expo-background-notification-handler/ios/ExpoBackgroundNotificationHandlerModule.swift
··· 10 "playSoundQuote": false, 11 "playSoundReply": false, 12 "playSoundRepost": false, 13 - "mutedThreads": [:] as! [String:[String]] 14 ] 15 16 /* ··· 111 } 112 userDefaults?.setValue(curr, forKey: forKey) 113 } 114 } 115 } 116 }
··· 10 "playSoundQuote": false, 11 "playSoundReply": false, 12 "playSoundRepost": false, 13 + "mutedThreads": [:] as! [String:[String]], 14 + "badgeCount": 0, 15 ] 16 17 /* ··· 112 } 113 userDefaults?.setValue(curr, forKey: forKey) 114 } 115 + } 116 + 117 + AsyncFunction("setBadgeCountAsync") { (count: Int) in 118 + userDefaults?.setValue(count, forKey: "badgeCount") 119 } 120 } 121 }
+1
modules/expo-background-notification-handler/src/ExpoBackgroundNotificationHandler.types.ts
··· 31 forKey: keyof BackgroundNotificationHandlerPreferences, 32 value: string[], 33 ) => Promise<void> 34 } 35 36 // TODO there are more preferences in the native code, however they have not been added here yet.
··· 31 forKey: keyof BackgroundNotificationHandlerPreferences, 32 value: string[], 33 ) => Promise<void> 34 + setBadgeCountAsync: (count: number) => Promise<void> 35 } 36 37 // TODO there are more preferences in the native code, however they have not been added here yet.
+1
modules/expo-background-notification-handler/src/ExpoBackgroundNotificationHandlerModule.web.ts
··· 24 removeFromStringArrayAsync: async (_: string, __: string) => {}, 25 addManyToStringArrayAsync: async (_: string, __: string[]) => {}, 26 removeManyFromStringArrayAsync: async (_: string, __: string[]) => {}, 27 } as ExpoBackgroundNotificationHandlerModule
··· 24 removeFromStringArrayAsync: async (_: string, __: string) => {}, 25 addManyToStringArrayAsync: async (_: string, __: string[]) => {}, 26 removeManyFromStringArrayAsync: async (_: string, __: string[]) => {}, 27 + setBadgeCountAsync: async (_: number) => {}, 28 } as ExpoBackgroundNotificationHandlerModule
+13 -11
src/lib/notifications/notifications.ts
··· 7 import {SessionAccount, useAgent, useSession} from '#/state/session' 8 import {logEvent, useGate} from 'lib/statsig/statsig' 9 import {devicePlatform, isNative} from 'platform/detection' 10 11 const SERVICE_DID = (serviceUrl?: string) => 12 serviceUrl?.includes('staging') ··· 108 } 109 } 110 111 - export async function decrementBadgeCount(by: number | 'reset' = 1) { 112 if (!isNative) return 113 114 - const currCount = await getBadgeCountAsync() 115 116 - if (by === 'reset') { 117 - await setBadgeCountAsync(0) 118 - return 119 - } 120 121 - let newCount = currCount - by 122 - if (newCount < 0) { 123 - newCount = 0 124 - } 125 - await setBadgeCountAsync(newCount) 126 }
··· 7 import {SessionAccount, useAgent, useSession} from '#/state/session' 8 import {logEvent, useGate} from 'lib/statsig/statsig' 9 import {devicePlatform, isNative} from 'platform/detection' 10 + import BackgroundNotificationHandler from '../../../modules/expo-background-notification-handler' 11 12 const SERVICE_DID = (serviceUrl?: string) => 13 serviceUrl?.includes('staging') ··· 109 } 110 } 111 112 + export async function decrementBadgeCount(by: number) { 113 if (!isNative) return 114 115 + let count = await getBadgeCountAsync() 116 + count -= by 117 + if (count < 0) { 118 + count = 0 119 + } 120 121 + await BackgroundNotificationHandler.setBadgeCountAsync(count) 122 + await setBadgeCountAsync(count) 123 + } 124 125 + export async function resetBadgeCount() { 126 + await BackgroundNotificationHandler.setBadgeCountAsync(0) 127 + await setBadgeCountAsync(0) 128 }
+2 -2
src/state/queries/notifications/unread.tsx
··· 11 import {logger} from '#/logger' 12 import {useMutedThreads} from '#/state/muted-threads' 13 import {useAgent, useSession} from '#/state/session' 14 - import {decrementBadgeCount} from 'lib/notifications/notifications' 15 import {useModerationOpts} from '../../preferences/moderation-opts' 16 import {truncateAndInvalidate} from '../util' 17 import {RQKEY as RQKEY_NOTIFS} from './feed' ··· 119 // update & broadcast 120 setNumUnread('') 121 broadcast.postMessage({event: ''}) 122 - decrementBadgeCount('reset') 123 }, 124 125 async checkUnread({
··· 11 import {logger} from '#/logger' 12 import {useMutedThreads} from '#/state/muted-threads' 13 import {useAgent, useSession} from '#/state/session' 14 + import {resetBadgeCount} from 'lib/notifications/notifications' 15 import {useModerationOpts} from '../../preferences/moderation-opts' 16 import {truncateAndInvalidate} from '../util' 17 import {RQKEY as RQKEY_NOTIFS} from './feed' ··· 119 // update & broadcast 120 setNumUnread('') 121 broadcast.postMessage({event: ''}) 122 + resetBadgeCount() 123 }, 124 125 async checkUnread({