Skip to content

Commit c6f63c1

Browse files
nan-licursoragent
andcommitted
fix: restore local tags cleared by a concurrent FetchUser
On a successful UpdateProperties response, merge the server-confirmed tags back into the local model so a concurrent FetchUser whose response is missing the just-written tags can't leave the tag cache cleared. Merging (never replacing) keeps backend-managed tags intact; a "" value removes the tag. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent d218b53 commit c6f63c1

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSPropertyOperationExecutor.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,24 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
246246
}
247247

248248
OneSignalCoreImpl.sharedClient().execute(request) { response in
249-
// On success, remove request from cache, and we do need to hydrate
250-
// TODO: We need to hydrate after all ? What why ?
249+
// On success, remove request from cache
251250
self.dispatchQueue.async {
252251
self.updateRequestQueue.removeAll(where: { $0 == request})
253252
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_PROPERTIES_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, withValue: self.updateRequestQueue)
254253
if inBackground {
255254
OSBackgroundTaskManager.endBackgroundTask(backgroundTaskIdentifier)
256255
}
257256
}
257+
258+
// Re-assert the tags the server just confirmed by merging them back into the local model,
259+
// to remedy a concurrent FetchUser whose response is missing the just-written tags
260+
if OneSignalUserManagerImpl.sharedInstance.isCurrentUser(request.identityModel),
261+
let properties = response?["properties"] as? [String: Any],
262+
let confirmedTags = properties["tags"] as? [String: String],
263+
!confirmedTags.isEmpty {
264+
OneSignalUserManagerImpl.sharedInstance._user?.propertiesModel.mergeConfirmedTags(confirmedTags)
265+
}
266+
258267
if let onesignalId = request.identityModel.onesignalId {
259268
if let rywToken = response?["ryw_token"] as? String
260269
{

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertiesModel.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,25 @@ class OSPropertiesModel: OSModel {
151151
self.set(property: "tags", newValue: tagsToSend)
152152
}
153153

154+
/**
155+
Merges server-confirmed tags into the local model, without enqueuing a new delta.
156+
A value of `""` removes the tag.
157+
158+
Used to re-assert tags in order to remedy a concurrent FetchUser whose response
159+
may be missing the just-written tags.
160+
*/
161+
func mergeConfirmedTags(_ serverTags: [String: String]) {
162+
tagsLock.withLock {
163+
for (key, value) in serverTags {
164+
if value.isEmpty {
165+
self.tags.removeValue(forKey: key)
166+
} else {
167+
self.tags[key] = value
168+
}
169+
}
170+
}
171+
}
172+
154173
public override func hydrateModel(_ response: [String: Any]) {
155174
for property in response {
156175
switch property.key {

0 commit comments

Comments
 (0)