Skip to content

Commit

Permalink
swiftlint
Browse files Browse the repository at this point in the history
  • Loading branch information
nan-li committed Dec 7, 2023
1 parent 5fe92b8 commit 2228ed7
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public class OSOperationRepo: NSObject {
OneSignalLog.onesignalLog(.LL_DEBUG, message: "OSOperationRepo not flushing queue due to being paused")
return
}

guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else {
return
}
if (inBackground) {

if inBackground {
OSBackgroundTaskManager.beginBackgroundTask(OPERATION_REPO_BACKGROUND_TASK)
}

Expand Down Expand Up @@ -148,8 +148,8 @@ public class OSOperationRepo: NSObject {
for executor in executors {
executor.processDeltaQueue(inBackground: inBackground)
}
if (inBackground) {

if inBackground {
OSBackgroundTaskManager.endBackgroundTask(OPERATION_REPO_BACKGROUND_TASK)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class OSIdentityModel: OSModel {
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityModel hydrateModel()")
var newOnesignalId: String?
var newExternalId: String?

for property in response {
switch property.key {
case "external_id":
Expand All @@ -108,18 +108,18 @@ class OSIdentityModel: OSModel {
}
fireUserStateChanged(newOnesignalId: newOnesignalId, newExternalId: newExternalId)
}

/**
Fires the user observer if `onesignal_id` OR `external_id` has changed from the previous snapshot (previous hydration).
*/
private func fireUserStateChanged(newOnesignalId: String?, newExternalId: String?) {
let prevOnesignalId = OneSignalUserDefaults.initShared().getSavedString(forKey: OS_SNAPSHOT_ONESIGNAL_ID, defaultValue: nil)
let prevExternalId = OneSignalUserDefaults.initShared().getSavedString(forKey: OS_SNAPSHOT_EXTERNAL_ID, defaultValue: nil)

guard prevOnesignalId != newOnesignalId || prevExternalId != newExternalId else {
return
}

OneSignalUserDefaults.initShared().saveString(forKey: OS_SNAPSHOT_ONESIGNAL_ID, withValue: newOnesignalId)
OneSignalUserDefaults.initShared().saveString(forKey: OS_SNAPSHOT_EXTERNAL_ID, withValue: newExternalId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityOperationExecutor: executeAddAliasesRequest making request: \(request)")

let backgroundTaskIdentifier = IDENTITY_EXECUTOR_BACKGROUND_TASK + UUID().uuidString
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier)
}

OneSignalClient.shared().execute(request) { _ in
// No hydration from response
// On success, remove request from cache
self.addRequestQueue.removeAll(where: { $0 == request})
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_IDENTITY_EXECUTOR_ADD_REQUEST_QUEUE_KEY, withValue: self.addRequestQueue)
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
} onFailure: { error in
Expand All @@ -198,7 +198,7 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
// Logout if the user in the SDK is the same
guard OneSignalUserManagerImpl.sharedInstance.isCurrentUser(request.identityModel)
else {
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
return
Expand All @@ -212,7 +212,7 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_IDENTITY_EXECUTOR_ADD_REQUEST_QUEUE_KEY, withValue: self.addRequestQueue)
}
}
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
}
Expand All @@ -230,21 +230,21 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSIdentityOperationExecutor: executeRemoveAliasRequest making request: \(request)")

let backgroundTaskIdentifier = IDENTITY_EXECUTOR_BACKGROUND_TASK + UUID().uuidString
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier)
}

OneSignalClient.shared().execute(request) { _ in
// There is nothing to hydrate
// On success, remove request from cache
self.removeRequestQueue.removeAll(where: { $0 == request})
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_IDENTITY_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY, withValue: self.removeRequestQueue)
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
} onFailure: { error in
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSIdentityOperationExecutor remove alias request failed with error: \(error.debugDescription)")

if let nsError = error as? NSError {
let responseType = OSNetworkingUtils.getResponseStatusType(nsError.code)
if responseType != .retryable {
Expand All @@ -254,7 +254,7 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_IDENTITY_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY, withValue: self.removeRequestQueue)
}
}
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class OSPropertiesModel: OSModel {
self.set(property: "location", newValue: location)
}
}

var timezoneId = TimeZone.current.identifier

var tags: [String: String] = [:]

// MARK: - Initialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
return
}
request.sentToClient = true

let backgroundTaskIdentifier = PROPERTIES_EXECUTOR_BACKGROUND_TASK + UUID().uuidString
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.beginBackgroundTask(backgroundTaskIdentifier)
}

