File tree Expand file tree Collapse file tree 3 files changed +40
-9
lines changed
pir/pir-impl/src/main/java/com/duckduckgo/pir/impl
dashboard/messaging/handlers Expand file tree Collapse file tree 3 files changed +40
-9
lines changed Original file line number Diff line number Diff line change @@ -55,20 +55,37 @@ class PirWebGetDataBrokersMessageHandler @Inject constructor(
55
55
logcat { " PIR-WEB: PirWebGetDataBrokersMessageHandler: process $jsMessage " }
56
56
57
57
appCoroutineScope.launch(dispatcherProvider.io()) {
58
- val brokers = repository.getAllActiveBrokerObjects()
59
-
60
58
jsMessaging.sendResponse(
61
59
jsMessage,
62
60
response = PirWebMessageResponse .GetDataBrokersResponse (
63
- dataBrokers = brokers.map {
64
- PirWebMessageResponse .GetDataBrokersResponse .DataBroker (
65
- url = it.url,
66
- name = it.name,
67
- parentURL = it.parent,
68
- )
69
- },
61
+ dataBrokers = getDataBrokers(),
70
62
),
71
63
)
72
64
}
73
65
}
66
+
67
+ private suspend fun getDataBrokers (): List <PirWebMessageResponse .GetDataBrokersResponse .DataBroker > {
68
+ val activeBrokers = repository.getAllActiveBrokerObjects().associateBy { it.name }
69
+ val mirrorSites = repository.getAllMirrorSites().filter { it.removedAt == 0L }
70
+ val brokerOptOutUrls = repository.getAllBrokerOptOutUrls()
71
+
72
+ val mappedBrokers = activeBrokers.values.map {
73
+ PirWebMessageResponse .GetDataBrokersResponse .DataBroker (
74
+ url = it.url,
75
+ name = it.name,
76
+ parentURL = it.parent,
77
+ optOutUrl = brokerOptOutUrls[it.name],
78
+ )
79
+ }
80
+ val mappedMirrorSites = mirrorSites.map {
81
+ PirWebMessageResponse .GetDataBrokersResponse .DataBroker (
82
+ url = it.url,
83
+ name = it.name,
84
+ parentURL = activeBrokers[it.parentSite]?.url,
85
+ optOutUrl = brokerOptOutUrls[it.parentSite],
86
+ )
87
+ }
88
+
89
+ return (mappedBrokers + mappedMirrorSites).distinct()
90
+ }
74
91
}
Original file line number Diff line number Diff line change @@ -66,6 +66,11 @@ interface PirRepository {
66
66
67
67
suspend fun getAllBrokersForScan (): List <String >
68
68
69
+ /* *
70
+ * Returns a map of broker names to their opt-out URLs.
71
+ */
72
+ suspend fun getAllBrokerOptOutUrls (): Map <String , String ?>
73
+
69
74
suspend fun getEtagForFilename (fileName : String ): String?
70
75
71
76
suspend fun updateBrokerData (
@@ -234,6 +239,12 @@ internal class RealPirRepository(
234
239
return @withContext brokerDao.getAllBrokersNamesWithScanSteps()
235
240
}
236
241
242
+ override suspend fun getAllBrokerOptOutUrls (): Map <String , String ?> =
243
+ withContext(dispatcherProvider.io()) {
244
+ val brokerOptOuts = brokerDao.getAllBrokerOptOuts()
245
+ return @withContext brokerOptOuts.associate { it.brokerName to it.optOutUrl }
246
+ }
247
+
237
248
override suspend fun getEtagForFilename (fileName : String ): String =
238
249
withContext(dispatcherProvider.io()) {
239
250
return @withContext brokerJsonDao.getEtag(fileName)
Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ interface BrokerDao {
48
48
@Query(" DELETE from pir_broker_details where name = :brokerName" )
49
49
fun deleteBroker (brokerName : String )
50
50
51
+ @Query(" SELECT * FROM pir_broker_opt_out" )
52
+ fun getAllBrokerOptOuts (): List <BrokerOptOut >
53
+
51
54
@Query(" SELECT * from pir_broker_mirror_sites" )
52
55
fun getAllMirrorSites (): List <MirrorSiteEntity >
53
56
You can’t perform that action at this time.
0 commit comments