about summary refs log tree commit diff
path: root/modules/expo-background-notification-handler
diff options
context:
space:
mode:
Diffstat (limited to 'modules/expo-background-notification-handler')
-rw-r--r--modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/BackgroundNotificationHandler.kt2
-rw-r--r--modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/ExpoBackgroundNotificationHandlerModule.kt95
-rw-r--r--modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/NotificationPrefs.kt109
-rw-r--r--modules/expo-background-notification-handler/ios/ExpoBackgroundNotificationHandlerModule.swift47
4 files changed, 131 insertions, 122 deletions
diff --git a/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/BackgroundNotificationHandler.kt b/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/BackgroundNotificationHandler.kt
index 0a8737b88..7c1494c70 100644
--- a/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/BackgroundNotificationHandler.kt
+++ b/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/BackgroundNotificationHandler.kt
@@ -5,7 +5,7 @@ import com.google.firebase.messaging.RemoteMessage
 
 class BackgroundNotificationHandler(
   private val context: Context,
-  private val notifInterface: BackgroundNotificationHandlerInterface
+  private val notifInterface: BackgroundNotificationHandlerInterface,
 ) {
   fun handleMessage(remoteMessage: RemoteMessage) {
     if (ExpoBackgroundNotificationHandlerModule.isForegrounded) {
diff --git a/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/ExpoBackgroundNotificationHandlerModule.kt b/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/ExpoBackgroundNotificationHandlerModule.kt
index c876f899a..0cc5fa6ab 100644
--- a/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/ExpoBackgroundNotificationHandlerModule.kt
+++ b/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/ExpoBackgroundNotificationHandlerModule.kt
@@ -8,67 +8,68 @@ class ExpoBackgroundNotificationHandlerModule : Module() {
     var isForegrounded = false
   }
 
-  override fun definition() = ModuleDefinition {
-    Name("ExpoBackgroundNotificationHandler")
+  override fun definition() =
+    ModuleDefinition {
+      Name("ExpoBackgroundNotificationHandler")
 
-    OnCreate {
-      NotificationPrefs(appContext.reactContext).initialize()
-    }
+      OnCreate {
+        NotificationPrefs(appContext.reactContext).initialize()
+      }
 
-    OnActivityEntersForeground {
-      isForegrounded = true
-    }
+      OnActivityEntersForeground {
+        isForegrounded = true
+      }
 
-    OnActivityEntersBackground {
-      isForegrounded = false
-    }
+      OnActivityEntersBackground {
+        isForegrounded = false
+      }
 
-    AsyncFunction("getAllPrefsAsync") {
-      return@AsyncFunction NotificationPrefs(appContext.reactContext).getAllPrefs()
-    }
+      AsyncFunction("getAllPrefsAsync") {
+        return@AsyncFunction NotificationPrefs(appContext.reactContext).getAllPrefs()
+      }
 
-    AsyncFunction("getBoolAsync") { forKey: String ->
-      return@AsyncFunction NotificationPrefs(appContext.reactContext).getBoolean(forKey)
-    }
+      AsyncFunction("getBoolAsync") { forKey: String ->
+        return@AsyncFunction NotificationPrefs(appContext.reactContext).getBoolean(forKey)
+      }
 
-    AsyncFunction("getStringAsync") { forKey: String ->
-      return@AsyncFunction NotificationPrefs(appContext.reactContext).getString(forKey)
-    }
+      AsyncFunction("getStringAsync") { forKey: String ->
+        return@AsyncFunction NotificationPrefs(appContext.reactContext).getString(forKey)
+      }
 
-    AsyncFunction("getStringArrayAsync") { forKey: String ->
-      return@AsyncFunction NotificationPrefs(appContext.reactContext).getStringArray(forKey)
-    }
+      AsyncFunction("getStringArrayAsync") { forKey: String ->
+        return@AsyncFunction NotificationPrefs(appContext.reactContext).getStringArray(forKey)
+      }
 
-    AsyncFunction("setBoolAsync") { forKey: String, value: Boolean ->
-      NotificationPrefs(appContext.reactContext).setBoolean(forKey, value)
-    }
+      AsyncFunction("setBoolAsync") { forKey: String, value: Boolean ->
+        NotificationPrefs(appContext.reactContext).setBoolean(forKey, value)
+      }
 
-    AsyncFunction("setStringAsync") { forKey: String, value: String ->
-      NotificationPrefs(appContext.reactContext).setString(forKey, value)
-    }
+      AsyncFunction("setStringAsync") { forKey: String, value: String ->
+        NotificationPrefs(appContext.reactContext).setString(forKey, value)
+      }
 
-    AsyncFunction("setStringArrayAsync") { forKey: String, value: Array<String> ->
-      NotificationPrefs(appContext.reactContext).setStringArray(forKey, value)
-    }
+      AsyncFunction("setStringArrayAsync") { forKey: String, value: Array<String> ->
+        NotificationPrefs(appContext.reactContext).setStringArray(forKey, value)
+      }
 
-    AsyncFunction("addToStringArrayAsync") { forKey: String, string: String ->
-      NotificationPrefs(appContext.reactContext).addToStringArray(forKey, string)
-    }
+      AsyncFunction("addToStringArrayAsync") { forKey: String, string: String ->
+        NotificationPrefs(appContext.reactContext).addToStringArray(forKey, string)
+      }
 
-    AsyncFunction("removeFromStringArrayAsync") { forKey: String, string: String ->
-      NotificationPrefs(appContext.reactContext).removeFromStringArray(forKey, string)
-    }
+      AsyncFunction("removeFromStringArrayAsync") { forKey: String, string: String ->
+        NotificationPrefs(appContext.reactContext).removeFromStringArray(forKey, string)
+      }
 
-    AsyncFunction("addManyToStringArrayAsync") { forKey: String, strings: Array<String> ->
-      NotificationPrefs(appContext.reactContext).addManyToStringArray(forKey, strings)
-    }
+      AsyncFunction("addManyToStringArrayAsync") { forKey: String, strings: Array<String> ->
+        NotificationPrefs(appContext.reactContext).addManyToStringArray(forKey, strings)
+      }
 
-    AsyncFunction("removeManyFromStringArrayAsync") { forKey: String, strings: Array<String> ->
-      NotificationPrefs(appContext.reactContext).removeManyFromStringArray(forKey, strings)
-    }
+      AsyncFunction("removeManyFromStringArrayAsync") { forKey: String, strings: Array<String> ->
+        NotificationPrefs(appContext.reactContext).removeManyFromStringArray(forKey, strings)
+      }
 
-    AsyncFunction("setBadgeCountAsync") { _: Int ->
-      // This does nothing on Android
+      AsyncFunction("setBadgeCountAsync") { _: Int ->
+        // This does nothing on Android
+      }
     }
-  }
 }
diff --git a/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/NotificationPrefs.kt b/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/NotificationPrefs.kt
index 17ef9205e..97b05b4d7 100644
--- a/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/NotificationPrefs.kt
+++ b/modules/expo-background-notification-handler/android/src/main/java/expo/modules/backgroundnotificationhandler/NotificationPrefs.kt
@@ -2,20 +2,24 @@ package expo.modules.backgroundnotificationhandler
 
 import android.content.Context
 
-val DEFAULTS = mapOf<String, Any>(
-  "playSoundChat" to true,
-  "playSoundFollow" to false,
-  "playSoundLike" to false,
-  "playSoundMention" to false,
-  "playSoundQuote" to false,
-  "playSoundReply" to false,
-  "playSoundRepost" to false,
-  "mutedThreads" to mapOf<String, List<String>>()
-)
-
-class NotificationPrefs (private val context: Context?) {
-  private val prefs = context?.getSharedPreferences("xyz.blueskyweb.app", Context.MODE_PRIVATE)
-    ?: throw Error("Context is null")
+val DEFAULTS =
+  mapOf<String, Any>(
+    "playSoundChat" to true,
+    "playSoundFollow" to false,
+    "playSoundLike" to false,
+    "playSoundMention" to false,
+    "playSoundQuote" to false,
+    "playSoundReply" to false,
+    "playSoundRepost" to false,
+    "mutedThreads" to mapOf<String, List<String>>(),
+  )
+
+class NotificationPrefs(
+  private val context: Context?,
+) {
+  private val prefs =
+    context?.getSharedPreferences("xyz.blueskyweb.app", Context.MODE_PRIVATE)
+      ?: throw Error("Context is null")
 
   fun initialize() {
     prefs
@@ -41,94 +45,99 @@ class NotificationPrefs (private val context: Context?) {
             }
           }
         }
-      }
-      .apply()
+      }.apply()
   }
 
-  fun getAllPrefs(): MutableMap<String, *> {
-    return prefs.all
-  }
+  fun getAllPrefs(): MutableMap<String, *> = prefs.all
 
-  fun getBoolean(key: String): Boolean {
-    return prefs.getBoolean(key, false)
-  }
+  fun getBoolean(key: String): Boolean = prefs.getBoolean(key, false)
 
-  fun getString(key: String): String? {
-    return prefs.getString(key, null)
-  }
+  fun getString(key: String): String? = prefs.getString(key, null)
 
-  fun getStringArray(key: String): Array<String>? {
-    return prefs.getStringSet(key, null)?.toTypedArray()
-  }
+  fun getStringArray(key: String): Array<String>? = prefs.getStringSet(key, null)?.toTypedArray()
 
-  fun setBoolean(key: String, value: Boolean) {
+  fun setBoolean(
+    key: String,
+    value: Boolean,
+  ) {
     prefs
       .edit()
       .apply {
         putBoolean(key, value)
-      }
-      .apply()
+      }.apply()
   }
 
-  fun setString(key: String, value: String) {
+  fun setString(
+    key: String,
+    value: String,
+  ) {
     prefs
       .edit()
       .apply {
         putString(key, value)
-      }
-      .apply()
+      }.apply()
   }
 
-  fun setStringArray(key: String, value: Array<String>) {
+  fun setStringArray(
+    key: String,
+    value: Array<String>,
+  ) {
     prefs
       .edit()
       .apply {
         putStringSet(key, value.toSet())
-      }
-      .apply()
+      }.apply()
   }
 
-  fun addToStringArray(key: String, string: String) {
+  fun addToStringArray(
+    key: String,
+    string: String,
+  ) {
     prefs
       .edit()
       .apply {
         val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
         set.add(string)
         putStringSet(key, set)
-      }
-      .apply()
+      }.apply()
   }
 
-  fun removeFromStringArray(key: String, string: String) {
+  fun removeFromStringArray(
+    key: String,
+    string: String,
+  ) {
     prefs
       .edit()
       .apply {
         val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
         set.remove(string)
         putStringSet(key, set)
-      }
-      .apply()
+      }.apply()
   }
 
-  fun addManyToStringArray(key: String, strings: Array<String>) {
+  fun addManyToStringArray(
+    key: String,
+    strings: Array<String>,
+  ) {
     prefs
       .edit()
       .apply {
         val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
         set.addAll(strings.toSet())
         putStringSet(key, set)
-      }
-      .apply()
+      }.apply()
   }
 
-  fun removeManyFromStringArray(key: String, strings: Array<String>) {
+  fun removeManyFromStringArray(
+    key: String,
+    strings: Array<String>,
+  ) {
     prefs
       .edit()
       .apply {
         val set = prefs.getStringSet(key, null)?.toMutableSet() ?: mutableSetOf()
         set.removeAll(strings.toSet())
         putStringSet(key, set)
-      }
-      .apply()
+      }.apply()
   }
-}
\ No newline at end of file
+}
diff --git a/modules/expo-background-notification-handler/ios/ExpoBackgroundNotificationHandlerModule.swift b/modules/expo-background-notification-handler/ios/ExpoBackgroundNotificationHandlerModule.swift
index 5f8c7fc3b..3845fe765 100644
--- a/modules/expo-background-notification-handler/ios/ExpoBackgroundNotificationHandlerModule.swift
+++ b/modules/expo-background-notification-handler/ios/ExpoBackgroundNotificationHandlerModule.swift
@@ -2,16 +2,16 @@ import ExpoModulesCore
 
 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,
