Skip to content

Commit

Permalink
Make NewRecordsState method non-optional
Browse files Browse the repository at this point in the history
* The canAccess method should really check a non-optional string
* Adjust the use of this method at the calling site
  • Loading branch information
nan-li committed Aug 16, 2024
1 parent dee1bcf commit c6db876
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ public class OSNewRecordsState {
}
}

public func canAccess(_ key: String?) -> Bool {
public func canAccess(_ key: String) -> Bool {
lock.withLock {
guard let key = key,
let timeLastMovedOrCreated = records[key]
else {
guard let timeLastMovedOrCreated = records[key] else {
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,21 @@ class OSRequestCreateUser: OneSignalRequest, OSUserRequest {

/// Checks if the subscription ID can be accessed, if a subscription is being included in the request
func prepareForExecution(newRecordsState: OSNewRecordsState) -> Bool {
guard let appId = OneSignalConfigManager.getAppId(),
newRecordsState.canAccess(pushSubscriptionModel?.subscriptionId)
else {
guard let appId = OneSignalConfigManager.getAppId() else {
OneSignalLog.onesignalLog(.LL_ERROR, message: "Cannot generate the create user request due to null app ID.")
return false
}

if let subscriptionId = pushSubscriptionModel?.subscriptionId,
!newRecordsState.canAccess(subscriptionId)
{
OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot generate the create user request yet.")
return false
}

_ = self.addPushSubscriptionIdToAdditionalHeaders()
self.addJWTHeader(identityModel: identityModel)
self.path = "apps/\(appId)/users"
// The pushSub doesn't need to have a token.
return true
}

Expand Down

0 comments on commit c6db876

Please sign in to comment.