Skip to content

Commit

Permalink
resolve conflicts between main and user-model/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jinliu9508 committed Feb 6, 2024
1 parent d15ee42 commit d73bfc6
Show file tree
Hide file tree
Showing 33 changed files with 71 additions and 12,175 deletions.
4 changes: 2 additions & 2 deletions OneSignalSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ buildscript {
huaweiHMSLocationVersion = '4.0.0.300'
kotlinVersion = '1.7.10'
kotestVersion = '5.5.0'
ktlintPluginVersion = '11.3.1'
ktlintVersion = '0.48.2'
ktlintPluginVersion = '11.6.1'
ktlintVersion = '1.0.1'
junitVersion = '4.13.2'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ fun JSONObject.safeLong(name: String): Long? {
}

/**
* Retrieve an [Double] from the [JSONObject] safely.
* Retrieve a [Double] from the [JSONObject] safely.
*
* @param name The name of the attribute that contains an [Int] value.
* @param name The name of the attribute that contains a [Double] value.
*
* @return The [Double] value if it exists, null otherwise.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@ open class EventProducer<THandler> : IEventNotifier<THandler> {
private val subscribers: MutableList<THandler> = Collections.synchronizedList(mutableListOf())

override fun subscribe(handler: THandler) {
subscribers.add(handler)
synchronized(subscribers) {
subscribers.add(handler)
}
}

override fun unsubscribe(handler: THandler) {
subscribers.remove(handler)
synchronized(subscribers) {
subscribers.remove(handler)
}
}

/**
* Subscribe all from an existing producer to this subscriber.
*/
fun subscribeAll(from: EventProducer<THandler>) {
for (s in from.subscribers) {
subscribe(s)
synchronized(subscribers) {
for (s in from.subscribers) {
subscribe(s)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ abstract class ModelStore<TModel>(
model: TModel,
tag: String,
) {
val oldModel = models.firstOrNull { it.id == model.id }
if (oldModel != null) {
removeItem(oldModel, tag)
}
synchronized(models) {
val oldModel = models.firstOrNull { it.id == model.id }
if (oldModel != null) {
removeItem(oldModel, tag)
}

addItem(model, tag)
}
Expand All @@ -54,10 +55,11 @@ abstract class ModelStore<TModel>(
model: TModel,
tag: String,
) {
val oldModel = models.firstOrNull { it.id == model.id }
if (oldModel != null) {
removeItem(oldModel, tag)
}
synchronized(models) {
val oldModel = models.firstOrNull { it.id == model.id }
if (oldModel != null) {
removeItem(oldModel, tag)
}

addItem(model, tag, index)
}
Expand All @@ -75,8 +77,10 @@ abstract class ModelStore<TModel>(
id: String,
tag: String,
) {
val model = models.firstOrNull { it.id == id } ?: return
removeItem(model, tag)
synchronized(models) {
val model = models.firstOrNull { it.id == id } ?: return
removeItem(model, tag)
}
}

override fun onChanged(
Expand All @@ -91,7 +95,8 @@ abstract class ModelStore<TModel>(
models: List<TModel>,
tag: String,
) {
clear(tag)
synchronized(models) {
clear(tag)

for (model in models) {
add(model, tag)
Expand All @@ -118,11 +123,12 @@ abstract class ModelStore<TModel>(
tag: String,
index: Int? = null,
) {
if (index != null) {
models.add(index, model)
} else {
models.add(model)
}
synchronized(models) {
if (index != null) {
models.add(index, model)
} else {
models.add(model)
}

// listen for changes to this model
model.subscribe(this)
Expand All @@ -136,7 +142,8 @@ abstract class ModelStore<TModel>(
model: TModel,
tag: String,
) {
models.remove(model)
synchronized(models) {
models.remove(model)

// no longer listen for changes to this model
model.unsubscribe(this)
Expand All @@ -147,23 +154,29 @@ abstract class ModelStore<TModel>(
}

protected fun load() {
if (name != null && _prefs != null) {
val str = _prefs.getString(PreferenceStores.ONESIGNAL, PreferenceOneSignalKeys.MODEL_STORE_PREFIX + name, "[]")
val jsonArray = JSONArray(str)
for (index in 0 until jsonArray.length()) {
val newModel = create(jsonArray.getJSONObject(index)) ?: continue
models.add(newModel)
// listen for changes to this model
newModel.subscribe(this)
synchronized(models) {
if (name != null && _prefs != null) {
val str = _prefs.getString(PreferenceStores.ONESIGNAL, PreferenceOneSignalKeys.MODEL_STORE_PREFIX + name, "[]")
val jsonArray = JSONArray(str)
for (index in 0 until jsonArray.length()) {
val newModel = create(jsonArray.getJSONObject(index)) ?: continue
models.add(newModel)
// listen for changes to this model
newModel.subscribe(this)
}
}
}
}

fun persist() {
if (name != null && _prefs != null) {
val jsonArray = JSONArray()
for (model in models) {
jsonArray.put(model.toJSON())
synchronized(models) {
if (name != null && _prefs != null) {
val jsonArray = JSONArray()
for (model in models) {
jsonArray.put(model.toJSON())
}

_prefs.saveString(PreferenceStores.ONESIGNAL, PreferenceOneSignalKeys.MODEL_STORE_PREFIX + name, jsonArray.toString())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ open class SingletonModelStore<TModel>(

override val model: TModel
get() {
val model = store.get(singletonId)
if (model != null) {
return model
}
synchronized(this) {
val model = store.get(singletonId)
if (model != null) {
return model
}

val createdModel = store.create() ?: throw Exception("Unable to initialize model from store $store")
createdModel.id = singletonId
store.add(createdModel)
return createdModel
val createdModel = store.create() ?: throw Exception("Unable to initialize model from store $store")
createdModel.id = singletonId
store.add(createdModel)
return createdModel
}
}

override fun replace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.onesignal.user.internal.subscriptions.SubscriptionModel
import com.onesignal.user.internal.subscriptions.SubscriptionModelStore
import com.onesignal.user.internal.subscriptions.SubscriptionStatus
import com.onesignal.user.internal.subscriptions.SubscriptionType
import org.json.JSONObject

internal class OneSignalImp : IOneSignal, IServiceProvider {
override val sdkVersion: String = OneSignalUtils.SDK_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ internal class LoginUserOperationExecutor(
var identities = mapOf<String, String>()
var subscriptions = mapOf<String, SubscriptionObject>()
val properties = mutableMapOf<String, String>()
properties["timezone_id"] = TimeUtils.getTimeZoneId()
properties["timezone_id"] = TimeUtils.getTimeZoneId()!!
properties["language"] = _languageContext.language

if (createUserOperation.externalId != null) {
val mutableIdentities = identities.toMutableMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RefreshUserOperationExecutorTests : FunSpec({
CreateUserResponse(
mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId, "aliasLabel1" to "aliasValue1"),
PropertiesObject(country = "US"),
listOf(SubscriptionObject(remoteSubscriptionId1, SubscriptionObjectType.ANDROID_PUSH, enabled = true, token = "pushToken"), SubscriptionObject(remoteSubscriptionId2, SubscriptionObjectType.EMAIL, token = "[email protected]")),
listOf(SubscriptionObject(existingSubscriptionId1, SubscriptionObjectType.ANDROID_PUSH, enabled = true, token = "pushToken1"), SubscriptionObject(remoteSubscriptionId1, SubscriptionObjectType.ANDROID_PUSH, enabled = true, token = "pushToken2"), SubscriptionObject(remoteSubscriptionId2, SubscriptionObjectType.EMAIL, token = "[email protected]")),
)

// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ internal object NavigateToAndroidSettingsForNotifications {

// for Android 5-7
intent.putExtra("app_package", context.getPackageName())
val applicationInfo = ApplicationInfoHelper.getInfo(context)
if (applicationInfo != null) {
intent.putExtra("app_uid", applicationInfo.uid)
}
intent.putExtra("app_uid", context.getApplicationInfo().uid)

// for Android 8 and above
intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName())
Expand Down
Loading

0 comments on commit d73bfc6

Please sign in to comment.