Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DIA-2151] Removed singleShotPM from ConsentActionImpl #657

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
1 change: 0 additions & 1 deletion cmplibrary/src/main/assets/js_receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function actionFromPM(payload) {
return {
localPmId: window.localPmId,
legislation: window.spLegislation,
singleShot: window.isSingleShot,
name: payload.name,
actionType: payload.actionType,
choiceId: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal class SpConsentLibImpl(
spClient.onConsentReady(spConsents)
(spClient as? UnitySpClient)?.onConsentReady(spConsentString)
executor.executeOnSingleThread {
clientEventManager.checkStatus()
clientEventManager.checkIfAllCampaignsWereProcessed()
}
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@ internal class SpConsentLibImpl(
},
pSuccess = {
val list = it.toCampaignModelList(logger = pLogger)
clientEventManager.setCampaignNumber(list.size)
clientEventManager.setCampaignsToProcess(list.size)
if (list.isEmpty()) {
consentManager.sendStoredConsentToClient()
return@getMessages
Expand Down Expand Up @@ -351,7 +351,7 @@ internal class SpConsentLibImpl(
useGroupPmIfAvailable: Boolean
) {
checkMainThread("loadPrivacyManager")
clientEventManager.executingLoadPM()
clientEventManager.setCampaignsToProcess(1)

val gdprGroupPmId = campaignManager.getGroupId(campaignType)

Expand Down Expand Up @@ -392,7 +392,6 @@ internal class SpConsentLibImpl(
url = url,
campaignType = campaignType,
pmId = it.messageId,
singleShot = true,
consent = JSONObject(storedConsent)
)
}
Expand Down Expand Up @@ -619,7 +618,6 @@ internal class SpConsentLibImpl(
url = url,
campaignType = actionImpl.campaignType,
pmId = actionImpl.privacyManagerId,
singleShot = true,
consent = JSONObject(dataStorage.gdprConsentStatus!!)
)
}
Expand All @@ -646,7 +644,6 @@ internal class SpConsentLibImpl(
url = url,
campaignType = actionImpl.campaignType,
pmId = actionImpl.privacyManagerId,
singleShot = false,
consent = JSONObject(dataStorage.ccpaConsentStatus!!)
)
}
Expand Down Expand Up @@ -679,7 +676,6 @@ internal class SpConsentLibImpl(
url = url,
campaignType = action.campaignType,
pmId = action.privacyManagerId,
singleShot = true,
consent = JSONObject(dataStorage.gdprConsentStatus!!)
)
}
Expand All @@ -706,7 +702,6 @@ internal class SpConsentLibImpl(
url = url,
campaignType = action.campaignType,
pmId = action.privacyManagerId,
singleShot = true,
consent = JSONObject(dataStorage.ccpaConsentStatus!!)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ import com.sourcepoint.cmplibrary.model.exposed.* // ktlint-disable
import com.sourcepoint.cmplibrary.util.check

internal interface ClientEventManager {

fun setCampaignNumber(campNum: Int)
fun executingLoadPM()
fun storedConsent()
fun setCampaignsToProcess(numberOfCampaigns: Int)
fun registerConsentResponse()
fun setAction(action: ConsentActionImpl)
fun setAction(action: NativeMessageActionType)
fun checkStatus()

fun checkIfAllCampaignsWereProcessed()
companion object
}

Expand All @@ -34,42 +31,35 @@ private class ClientEventManagerImpl(
val consentManagerUtils: ConsentManagerUtils,
) : ClientEventManager {

private var cNumber: Int = Int.MAX_VALUE
private var storedConsent: Int = 0

override fun setCampaignNumber(campNum: Int) {
cNumber = campNum
storedConsent = 0
}
private var campaignsToProcess: Int = Int.MAX_VALUE
private var isFirstLayerMessage = true

override fun executingLoadPM() {
cNumber = 1
storedConsent = 0
override fun setCampaignsToProcess(numberOfCampaigns: Int) {
campaignsToProcess = numberOfCampaigns
}

override fun setAction(action: ConsentActionImpl) {
executor.executeOnSingleThread {
when (action.actionType) {
ActionType.ACCEPT_ALL,
ActionType.REJECT_ALL,
ActionType.SAVE_AND_EXIT -> {
}
ActionType.SHOW_OPTIONS -> {
}
ActionType.UNKNOWN -> {
isFirstLayerMessage = false
}
ActionType.CUSTOM,
ActionType.MSG_CANCEL,
ActionType.PM_DISMISS -> {
if (!action.requestFromPm || action.singleShotPM) {
if (cNumber > 0) cNumber--
if (isFirstLayerMessage) {
campaignsToProcess--
}
isFirstLayerMessage = true
andresilveirah marked this conversation as resolved.
Show resolved Hide resolved
}
ActionType.GET_MSG_ERROR, ActionType.GET_MSG_NOT_CALLED -> {
cNumber = 0
campaignsToProcess = 0
}
else -> {
// do nothing
}
}
checkStatus()
checkIfAllCampaignsWereProcessed()
}
}

Expand All @@ -83,20 +73,19 @@ private class ClientEventManagerImpl(
NativeMessageActionType.UNKNOWN -> {
}
NativeMessageActionType.MSG_CANCEL -> {
if (cNumber > 0) cNumber--
if (campaignsToProcess > 0) campaignsToProcess--
}
NativeMessageActionType.GET_MSG_ERROR, NativeMessageActionType.GET_MSG_NOT_CALLED -> {
cNumber = 0
campaignsToProcess = 0
}
}
checkStatus()
checkIfAllCampaignsWereProcessed()
}
}

override fun checkStatus() {
if (cNumber == storedConsent) {
cNumber = Int.MAX_VALUE
storedConsent = 0
override fun checkIfAllCampaignsWereProcessed() {
if (campaignsToProcess <= 0) {
campaignsToProcess = Int.MAX_VALUE

val spConsent: SPConsents? = getSPConsents().getOrNull()
val spConsentString = spConsent
Expand All @@ -116,8 +105,8 @@ private class ClientEventManagerImpl(
}
}

override fun storedConsent() {
storedConsent++
override fun registerConsentResponse() {
campaignsToProcess--
}

private fun getSPConsents() = check<SPConsents> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private class ConsentManagerImpl(
service.sendConsent(actionImpl, env, sPConsentsSuccess, actionImpl.privacyManagerId)
.executeOnLeft { sPConsentsError?.invoke(it) }
.executeOnRight {
clientEventManager.storedConsent()
clientEventManager.registerConsentResponse()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ internal class ConsentWebView(
url: HttpUrl,
campaignType: CampaignType,
pmId: String?,
singleShot: Boolean,
consent: JSONObject
): Either<Boolean> = check {
if (!connectionManager.isConnected) throw NoInternetConnectionException(description = "No internet connection")
Expand All @@ -127,7 +126,6 @@ internal class ConsentWebView(
"""
javascript: window.spLegislation = '${campaignType.name}';
window.localPmId ='$pmId';
window.isSingleShot = $singleShot;
$jsReceiver;
window.postMessage($obj, "*");
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ internal interface IConsentWebView {
url: HttpUrl,
campaignType: CampaignType,
pmId: String?,
singleShot: Boolean,
consent: JSONObject
): Either<Boolean>
fun loadConsentUI(campaignModel: CampaignModel, url: HttpUrl, campaignType: CampaignType): Either<Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ internal fun String.toConsentAction(): ConsentActionImpl {
val actionType = (map["actionType"] as? Int)?.let { ActionType.values().find { v -> v.code == it } }
val choiceId = (map["choiceId"] as? String)
val legislation = map.getFieldValue<String>("legislation") ?: "CCPA"
val singleShot = map.getFieldValue<Boolean>("singleShot") ?: false
val privacyManagerId = (map["pmId"] as? String) ?: (map["localPmId"] as? String)
val pmTab = (map["pmTab"] as? String)
val requestFromPm = map.getFieldValue<Boolean>("requestFromPm") ?: false
Expand All @@ -57,7 +56,6 @@ internal fun String.toConsentAction(): ConsentActionImpl {
campaignType = CampaignType.valueOf(legislation),
customActionId = customActionId,
thisContent = map.toJSONObj(),
singleShotPM = singleShot
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ internal data class ConsentActionImpl(
override val requestFromPm: Boolean,
override val saveAndExitVariables: JSONObject = JSONObject(),
override val consentLanguage: String? = MessageLanguage.ENGLISH.value,
val singleShotPM: Boolean = false,
val saveAndExitVariablesOptimized: JsonObject = JsonObject(mapOf()),
val pmTab: String? = null,
val thisContent: JSONObject = JSONObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ data class ConsentActionImplOptimized(
@SerialName("pmTab") val pmTab: String? = null,
@SerialName("requestFromPm") override val requestFromPm: Boolean,
@SerialName("saveAndExitVariables") val saveAndExitVariablesOptimized: JsonObject = JsonObject(mapOf()),
@SerialName("singleShot") val singleShot: Boolean?,
@SerialName("pubData") override val pubData2: JsonObject = JsonObject(mapOf()),
@SerialName("singleShotPM") val singleShotPM: Boolean = false,
@SerialName("privacyManagerId") override val privacyManagerId: String? = null,
) : ConsentAction {
override val pubData: JSONObject
Expand Down
Loading