load preferences

This commit is contained in:
Hailey
2024-06-26 11:24:14 -07:00
parent d6a2ee4e9e
commit f9c5c42290
4 changed files with 13 additions and 2 deletions
@@ -64,6 +64,11 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
SharedPrefs.shared.removeFromSet(INCREMENTED_FOR_KEY, convoId) SharedPrefs.shared.removeFromSet(INCREMENTED_FOR_KEY, convoId)
SharedPrefs.shared.setValue(BadgeType.messages.toKeyName(), count) SharedPrefs.shared.setValue(BadgeType.messages.toKeyName(), count)
} }
AsyncFunction("getPrefsAsync") {
let keys = Array(DEFAULTS.keys)
return SharedPrefs.shared.getValues(keys)
}
} }
} }
@@ -31,7 +31,9 @@ export function BackgroundNotificationPreferencesProvider({
React.useEffect(() => { React.useEffect(() => {
;(async () => { ;(async () => {
const prefs = await BackgroundNotifications.getPrefsAsync() const prefs = await BackgroundNotifications.getPrefsAsync()
setPreferences(prefs) if (prefs) {
setPreferences(prefs)
}
})() })()
}, []) }, [])
@@ -19,6 +19,6 @@ export function decrementMessagesCountAsync(
throw new NotImplementedError({count, convoId}) throw new NotImplementedError({count, convoId})
} }
export function getPrefsAsync(): Promise<BackgroundNotificationHandlerPreferences> { export function getPrefsAsync(): Promise<BackgroundNotificationHandlerPreferences | null> {
throw new NotImplementedError() throw new NotImplementedError()
} }
@@ -82,4 +82,8 @@ public class SharedPrefs {
public func hasValue(_ key: String) -> Bool { public func hasValue(_ key: String) -> Bool {
return getDefaults(key)?.value(forKey: key) != nil return getDefaults(key)?.value(forKey: key) != nil
} }
public func getValues(_ keys: [String]) -> [String:Any?]? {
return getDefaults("keys:\(keys)")?.dictionaryWithValues(forKeys: keys)
}
} }