Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.onesignal.session.internal.session.ISessionService
import com.onesignal.user.internal.identity.IdentityModelStore
import com.onesignal.user.internal.operations.TrackSessionEndOperation
import com.onesignal.user.internal.operations.TrackSessionStartOperation
import com.onesignal.user.internal.properties.PropertiesModelStore

/**
* The [SessionListener] is responsible for subscribing itself as an [ISessionLifecycleHandler]
Expand All @@ -33,13 +34,16 @@ internal class SessionListener(
private val _sessionService: ISessionService,
private val _configModelStore: ConfigModelStore,
private val _identityModelStore: IdentityModelStore,
private val _propertiesModelStore: PropertiesModelStore,
private val _outcomeEventsController: IOutcomeEventsController,
) : IStartableService, ISessionLifecycleHandler {
override fun start() {
_sessionService.subscribe(this)
}

override fun onSessionStarted() {
// Detect any user updates to send with the TrackSessionStartOperation
_propertiesModelStore.model.update()
_operationRepo.enqueue(TrackSessionStartOperation(_configModelStore.model.appId, _identityModelStore.model.onesignalId), true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ internal class RefreshUserOperationExecutor(
}
}

if (response.properties.timezoneId != null) {
propertiesModel.timezone = response.properties.timezoneId
}
// No longer hydrate timezone from remote, set locally
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with this.

propertiesModel.update()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be done on a background thread?

Copy link
Contributor Author

@nan-li nan-li Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before, propertiesModel.update() just sets propertiesModel.timezone = TimeUtils.getTimeZoneId(). If we look at the lines above this, we are setting various properties on the propertiesModel like:

propertiesModel.country = response.properties.country
propertiesModel.tags[tagKVP.key] = tagKVP.value!!
propertiesModel.language = response.properties.language

Setting timezone shouldn't run separately while this object is being set up. Also, during this time while the model is being set up, no updates will fire an operation to enqueue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good around the background thread. but we definitely need to write a test if the properties.update() is called and if the timezone is actually set.
this helps in possible regression defects and helps us gain confidence when we are making changes.


val subscriptionModels = mutableListOf<SubscriptionModel>()
for (subscription in response.subscriptions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.onesignal.user.internal.properties

import com.onesignal.common.TimeUtils
import com.onesignal.common.modeling.MapModel
import com.onesignal.common.modeling.Model
import org.json.JSONObject
Expand Down Expand Up @@ -122,4 +123,8 @@ class PropertiesModel : Model() {

return null
}

fun update() {
timezone = TimeUtils.getTimeZoneId()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this TimeUtils.getTimeZoneId() match with what the backend really expects?
Can we write a test to make sure that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it does. Currently, the only place the SDK ever sends timezone is in a create user call here:

// the non-null assert is actually extraneous
properties["timezone_id"] = TimeUtils.getTimeZoneId()!!

does this TimeUtils.getTimeZoneId() match with what the backend really expects? Can we write a test to make sure that?

I don't know how we could write a test for what the server expects. We could write a test that ensures timezone is always sent as a certain format, but if the backend ever changed its expectation, we wouldn't know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, we cant test server expectations directly. But we should write tests to catch internal breaking changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the model classes should be very simple and all setting should done outside of it. So we shouldn't add a helper like this that is set a specific implementation of getting timezone.

}
}
Loading