OneSignalClient.shared().execute(request) { _ in
// On success, remove request from cache, and we do need to hydrate
// TODO: We need to hydrate after all ? What why ?
self.updateRequestQueue.removeAll(where: { $0 == request})
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_PROPERTIES_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, withValue: self.updateRequestQueue)
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
} onFailure: { error in
Expand All @@ -157,7 +157,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
// Logout if the user in the SDK is the same
guard OneSignalUserManagerImpl.sharedInstance.isCurrentUser(request.identityModel)
else {
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
return
Expand All @@ -171,7 +171,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_PROPERTIES_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, withValue: self.updateRequestQueue)
}
}
if (inBackground) {
if inBackground {
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
}
}
Expand All @@ -189,7 +189,7 @@ extension OSPropertyOperationExecutor {
modelToUpdate: propertiesModel,
identityModel: identityModel)

if (sendImmediately) {
if sendImmediately {
// Bypass the request queues
OneSignalClient.shared().execute(request) { _ in
if let onSuccess = onSuccess {
Expand Down
22 changes: 11 additions & 11 deletions iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class OSSubscriptionModel: OSModel {
self.set(property: "testType", newValue: testType)
}
}

var deviceOs = UIDevice.current.systemVersion {
didSet {
guard deviceOs != oldValue else {
Expand All @@ -212,7 +212,7 @@ class OSSubscriptionModel: OSModel {
self.set(property: "deviceOs", newValue: deviceOs)
}
}

var sdk = ONESIGNAL_VERSION {
didSet {
guard sdk != oldValue else {
Expand All @@ -221,7 +221,7 @@ class OSSubscriptionModel: OSModel {
self.set(property: "sdk", newValue: sdk)
}
}

var deviceModel: String? = OSDeviceUtils.getDeviceVariant() {
didSet {
guard deviceModel != oldValue else {
Expand All @@ -230,7 +230,7 @@ class OSSubscriptionModel: OSModel {
self.set(property: "deviceModel", newValue: deviceModel)
}
}

var appVersion: String? = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
didSet {
guard appVersion != oldValue else {
Expand All @@ -239,7 +239,7 @@ class OSSubscriptionModel: OSModel {
self.set(property: "appVersion", newValue: appVersion)
}
}

var netType: Int? = OSNetworkingUtils.getNetType() as? Int {
didSet {
guard netType != oldValue else {
Expand All @@ -266,7 +266,7 @@ class OSSubscriptionModel: OSModel {
if type == .push {
let releaseMode: OSUIApplicationReleaseMode = OneSignalMobileProvision.releaseMode()
#if targetEnvironment(simulator)
if (releaseMode == OSUIApplicationReleaseMode.UIApplicationReleaseUnknown) {
if releaseMode == OSUIApplicationReleaseMode.UIApplicationReleaseUnknown {
self.testType = OSUIApplicationReleaseMode.UIApplicationReleaseDev.rawValue
}
#endif
Expand Down Expand Up @@ -322,7 +322,7 @@ class OSSubscriptionModel: OSModel {
self.deviceModel = coder.decodeObject(forKey: "deviceModel") as? String
self.appVersion = coder.decodeObject(forKey: "appVersion") as? String
self.netType = coder.decodeObject(forKey: "netType") as? Int

super.init(coder: coder)
}

Expand Down Expand Up @@ -354,7 +354,7 @@ class OSSubscriptionModel: OSModel {
}
}
}

// Using snake_case so we can use this in request bodies
public func jsonRepresentation() -> [String: Any] {
var json: [String: Any] = [:]
Expand Down Expand Up @@ -401,7 +401,7 @@ extension OSSubscriptionModel {
func updateNotificationTypes() {
notificationTypes = Int(OSNotificationsManager.getNotificationTypes(_isDisabled))
}

func updateTestType() {
let releaseMode: OSUIApplicationReleaseMode = OneSignalMobileProvision.releaseMode()
// Workaround to unsure how to extract the Int value in 1 step...
Expand All @@ -415,7 +415,7 @@ extension OSSubscriptionModel {
self.testType = OSUIApplicationReleaseMode.UIApplicationReleaseWildcard.rawValue
}
}

func update() {
updateTestType()
deviceOs = UIDevice.current.systemVersion
Expand All @@ -429,7 +429,7 @@ extension OSSubscriptionModel {
OneSignalUserDefaults.initShared().saveString(forKey: OSUD_PUSH_SUBSCRIPTION_ID, withValue: subscriptionId)
}
}

enum OSPushPropertyChanged {
case subscriptionId(String?)
case reachable(Bool)
Expand Down
Loading

0 comments on commit 2228ed7

Please sign in to comment.