Skip to content

Commit

Permalink
remove modelToUpdate from the Update User request
Browse files Browse the repository at this point in the history
* We don't need the reference to the property model for an Update User request, and this reference has gone unused
* We don't hydrate anyway from the response as the response is not the full user, just the property that was updated.
  • Loading branch information
nan-li committed Apr 22, 2024
1 parent 98908ee commit 21661e5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
if var updateRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_PROPERTIES_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestUpdateProperties] {
// Hook each uncached Request to the model in the store
for (index, request) in updateRequestQueue.enumerated().reversed() {
// 0. Hook up the properties model if its the current user's so it can hydrate
if let propertiesModel = OneSignalUserManagerImpl.sharedInstance.propertiesModelStore.getModel(modelId: request.modelToUpdate.modelId) {
request.modelToUpdate = propertiesModel
}
if let identityModel = OneSignalUserManagerImpl.sharedInstance.identityModelStore.getModel(modelId: request.identityModel.modelId) {
// 1. The identity model exist in the store, set it to be the Request's models
request.identityModel = identityModel
Expand Down Expand Up @@ -112,7 +108,6 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
properties: [delta.property: delta.value],
deltas: nil,
refreshDeviceMetadata: false, // Sort this out.
modelToUpdate: model,
identityModel: OneSignalUserManagerImpl.sharedInstance.user.identityModel // TODO: Make sure this is ok
)
self.updateRequestQueue.append(request)
Expand Down Expand Up @@ -204,7 +199,6 @@ extension OSPropertyOperationExecutor {
properties: [:],
deltas: propertiesDeltas.jsonRepresentation(),
refreshDeviceMetadata: refreshDeviceMetadata,
modelToUpdate: propertiesModel,
identityModel: identityModel)

if sendImmediately {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ class OSRequestUpdateProperties: OneSignalRequest, OSUserRequest {
return stringDescription
}

// TODO: does updating properties even have a response in which we need to hydrate from? Then we can get rid of modelToUpdate
// Yes we may, if we cleared local state
var modelToUpdate: OSPropertiesModel
var identityModel: OSIdentityModel

// TODO: Decide if addPushSubscriptionIdToAdditionalHeadersIfNeeded should block.
Expand All @@ -55,8 +52,7 @@ class OSRequestUpdateProperties: OneSignalRequest, OSUserRequest {
}
}

init(properties: [String: Any], deltas: [String: Any]?, refreshDeviceMetadata: Bool?, modelToUpdate: OSPropertiesModel, identityModel: OSIdentityModel) {
self.modelToUpdate = modelToUpdate
init(properties: [String: Any], deltas: [String: Any]?, refreshDeviceMetadata: Bool?, identityModel: OSIdentityModel) {
self.identityModel = identityModel
self.stringDescription = "<OSRequestUpdateProperties with properties: \(properties) deltas: \(String(describing: deltas)) refreshDeviceMetadata: \(String(describing: refreshDeviceMetadata))>"
super.init()
Expand All @@ -79,7 +75,6 @@ class OSRequestUpdateProperties: OneSignalRequest, OSUserRequest {
}

func encode(with coder: NSCoder) {
coder.encode(modelToUpdate, forKey: "modelToUpdate")
coder.encode(identityModel, forKey: "identityModel")
coder.encode(parameters, forKey: "parameters")
coder.encode(method.rawValue, forKey: "method") // Encodes as String
Expand All @@ -88,7 +83,6 @@ class OSRequestUpdateProperties: OneSignalRequest, OSUserRequest {

required init?(coder: NSCoder) {
guard
let modelToUpdate = coder.decodeObject(forKey: "modelToUpdate") as? OSPropertiesModel,
let identityModel = coder.decodeObject(forKey: "identityModel") as? OSIdentityModel,
let rawMethod = coder.decodeObject(forKey: "method") as? UInt32,
let parameters = coder.decodeObject(forKey: "parameters") as? [String: Any],
Expand All @@ -97,7 +91,6 @@ class OSRequestUpdateProperties: OneSignalRequest, OSUserRequest {
// Log error
return nil
}
self.modelToUpdate = modelToUpdate
self.identityModel = identityModel
self.stringDescription = "<OSRequestUpdateProperties with parameters: \(parameters)>"
super.init()
Expand Down

0 comments on commit 21661e5

Please sign in to comment.