-  "mutedThreads": [:] as! [String:[String]],
-  "badgeCount": 0,
+  "mutedThreads": [:] as! [String: [String]],
+  "badgeCount": 0
 ]
 
 /*
@@ -23,10 +23,10 @@ let DEFAULTS: [String:Any] = [
  */
 public class ExpoBackgroundNotificationHandlerModule: Module {
   let userDefaults = UserDefaults(suiteName: APP_GROUP)
-  
+
   public func definition() -> ModuleDefinition {
     Name("ExpoBackgroundNotificationHandler")
-    
+
     OnCreate {
       DEFAULTS.forEach { p in
         if userDefaults?.value(forKey: p.key) == nil {
@@ -34,57 +34,56 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
         }
       }
     }
-    
-    AsyncFunction("getAllPrefsAsync") { () -> [String:Any]? in
+
+    AsyncFunction("getAllPrefsAsync") { () -> [String: Any]? in
       var keys: [String] = []
       DEFAULTS.forEach { p in
         keys.append(p.key)
       }
       return userDefaults?.dictionaryWithValues(forKeys: keys)
     }
-    
+
     AsyncFunction("getBoolAsync") { (forKey: String) -> Bool in
       if let pref = userDefaults?.bool(forKey: forKey) {
         return pref
       }
       return false
     }
-    
+
     AsyncFunction("getStringAsync") { (forKey: String) -> String? in
       if let pref = userDefaults?.string(forKey: forKey) {
         return pref
       }
       return nil
     }
-    
+
     AsyncFunction("getStringArrayAsync") { (forKey: String) -> [String]? in
       if let pref = userDefaults?.stringArray(forKey: forKey) {
         return pref
       }
       return nil
     }
-    
-    AsyncFunction("setBoolAsync") { (forKey: String, value: Bool) -> Void in
+
+    AsyncFunction("setBoolAsync") { (forKey: String, value: Bool) in
       userDefaults?.setValue(value, forKey: forKey)
     }
-    
-    AsyncFunction("setStringAsync") { (forKey: String, value: String) -> Void in
+
+    AsyncFunction("setStringAsync") { (forKey: String, value: String) in
       userDefaults?.setValue(value, forKey: forKey)
     }
-    
-    AsyncFunction("setStringArrayAsync") { (forKey: String, value: [String]) -> Void in
+
+    AsyncFunction("setStringArrayAsync") { (forKey: String, value: [String]) in
       userDefaults?.setValue(value, forKey: forKey)
     }
-    
+
     AsyncFunction("addToStringArrayAsync") { (forKey: String, string: String) in
       if var curr = userDefaults?.stringArray(forKey: forKey),
-         !curr.contains(string)
-      {
+         !curr.contains(string) {
         curr.append(string)
         userDefaults?.setValue(curr, forKey: forKey)
       }
     }
-    
+
     AsyncFunction("removeFromStringArrayAsync") { (forKey: String, string: String) in
       if var curr = userDefaults?.stringArray(forKey: forKey) {
         curr.removeAll { s in
@@ -93,7 +92,7 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
         userDefaults?.setValue(curr, forKey: forKey)
       }
     }
-    
+
     AsyncFunction("addManyToStringArrayAsync") { (forKey: String, strings: [String]) in
       if var curr = userDefaults?.stringArray(forKey: forKey) {
         strings.forEach { s in
@@ -104,7 +103,7 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
         userDefaults?.setValue(curr, forKey: forKey)
       }
     }
-    
+
     AsyncFunction("removeManyFromStringArrayAsync") { (forKey: String, strings: [String]) in
       if var curr = userDefaults?.stringArray(forKey: forKey) {
         strings.forEach { s in
@@ -113,7 +112,7 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
         userDefaults?.setValue(curr, forKey: forKey)
       }
     }
-    
+
     AsyncFunction("setBadgeCountAsync") { (count: Int) in
       userDefaults?.setValue(count, forKey: "badgeCount")
     }