Fix handling of E164-only contacts in incoming block sync message.

This commit is contained in:
Greyson Parrelli
2025-02-06 10:48:35 -05:00
parent 5973e96d76
commit 254b0dacc3
2 changed files with 34 additions and 43 deletions

View File

@@ -106,7 +106,6 @@ import org.whispersystems.signalservice.api.profiles.SignalServiceProfile
import org.whispersystems.signalservice.api.push.ServiceId import org.whispersystems.signalservice.api.push.ServiceId
import org.whispersystems.signalservice.api.push.ServiceId.ACI import org.whispersystems.signalservice.api.push.ServiceId.ACI
import org.whispersystems.signalservice.api.push.ServiceId.PNI import org.whispersystems.signalservice.api.push.ServiceId.PNI
import org.whispersystems.signalservice.api.push.SignalServiceAddress
import org.whispersystems.signalservice.api.storage.SignalAccountRecord import org.whispersystems.signalservice.api.storage.SignalAccountRecord
import org.whispersystems.signalservice.api.storage.SignalContactRecord import org.whispersystems.signalservice.api.storage.SignalContactRecord
import org.whispersystems.signalservice.api.storage.SignalGroupV1Record import org.whispersystems.signalservice.api.storage.SignalGroupV1Record
@@ -3651,53 +3650,43 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
} }
} }
fun applyBlockedUpdate(blocked: List<SignalServiceAddress>, groupIds: List<ByteArray?>) { fun applyBlockedUpdate(blockedE164s: List<String>, blockedAcis: List<ACI>, blockedGroupIds: List<ByteArray?>) {
val blockedE164 = blocked writableDatabase.withinTransaction { db ->
.filter { b: SignalServiceAddress -> b.number.isPresent } db.updateAll(TABLE_NAME)
.map { b: SignalServiceAddress -> b.number.get() } .values(BLOCKED to 0)
.toList() .run()
val blockedUuid = blocked val blockValues = contentValuesOf(
.map { b: SignalServiceAddress -> b.serviceId.toString().lowercase() } BLOCKED to 1,
.toList() PROFILE_SHARING to 0
)
val db = writableDatabase val e164Query = SqlUtil.buildFastCollectionQuery(E164, blockedE164s)
db.beginTransaction() db.update(TABLE_NAME)
try { .values(blockValues)
val resetBlocked = ContentValues().apply { .where(e164Query.where, e164Query.whereArgs)
put(BLOCKED, 0) .run()
}
db.update(TABLE_NAME, resetBlocked, null, null)
val setBlocked = ContentValues().apply { val aciQuery = SqlUtil.buildFastCollectionQuery(ACI_COLUMN, blockedAcis.map { it.toString() })
put(BLOCKED, 1) db.update(TABLE_NAME)
put(PROFILE_SHARING, 0) .values(blockValues)
} .where(aciQuery.where, aciQuery.whereArgs)
.run()
for (e164 in blockedE164) { val groupIds: List<GroupId.V1> = blockedGroupIds.mapNotNull { raw ->
db.update(TABLE_NAME, setBlocked, "$E164 = ?", arrayOf(e164))
}
for (uuid in blockedUuid) {
db.update(TABLE_NAME, setBlocked, "$ACI_COLUMN = ?", arrayOf(uuid))
}
val groupIdStrings: MutableList<V1> = ArrayList(groupIds.size)
for (raw in groupIds) {
try { try {
groupIdStrings.add(GroupId.v1(raw)) GroupId.v1(raw)
} catch (e: BadGroupIdException) { } catch (e: BadGroupIdException) {
Log.w(TAG, "[applyBlockedUpdate] Bad GV1 ID!") Log.w(TAG, "[applyBlockedUpdate] Bad GV1 ID!")
null
} }
} }
for (groupId in groupIdStrings) { val groupIdQuery = SqlUtil.buildFastCollectionQuery(GROUP_ID, groupIds.map { it.toString() })
db.update(TABLE_NAME, setBlocked, "$GROUP_ID = ?", arrayOf(groupId.toString())) db.update(TABLE_NAME)
} .values(blockValues)
.where(groupIdQuery.where, groupIdQuery.whereArgs)
db.setTransactionSuccessful() .run()
} finally {
db.endTransaction()
} }
AppDependencies.recipientCache.clear() AppDependencies.recipientCache.clear()

View File

@@ -153,7 +153,7 @@ object SyncMessageProcessor {
syncMessage.verified != null -> handleSynchronizeVerifiedMessage(context, syncMessage.verified!!) syncMessage.verified != null -> handleSynchronizeVerifiedMessage(context, syncMessage.verified!!)
syncMessage.stickerPackOperation.isNotEmpty() -> handleSynchronizeStickerPackOperation(syncMessage.stickerPackOperation, envelope.timestamp!!) syncMessage.stickerPackOperation.isNotEmpty() -> handleSynchronizeStickerPackOperation(syncMessage.stickerPackOperation, envelope.timestamp!!)
syncMessage.configuration != null -> handleSynchronizeConfigurationMessage(context, syncMessage.configuration!!, envelope.timestamp!!) syncMessage.configuration != null -> handleSynchronizeConfigurationMessage(context, syncMessage.configuration!!, envelope.timestamp!!)
syncMessage.blocked != null -> handleSynchronizeBlockedListMessage(syncMessage.blocked!!) syncMessage.blocked != null -> handleSynchronizeBlockedListMessage(syncMessage.blocked!!, envelope.timestamp!!)
syncMessage.fetchLatest?.type != null -> handleSynchronizeFetchMessage(syncMessage.fetchLatest!!.type!!, envelope.timestamp!!) syncMessage.fetchLatest?.type != null -> handleSynchronizeFetchMessage(syncMessage.fetchLatest!!.type!!, envelope.timestamp!!)
syncMessage.messageRequestResponse != null -> handleSynchronizeMessageRequestResponse(syncMessage.messageRequestResponse!!, envelope.timestamp!!) syncMessage.messageRequestResponse != null -> handleSynchronizeMessageRequestResponse(syncMessage.messageRequestResponse!!, envelope.timestamp!!)
syncMessage.outgoingPayment != null -> handleSynchronizeOutgoingPayment(syncMessage.outgoingPayment!!, envelope.timestamp!!) syncMessage.outgoingPayment != null -> handleSynchronizeOutgoingPayment(syncMessage.outgoingPayment!!, envelope.timestamp!!)
@@ -1095,11 +1095,13 @@ object SyncMessageProcessor {
} }
} }
private fun handleSynchronizeBlockedListMessage(blockMessage: Blocked) { private fun handleSynchronizeBlockedListMessage(blockMessage: Blocked, envelopeTimestamp: Long) {
val addresses: List<SignalServiceAddress> = blockMessage.acis.mapNotNull { SignalServiceAddress.fromRaw(it, null).orNull() } val blockedAcis = blockMessage.acis.mapNotNull { ACI.parseOrNull(it) }
val groupIds: List<ByteArray> = blockMessage.groupIds.map { it.toByteArray() } val blockedE164s = blockMessage.numbers
val blockedGroupIds = blockMessage.groupIds.map { it.toByteArray() }
log(envelopeTimestamp, "Synchronize block message. Counts: (ACI: ${blockedAcis.size}, E164: ${blockedE164s.size}, Group: ${blockedGroupIds.size})")
SignalDatabase.recipients.applyBlockedUpdate(addresses, groupIds) SignalDatabase.recipients.applyBlockedUpdate(blockedE164s, blockedAcis, blockedGroupIds)
} }
private fun handleSynchronizeFetchMessage(fetchType: FetchLatest.Type, envelopeTimestamp: Long) { private fun handleSynchronizeFetchMessage(fetchType: FetchLatest.Type, envelopeTimestamp: Long) {