Skip to content

Commit f2ec786

Browse files
authored
Merge pull request #1681 from OneSignal/user-model/login-identity
[User Model] New login process and operation repo updates
2 parents 698b14f + 77793e8 commit f2ec786

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1033
-414
lines changed

Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/MainActivityViewModel.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,11 @@ private void setupAppLayout() {
395395

396396
switchUserButton.setOnClickListener(v -> {
397397
if(isLoggedIn) {
398-
OneSignal.logout();
399-
isLoggedIn = false;
400-
switchUserButton.setText(R.string.login_user);
401-
refreshState();
398+
OneSignal.logout(Continue.with(r -> {
399+
isLoggedIn = false;
400+
switchUserButton.setText(R.string.login_user);
401+
refreshState();
402+
}));
402403
}
403404
else {
404405
dialog.createUpdateAlertDialog(OneSignal.getUser().getExternalId(), Dialog.DialogAction.LOGIN, ProfileUtil.FieldType.EXTERNAL_USER_ID, new UpdateAlertDialogCallback() {

OneSignalSDK/onesignal/iam/src/main/java/com/onesignal/iam/internal/IAMManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import android.app.AlertDialog
44
import com.onesignal.common.AndroidUtils
55
import com.onesignal.common.IDManager
66
import com.onesignal.common.JSONUtils
7-
import com.onesignal.common.exceptions.BackendException
87
import com.onesignal.common.events.CallbackProducer
98
import com.onesignal.common.events.ICallbackProducer
9+
import com.onesignal.common.exceptions.BackendException
1010
import com.onesignal.common.modeling.ISingletonModelStoreChangeHandler
1111
import com.onesignal.common.modeling.ModelChangedArgs
1212
import com.onesignal.common.threading.suspendifyOnThread
@@ -193,7 +193,7 @@ internal class IAMManager(
193193
val appId = _configModelStore.model.appId
194194
val subscriptionId = _subscriptionManager.subscriptions.push?.id
195195

196-
if (subscriptionId == null || IDManager.isIdLocalOnly(subscriptionId) || appId.isEmpty()) {
196+
if (subscriptionId == null || IDManager.isLocalId(subscriptionId) || appId.isEmpty()) {
197197
return
198198
}
199199

OneSignalSDK/onesignal/notification/src/main/java/com/onesignal/notification/internal/NotificationsManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.onesignal.notification.internal
22

33
import android.app.Activity
4-
import com.onesignal.common.exceptions.BackendException
54
import com.onesignal.common.events.EventProducer
5+
import com.onesignal.common.exceptions.BackendException
66
import com.onesignal.common.threading.suspendifyOnMain
77
import com.onesignal.common.threading.suspendifyOnThread
88
import com.onesignal.core.internal.application.IApplicationService

OneSignalSDK/onesignal/src/main/java/com/onesignal/IOneSignal.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,5 @@ interface IOneSignal {
113113
* be retrieved, except through this device as long as the app remains installed and the app
114114
* data is not cleared.
115115
*/
116-
fun logout()
116+
suspend fun logout()
117117
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ object OneSignal {
178178
* data is not cleared.
179179
*/
180180
@JvmStatic
181-
fun logout() = oneSignal.logout()
181+
suspend fun logout() = oneSignal.logout()
182182

183183
private val oneSignal: IOneSignal by lazy {
184184
OneSignalImp()

OneSignalSDK/onesignal/src/main/java/com/onesignal/common/IDManager.kt

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,27 @@ package com.onesignal.common
33
import java.util.UUID
44

55
/**
6-
* Manages IDs that are initially generated locally, then regenerated on the backend. Generally when
7-
* resources are created they are first created with a locally generated ID. Once the resource
8-
* has been created on the backend that local ID is replaced with the backend one.
9-
*
10-
* The [IDManager] is able to handle IDs created locally in one application instance, and detected
11-
* as local/translated in a subsequent application instance.
6+
* Manages IDs that are created locally. Has the ability to generate globally unique identifiers
7+
* and detect whether a provided ID was generated locally.
128
*/
139
object IDManager {
1410
private const val LOCAL_PREFIX = "local-"
15-
private val _localIdMap = mutableMapOf<String, String?>()
1611

1712
/**
1813
* Create a new local ID to be used temporarily prior to backend generation.
1914
*
2015
* @return A new locally generated ID.
2116
*/
2217
fun createLocalId(): String {
23-
val newID = "$LOCAL_PREFIX${UUID.randomUUID()}"
24-
_localIdMap[newID] = null
25-
return newID
18+
return "$LOCAL_PREFIX${UUID.randomUUID()}"
2619
}
2720

2821
/**
29-
* Set the backend-generated ID for the previously locally-generated ID.
30-
*
31-
* @param localId The locally-generated ID previously generated via [createLocalId].
32-
* @param backendId The backend-generated ID.
33-
*/
34-
fun setLocalToBackendIdTranslation(localId: String, backendId: String) {
35-
_localIdMap[localId] = backendId
36-
}
37-
38-
/**
39-
* Determine whether the ID provided is locally generated, and has yet to have a backend-generated ID.
22+
* Determine whether the ID provided is locally generated.
4023
*
4124
* @param id The ID to test.
4225
*
43-
* @return true if the [id] provided was created via [createLocalId], but has not yet had
44-
* a backend-generated ID set via [setLocalToBackendIdTranslation].
45-
*/
46-
fun isIdLocalOnly(id: String): Boolean = id.startsWith(LOCAL_PREFIX)
47-
48-
/**
49-
* Retrieve the provided ID. Will retrieve the backend-generated ID if there is one, falling
50-
* back to the provided ID if there is not.
51-
*
52-
* @param id The ID to retrieve.
53-
*
54-
* @return The backend-generated ID, or the ID provided if there is no backend-generated ID.
26+
* @return true if the [id] provided was created via [createLocalId].
5527
*/
56-
fun retrieveId(id: String): String = _localIdMap[id] ?: id
28+
fun isLocalId(id: String): Boolean = id.startsWith(LOCAL_PREFIX)
5729
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/common/JSONObjectExtensions.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ fun JSONObject.safeInt(name: String): Int? {
1717
return null
1818
}
1919

20+
/**
21+
* Retrieve an [Long] from the [JSONObject] safely.
22+
*
23+
* @param name The name of the attribute that contains an [Int] value.
24+
*
25+
* @return The [Long] value if it exists, null otherwise.
26+
*/
27+
fun JSONObject.safeLong(name: String): Long? {
28+
if (this.has(name)) {
29+
return this.getLong(name)
30+
}
31+
32+
return null
33+
}
34+
2035
/**
2136
* Retrieve a [Boolean] from the [JSONObject] safely.
2237
*

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/backend/IParamsBackendService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ParamsObject(
3030
var unsubscribeWhenNotificationsDisabled: Boolean? = null,
3131
var locationShared: Boolean? = null,
3232
var requiresUserPrivacyConsent: Boolean? = null,
33+
var opRepoExecutionInterval: Long? = null,
3334
var influenceParams: InfluenceParamsObject,
3435
var fcmParams: FCMParamsObject
3536
)

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/backend/impl/ParamsBackendService.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.onesignal.core.internal.backend.impl
22

3+
import com.onesignal.common.IDManager
34
import com.onesignal.common.exceptions.BackendException
45
import com.onesignal.common.expand
56
import com.onesignal.common.safeBool
67
import com.onesignal.common.safeInt
8+
import com.onesignal.common.safeLong
79
import com.onesignal.common.safeString
810
import com.onesignal.core.internal.backend.FCMParamsObject
911
import com.onesignal.core.internal.backend.IParamsBackendService
@@ -23,7 +25,7 @@ internal class ParamsBackendService(
2325
Logging.log(LogLevel.DEBUG, "ParamsBackendService.fetchParams(appId: $appId, subscriptionId: $subscriptionId)")
2426

2527
var paramsUrl = "apps/$appId/android_params.js"
26-
if (subscriptionId != null) {
28+
if (subscriptionId != null && !IDManager.isLocalId(subscriptionId)) {
2729
paramsUrl += "?player_id=$subscriptionId"
2830
}
2931

@@ -64,6 +66,7 @@ internal class ParamsBackendService(
6466
unsubscribeWhenNotificationsDisabled = responseJson.safeBool("unsubscribe_on_notifications_disabled"),
6567
locationShared = responseJson.safeBool("location_shared"),
6668
requiresUserPrivacyConsent = responseJson.safeBool("requires_user_privacy_consent"),
69+
opRepoExecutionInterval = responseJson.safeLong("oprepo_execution_interval"), // TODO: New
6770
influenceParams = influenceParams ?: InfluenceParamsObject(),
6871
fcmParams = fcmParams ?: FCMParamsObject()
6972
)

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/config/ConfigModel.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ class ConfigModel : Model() {
6161
get() = getProperty(::sessionFocusTimeout.name) { 30000 }
6262
set(value) { setProperty(::sessionFocusTimeout.name, value) }
6363

64+
/**
65+
* The minimum number of milliseconds required to pass before executing another operation on
66+
* the queue.
67+
*/
68+
var opRepoExecutionInterval: Long
69+
get() = getProperty(::opRepoExecutionInterval.name) { 5000 }
70+
set(value) { setProperty(::opRepoExecutionInterval.name, value) }
71+
6472
/**
6573
* The minimum number of milliseconds required to pass to allow the fetching of IAM to occur.
6674
*/
@@ -79,7 +87,7 @@ class ConfigModel : Model() {
7987
* Whether the current application is an enterprise-level
8088
*/
8189
var enterprise: Boolean
82-
get() = getProperty(::enterprise.name)
90+
get() = getProperty(::enterprise.name) { false }
8391
set(value) { setProperty(::enterprise.name, value) }
8492

8593
/**
@@ -107,14 +115,14 @@ class ConfigModel : Model() {
107115
* Whether to honor TTL for notifications
108116
*/
109117
var restoreTTLFilter: Boolean
110-
get() = getProperty(::restoreTTLFilter.name) { false }
118+
get() = getProperty(::restoreTTLFilter.name) { true }
111119
set(value) { setProperty(::restoreTTLFilter.name, value) }
112120

113121
/**
114122
* Whether to track notification receive receipts
115123
*/
116124
var receiveReceiptEnabled: Boolean
117-
get() = getProperty(::receiveReceiptEnabled.name) { true }
125+
get() = getProperty(::receiveReceiptEnabled.name) { false }
118126
set(value) { setProperty(::receiveReceiptEnabled.name, value) }
119127

120128
/**

0 commit comments

Comments
 (0)