Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -4,6 +4,7 @@ import android.content.Context
import com.onesignal.IOneSignal
import com.onesignal.common.IDManager
import com.onesignal.common.OneSignalUtils
import com.onesignal.common.exceptions.BackendException
import com.onesignal.common.modeling.ModelChangeTags
import com.onesignal.common.modules.IModule
import com.onesignal.common.safeString
Expand Down Expand Up @@ -254,7 +255,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
Logging.log(LogLevel.DEBUG, "login(externalId: $externalId, jwtBearerToken: $jwtBearerToken)")

if (!isInitialized) {
throw Exception("Must call 'initWithContext' before use")
Logging.log(LogLevel.ERROR, "Must call 'initWithContext' before using Login")
}

var currentIdentityExternalId: String? = null
Expand Down Expand Up @@ -306,28 +307,29 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
)

if (!result) {
throw Exception("Could not login user")
Logging.log(LogLevel.ERROR, "Could not login user")
} else {
// enqueue a RefreshUserOperation to pull the user from the backend and refresh the models.
// This is a separate enqueue operation to ensure any outstanding operations that happened
// after the createAndSwitchToNewUser have been executed, and the retrieval will be the
// most up to date reflection of the user.
_operationRepo!!.enqueueAndWait(
RefreshUserOperation(
_configModel!!.appId,
_identityModelStore!!.model.onesignalId,
),
true,
)
}

// enqueue a RefreshUserOperation to pull the user from the backend and refresh the models.
// This is a separate enqueue operation to ensure any outstanding operations that happened
// after the createAndSwitchToNewUser have been executed, and the retrieval will be the
// most up to date reflection of the user.
_operationRepo!!.enqueueAndWait(
RefreshUserOperation(
_configModel!!.appId,
_identityModelStore!!.model.onesignalId,
),
true,
)
}
}

override fun logout() {
Logging.log(LogLevel.DEBUG, "logout()")

if (!isInitialized) {
throw Exception("Must call 'initWithContext' before use")
Logging.log(LogLevel.ERROR, "Must call 'initWithContext' before using Login")
return
}

// only allow one login/logout at a time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ internal open class UserManager(
Logging.log(LogLevel.DEBUG, "setAlias(label: $label, id: $id)")

if (label.isEmpty()) {
throw Exception("Cannot add empty alias")
Logging.log(LogLevel.ERROR, "Cannot add empty alias")
return
}

if (label == IdentityConstants.ONESIGNAL_ID) {
throw Exception("Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias")
Logging.log(LogLevel.ERROR, "Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias")
return
}

_identityModel[label] = id
Expand All @@ -65,11 +67,13 @@ internal open class UserManager(

aliases.forEach {
if (it.key.isEmpty()) {
throw Exception("Cannot add empty alias")
Logging.log(LogLevel.ERROR, "Cannot add empty alias")
return
}

if (it.key == IdentityConstants.ONESIGNAL_ID) {
throw Exception("Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias")
Logging.log(LogLevel.ERROR, "Cannot add '${IdentityConstants.ONESIGNAL_ID}' alias")
return
}
}

Expand All @@ -82,11 +86,13 @@ internal open class UserManager(
Logging.log(LogLevel.DEBUG, "removeAlias(label: $label)")

if (label.isEmpty()) {
throw Exception("Cannot remove empty alias")
Logging.log(LogLevel.ERROR, "Cannot remove empty alias")
return
}

if (label == IdentityConstants.ONESIGNAL_ID) {
throw Exception("Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias")
Logging.log(LogLevel.ERROR, "Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias")
return
}

_identityModel.remove(label)
Expand All @@ -97,11 +103,13 @@ internal open class UserManager(

labels.forEach {
if (it.isEmpty()) {
throw Exception("Cannot remove empty alias")
Logging.log(LogLevel.ERROR, "Cannot remove empty alias")
return
}

if (it == IdentityConstants.ONESIGNAL_ID) {
throw Exception("Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias")
Logging.log(LogLevel.ERROR, "Cannot remove '${IdentityConstants.ONESIGNAL_ID}' alias")
return
}
}

Expand All @@ -114,7 +122,8 @@ internal open class UserManager(
Logging.log(LogLevel.DEBUG, "addEmail(email: $email)")

if (!OneSignalUtils.isValidEmail(email)) {
throw Exception("Cannot add invalid email address as subscription: $email")
Logging.log(LogLevel.ERROR, "Cannot add invalid email address as subscription: $email")
return
}

_subscriptionManager.addEmailSubscription(email)
Expand All @@ -124,7 +133,8 @@ internal open class UserManager(
Logging.log(LogLevel.DEBUG, "removeEmail(email: $email)")

if (!OneSignalUtils.isValidEmail(email)) {
throw Exception("Cannot remove invalid email address as subscription: $email")
Logging.log(LogLevel.ERROR, "Cannot remove invalid email address as subscription: $email")
return
}

_subscriptionManager.removeEmailSubscription(email)
Expand All @@ -134,7 +144,8 @@ internal open class UserManager(
Logging.log(LogLevel.DEBUG, "addSms(sms: $sms)")

if (!OneSignalUtils.isValidPhoneNumber(sms)) {
throw Exception("Cannot add invalid sms number as subscription: $sms")
Logging.log(LogLevel.ERROR, "Cannot add invalid sms number as subscription: $sms")
return
}

_subscriptionManager.addSmsSubscription(sms)
Expand All @@ -144,7 +155,8 @@ internal open class UserManager(
Logging.log(LogLevel.DEBUG, "removeSms(sms: $sms)")

if (!OneSignalUtils.isValidPhoneNumber(sms)) {
throw Exception("Cannot remove invalid sms number as subscription: $sms")
Logging.log(LogLevel.ERROR, "Cannot remove invalid sms number as subscription: $sms")
return
}

_subscriptionManager.removeSmsSubscription(sms)
Expand All @@ -154,7 +166,8 @@ internal open class UserManager(
Logging.log(LogLevel.DEBUG, "setTag(key: $key, value: $value)")

if (key.isEmpty()) {
throw Exception("Cannot add tag with empty key")
Logging.log(LogLevel.ERROR, "Cannot add tag with empty key")
return
}

_propertiesModel.tags[key] = value
Expand All @@ -165,7 +178,8 @@ internal open class UserManager(

tags.forEach {
if (it.key.isEmpty()) {
throw Exception("Cannot add tag with empty key")
Logging.log(LogLevel.ERROR, "Cannot add tag with empty key")
return
}
}

Expand All @@ -178,7 +192,8 @@ internal open class UserManager(
Logging.log(LogLevel.DEBUG, "removeTag(key: $key)")

if (key.isEmpty()) {
throw Exception("Cannot remove tag with empty key")
Logging.log(LogLevel.ERROR, "Cannot remove tag with empty key")
return
}

_propertiesModel.tags.remove(key)
Expand All @@ -189,7 +204,8 @@ internal open class UserManager(

keys.forEach {
if (it.isEmpty()) {
throw Exception("Cannot remove tag with empty key")
Logging.log(LogLevel.ERROR, "Cannot remove tag with empty key")
return
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal class InAppBackendService(

override suspend fun getIAMData(appId: String, messageId: String, variantId: String?): GetIAMDataResponse {
val htmlPath = htmlPathForMessage(messageId, variantId, appId)
?: throw Exception("variantId not valid: $variantId")
?: return GetIAMDataResponse(null, false)

val response = _httpClient.get(htmlPath, null)

Expand Down