Skip to content

Commit 53cbab4

Browse files
authored
PIR: User Extract actionr response instead of meta (#6168)
Task/Issue URL: https://app.asana.com/1/137249556945/project/488551667048375/task/1210386349388281?focus=true ### Description See attached task description ### Steps to test this PR https://app.asana.com/1/137249556945/task/1210437341069871?focus=true
1 parent 165abbe commit 53cbab4

File tree

8 files changed

+24
-49
lines changed

8 files changed

+24
-49
lines changed

pir/pir-internal/src/main/java/com/duckduckgo/pir/internal/common/BrokerStepsParser.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ class RealBrokerStepsParser @Inject constructor(
105105
if (this is OptOutStep) {
106106
this.copy(
107107
brokerName = brokerName,
108-
profilesToOptOut = repository.getExtractProfileResultForBroker(brokerName)?.extractResults?.filter {
109-
it.result
110-
}?.map {
111-
it.scrapedData
112-
} ?: emptyList(),
108+
profilesToOptOut = repository.getExtractProfileResultForBroker(brokerName)?.extractResults ?: emptyList(),
113109
)
114110
} else {
115111
(this as ScanStep).copy(brokerName = brokerName)

pir/pir-internal/src/main/java/com/duckduckgo/pir/internal/common/actions/EmailReceivedEventHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class EmailReceivedEventHandler @Inject constructor() : EventHandler {
6262
extractedProfile = extractedProfileWithEmail.run {
6363
ExtractedProfileParams(
6464
name = this.name,
65-
profileUrl = this.profileUrl?.profileUrl,
65+
profileUrl = this.profileUrl,
6666
fullName = state.profileQuery?.fullName,
6767
email = this.email,
6868
)

pir/pir-internal/src/main/java/com/duckduckgo/pir/internal/common/actions/ExecuteNextBrokerActionEventHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class ExecuteNextBrokerActionEventHandler @Inject constructor() : EventHandler {
144144
extractedProfile = extractedProfile.run {
145145
ExtractedProfileParams(
146146
name = this.name,
147-
profileUrl = this.profileUrl?.profileUrl,
147+
profileUrl = this.profileUrl,
148148
fullName = state.profileQuery?.fullName,
149149
email = this.email,
150150
)

pir/pir-internal/src/main/java/com/duckduckgo/pir/internal/scripts/models/PirScriptProfile.kt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,17 @@ data class Address(
4545
data class ExtractedProfile(
4646
val id: Int? = null,
4747
val name: String? = null,
48-
val alternativeNamesList: List<String>? = emptyList(),
49-
val addressFull: List<AddressCityState>? = emptyList(),
50-
val addressCityState: List<AddressCityState>? = emptyList(),
51-
val phoneNumbers: List<String>? = null,
52-
val relativesList: List<String>? = null,
53-
val profileUrl: ProfileUrl? = null,
54-
val reportId: String? = null,
48+
val alternativeNames: List<String>? = emptyList(),
5549
val age: String? = null,
50+
val addresses: List<AddressCityState>? = emptyList(),
51+
val phoneNumbers: List<String>? = emptyList(),
52+
val relatives: List<String>? = emptyList(),
53+
val profileUrl: String? = null,
54+
val identifier: String? = null,
55+
val reportId: String? = null,
5656
val email: String? = null,
5757
val removedDate: String? = null,
5858
val fullName: String? = null,
59-
val identifier: String? = null,
60-
)
61-
62-
data class ProfileUrl(
63-
val profileUrl: String,
64-
val identifier: String,
6559
)
6660

6761
data class AddressCityState(

pir/pir-internal/src/main/java/com/duckduckgo/pir/internal/scripts/models/PirScriptResponseParams.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,11 @@ sealed class PirSuccessResponse(
4747
data class ExtractedResponse(
4848
override val actionID: String,
4949
override val actionType: String,
50+
val response: List<ExtractedProfile>,
5051
val meta: AdditionalData? = null,
5152
) : PirSuccessResponse(actionID, actionType) {
5253
data class AdditionalData(
5354
val userData: ProfileQuery,
54-
val extractResults: List<ScrapedData>,
55-
)
56-
data class ScrapedData(
57-
val scrapedData: ExtractedProfile,
58-
val result: Boolean,
59-
val score: Int,
60-
val matchedFields: List<String>,
6155
)
6256
}
6357

@@ -83,6 +77,7 @@ sealed class PirSuccessResponse(
8377
data class ResponseData(
8478
val callback: CallbackData,
8579
)
80+
8681
data class CallbackData(
8782
val eval: String,
8883
)

pir/pir-internal/src/main/java/com/duckduckgo/pir/internal/settings/PirDevScanActivity.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,12 @@ class PirDevScanActivity : DuckDuckGoActivity() {
122122
private fun render(results: List<ScanResult>) {
123123
val allExtracted = results.filterIsInstance<ExtractedProfileResult>()
124124
val brokersWithRecords = allExtracted.filter {
125-
it.extractResults.isNotEmpty() && it.extractResults.any { result ->
126-
result.result
127-
}
125+
it.extractResults.isNotEmpty()
128126
}
129127
val brokersWithRecordsCount = brokersWithRecords.size
130128

131129
val totalRecordCount = brokersWithRecords.sumOf {
132-
it.extractResults.filter { result -> result.result }.size
130+
it.extractResults.size
133131
}
134132

135133
with(binding) {
@@ -141,7 +139,7 @@ class PirDevScanActivity : DuckDuckGoActivity() {
141139

142140
recordStringBuilder.append("\nRecords found:\n")
143141
brokersWithRecords.forEach { broker ->
144-
val recordCount = broker.extractResults.filter { it.result }.size
142+
val recordCount = broker.extractResults.size
145143
recordStringBuilder.append("${broker.brokerName} - records: $recordCount\n")
146144
}
147145
this.records.text = recordStringBuilder.toString()

pir/pir-internal/src/main/java/com/duckduckgo/pir/internal/settings/PirResultsActivity.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ class PirResultsActivity : DuckDuckGoActivity() {
126126
}
127127

128128
is ExtractedProfileResult -> {
129-
val records = it.extractResults.filter {
130-
it.result
131-
}.size
129+
val records = it.extractResults.size
132130
stringBuilder.append("VALID RECORDS FOUND COUNT: $records\n")
133131
}
134132

pir/pir-internal/src/main/java/com/duckduckgo/pir/internal/store/PirRepository.kt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.duckduckgo.common.utils.DispatcherProvider
2121
import com.duckduckgo.pir.internal.scripts.models.ExtractedProfile
2222
import com.duckduckgo.pir.internal.scripts.models.PirErrorReponse
2323
import com.duckduckgo.pir.internal.scripts.models.PirSuccessResponse.ExtractedResponse
24-
import com.duckduckgo.pir.internal.scripts.models.PirSuccessResponse.ExtractedResponse.ScrapedData
2524
import com.duckduckgo.pir.internal.scripts.models.PirSuccessResponse.NavigateResponse
2625
import com.duckduckgo.pir.internal.scripts.models.ProfileQuery
2726
import com.duckduckgo.pir.internal.service.DbpService
@@ -53,7 +52,6 @@ import com.duckduckgo.pir.internal.store.db.ScanResultsDao
5352
import com.duckduckgo.pir.internal.store.db.UserProfile
5453
import com.duckduckgo.pir.internal.store.db.UserProfileDao
5554
import com.squareup.moshi.Moshi
56-
import java.util.regex.Pattern
5755
import kotlinx.coroutines.flow.Flow
5856
import kotlinx.coroutines.flow.combine
5957
import kotlinx.coroutines.flow.map
@@ -187,7 +185,7 @@ interface PirRepository {
187185
override val completionTimeInMillis: Long,
188186
override val actionType: String,
189187
val profileQuery: ProfileQuery?,
190-
val extractResults: List<ScrapedData> = emptyList(),
188+
val extractResults: List<ExtractedProfile> = emptyList(),
191189
) : ScanResult(brokerName, completionTimeInMillis, actionType)
192190

193191
data class ErrorResult(
@@ -219,9 +217,7 @@ class RealPirRepository(
219217
private val optOutResultsDao: OptOutResultsDao,
220218
) : PirRepository {
221219
private val profileQueryAdapter by lazy { moshi.adapter(ProfileQuery::class.java) }
222-
private val scrapedDataAdapter by lazy { moshi.adapter(ScrapedData::class.java) }
223220
private val extractedProfileAdapter by lazy { moshi.adapter(ExtractedProfile::class.java) }
224-
private val validExtractedProfilePattern by lazy { Pattern.compile(".*\"result\"\\s*:\\s*true.*") }
225221

226222
override suspend fun getCurrentMainEtag(): String? = pirDataStore.mainConfigEtag
227223

@@ -308,9 +304,7 @@ class RealPirRepository(
308304

309305
override suspend fun getBrokersForOptOut(formOptOutOnly: Boolean): List<String> = withContext(dispatcherProvider.io()) {
310306
scanResultsDao.getAllExtractProfileResult().filter {
311-
it.extractResults.isNotEmpty() && it.extractResults.any { result ->
312-
validExtractedProfilePattern.matcher(result).find()
313-
}
307+
it.extractResults.isNotEmpty()
314308
}.map {
315309
it.brokerName
316310
}.run {
@@ -370,9 +364,9 @@ class RealPirRepository(
370364
actionType = response.actionType,
371365
completionTimeInMillis = currentTimeProvider.currentTimeMillis(),
372366
userData = profileQueryAdapter.toJson(response.meta?.userData),
373-
extractResults = response.meta?.extractResults?.map {
374-
scrapedDataAdapter.toJson(it)
375-
} ?: emptyList(),
367+
extractResults = response.response.map {
368+
extractedProfileAdapter.toJson(it)
369+
},
376370
),
377371
)
378372
}
@@ -385,7 +379,7 @@ class RealPirRepository(
385379
completionTimeInMillis = this.completionTimeInMillis,
386380
actionType = this.actionType,
387381
extractResults = this.extractResults.mapNotNull {
388-
scrapedDataAdapter.fromJson(it)
382+
extractedProfileAdapter.fromJson(it)
389383
},
390384
profileQuery = null,
391385
)
@@ -421,7 +415,7 @@ class RealPirRepository(
421415
actionType = it.actionType,
422416
profileQuery = profileQueryAdapter.fromJson(it.userData),
423417
extractResults = it.extractResults.mapNotNull { data ->
424-
scrapedDataAdapter.fromJson(data)
418+
extractedProfileAdapter.fromJson(data)
425419
},
426420
)
427421
}
@@ -520,7 +514,7 @@ class RealPirRepository(
520514
it.filter {
521515
it.isSubmitSuccess
522516
}.map {
523-
(extractedProfileAdapter.fromJson(it.extractedProfile)?.profileUrl?.identifier ?: "Unknown") to it.brokerName
517+
(extractedProfileAdapter.fromJson(it.extractedProfile)?.identifier ?: "Unknown") to it.brokerName
524518
}.distinct().toMap()
525519
}
526520
}

0 commit comments

Comments
 (0)