lint
This commit is contained in:
+15
-15
@@ -3,15 +3,15 @@ import ExpoBlueskySwissArmy
|
||||
|
||||
let APP_GROUP = "group.app.bsky"
|
||||
|
||||
let DEFAULTS: [String:Any] = [
|
||||
"playSoundChat" : true,
|
||||
let DEFAULTS: [String: Any] = [
|
||||
"playSoundChat": true,
|
||||
"playSoundFollow": false,
|
||||
"playSoundLike": false,
|
||||
"playSoundMention": false,
|
||||
"playSoundQuote": false,
|
||||
"playSoundReply": false,
|
||||
"playSoundRepost": false,
|
||||
"badgeCount": 0,
|
||||
"badgeCount": 0
|
||||
]
|
||||
|
||||
let INCREMENTED_FOR_KEY = "incremented-for-convos"
|
||||
@@ -25,10 +25,10 @@ let INCREMENTED_FOR_KEY = "incremented-for-convos"
|
||||
*/
|
||||
public class ExpoBackgroundNotificationHandlerModule: Module {
|
||||
let userDefaults = UserDefaults(suiteName: APP_GROUP)
|
||||
|
||||
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("ExpoBackgroundNotificationHandler")
|
||||
|
||||
|
||||
OnCreate {
|
||||
DEFAULTS.forEach { p in
|
||||
if !SharedPrefs.shared.hasValue(p.key) {
|
||||
@@ -36,37 +36,37 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("getPrefsAsync") {
|
||||
let keys = Array(DEFAULTS.keys)
|
||||
return SharedPrefs.shared.getValues(keys)
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("resetGenericCountAsync") {
|
||||
SharedPrefs.shared.setValue(BadgeType.generic.toKeyName(), 0)
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("maybeIncrementMessagesCountAsync") { (convoId: String) in
|
||||
guard !SharedPrefs.shared.setContains(INCREMENTED_FOR_KEY, convoId) else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
var count = SharedPrefs.shared.getNumber(BadgeType.messages.toKeyName()) ?? 0
|
||||
count += 1
|
||||
|
||||
|
||||
SharedPrefs.shared.addToSet(INCREMENTED_FOR_KEY, convoId)
|
||||
SharedPrefs.shared.setValue(BadgeType.messages.toKeyName(), count)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("maybeDecrementMessagesCountAsync") { (convoId: String) in
|
||||
guard SharedPrefs.shared.setContains(INCREMENTED_FOR_KEY, convoId) else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
var count = SharedPrefs.shared.getNumber(BadgeType.messages.toKeyName()) ?? 0
|
||||
count -= 1
|
||||
|
||||
|
||||
SharedPrefs.shared.removeFromSet(INCREMENTED_FOR_KEY, convoId)
|
||||
SharedPrefs.shared.setValue(BadgeType.messages.toKeyName(), count)
|
||||
return true
|
||||
@@ -74,10 +74,10 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
|
||||
}
|
||||
}
|
||||
|
||||
enum BadgeType : String, Enumerable {
|
||||
enum BadgeType: String, Enumerable {
|
||||
case generic
|
||||
case messages
|
||||
|
||||
|
||||
func toKeyName() -> String {
|
||||
switch self {
|
||||
case .generic:
|
||||
|
||||
@@ -3,7 +3,7 @@ import ExpoModulesCore
|
||||
|
||||
public class ExpoBlueskySharedPrefsModule: Module {
|
||||
let defaults = UserDefaults(suiteName: "group.app.bsky")
|
||||
|
||||
|
||||
func getDefaults(_ info: String = "(no info)") -> UserDefaults? {
|
||||
guard let defaults = self.defaults else {
|
||||
NSLog("Failed to get defaults for app group: \(info)")
|
||||
@@ -14,7 +14,7 @@ public class ExpoBlueskySharedPrefsModule: Module {
|
||||
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("ExpoBlueskySharedPrefs")
|
||||
|
||||
|
||||
AsyncFunction("setValueAsync") { (key: String, value: JavaScriptValue, promise: Promise) in
|
||||
if value.isString() {
|
||||
SharedPrefs.shared.setValue(key, value.getString())
|
||||
@@ -28,7 +28,7 @@ public class ExpoBlueskySharedPrefsModule: Module {
|
||||
promise.reject("UNSUPPORTED_TYPE_ERROR", "Attempted to set an unsupported type")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("removeValueAsync") { (key: String) in
|
||||
SharedPrefs.shared.removeValue(key)
|
||||
}
|
||||
@@ -36,23 +36,23 @@ public class ExpoBlueskySharedPrefsModule: Module {
|
||||
AsyncFunction("getStringAsync") { (key: String) in
|
||||
return SharedPrefs.shared.getString(key)
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("getBoolAsync") { (key: String) in
|
||||
return SharedPrefs.shared.getBool(key)
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("getNumberAsync") { (key: String) in
|
||||
return SharedPrefs.shared.getNumber(key)
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("addToSetAsync") { (key: String, value: String) in
|
||||
SharedPrefs.shared.addToSet(key, value)
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("removeFromSetAsync") { (key: String, value: String) in
|
||||
SharedPrefs.shared.removeFromSet(key, value)
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("setContainsAsync") { (key: String, value: String) in
|
||||
return SharedPrefs.shared.setContains(key, value)
|
||||
}
|
||||
|
||||
@@ -52,20 +52,20 @@ public class SharedPrefs {
|
||||
}
|
||||
|
||||
public func addToSet(_ key: String, _ value: String) {
|
||||
var dict: [String:Bool]?
|
||||
if var currDict = getDefaults(key)?.dictionary(forKey: key) as? [String:Bool] {
|
||||
var dict: [String: Bool]?
|
||||
if var currDict = getDefaults(key)?.dictionary(forKey: key) as? [String: Bool] {
|
||||
currDict[value] = true
|
||||
dict = currDict
|
||||
} else {
|
||||
dict = [
|
||||
value : true
|
||||
value: true
|
||||
]
|
||||
}
|
||||
getDefaults(key)?.setValue(dict, forKey: key)
|
||||
}
|
||||
|
||||
public func removeFromSet(_ key: String, _ value: String) {
|
||||
guard var dict = getDefaults(key)?.dictionary(forKey: key) as? [String:Bool] else {
|
||||
guard var dict = getDefaults(key)?.dictionary(forKey: key) as? [String: Bool] else {
|
||||
return
|
||||
}
|
||||
dict.removeValue(forKey: value)
|
||||
@@ -73,7 +73,7 @@ public class SharedPrefs {
|
||||
}
|
||||
|
||||
public func setContains(_ key: String, _ value: String) -> Bool {
|
||||
guard let dict = getDefaults(key)?.dictionary(forKey: key) as? [String:Bool] else {
|
||||
guard let dict = getDefaults(key)?.dictionary(forKey: key) as? [String: Bool] else {
|
||||
return false
|
||||
}
|
||||
return dict[value] == true
|
||||
@@ -83,7 +83,7 @@ public class SharedPrefs {
|
||||
return getDefaults(key)?.value(forKey: key) != nil
|
||||
}
|
||||
|
||||
public func getValues(_ keys: [String]) -> [String:Any?]? {
|
||||
public func getValues(_ keys: [String]) -> [String: Any?]? {
|
||||
return getDefaults("keys:\(keys)")?.dictionaryWithValues(forKeys: keys)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user