mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-22 20:18:36 +00:00
Fix handling of E164-only contacts in incoming block sync message.
This commit is contained in:
@@ -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.ACI
|
||||
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.SignalContactRecord
|
||||
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?>) {
|
||||
val blockedE164 = blocked
|
||||
.filter { b: SignalServiceAddress -> b.number.isPresent }
|
||||
.map { b: SignalServiceAddress -> b.number.get() }
|
||||
.toList()
|
||||
fun applyBlockedUpdate(blockedE164s: List<String>, blockedAcis: List<ACI>, blockedGroupIds: List<ByteArray?>) {
|
||||
writableDatabase.withinTransaction { db ->
|
||||
db.updateAll(TABLE_NAME)
|
||||
.values(BLOCKED to 0)
|
||||
.run()
|
||||
|
||||
val blockedUuid = blocked
|
||||
.map { b: SignalServiceAddress -> b.serviceId.toString().lowercase() }
|
||||
.toList()
|
||||
val blockValues = contentValuesOf(
|
||||
BLOCKED to 1,
|
||||
PROFILE_SHARING to 0
|
||||
)
|
||||
|
||||
val db = writableDatabase
|
||||
db.beginTransaction()
|
||||
val e164Query = SqlUtil.buildFastCollectionQuery(E164, blockedE164s)
|
||||
db.update(TABLE_NAME)
|
||||
.values(blockValues)
|
||||
.where(e164Query.where, e164Query.whereArgs)
|
||||
.run()
|
||||
|
||||
val aciQuery = SqlUtil.buildFastCollectionQuery(ACI_COLUMN, blockedAcis.map { it.toString() })
|
||||
db.update(TABLE_NAME)
|
||||
.values(blockValues)
|
||||
.where(aciQuery.where, aciQuery.whereArgs)
|
||||
.run()
|
||||
|
||||
val groupIds: List<GroupId.V1> = blockedGroupIds.mapNotNull { raw ->
|
||||
try {
|
||||
val resetBlocked = ContentValues().apply {
|
||||
put(BLOCKED, 0)
|
||||
}
|
||||
db.update(TABLE_NAME, resetBlocked, null, null)
|
||||
|
||||
val setBlocked = ContentValues().apply {
|
||||
put(BLOCKED, 1)
|
||||
put(PROFILE_SHARING, 0)
|
||||
}
|
||||
|
||||
for (e164 in blockedE164) {
|
||||
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 {
|
||||
groupIdStrings.add(GroupId.v1(raw))
|
||||
GroupId.v1(raw)
|
||||
} catch (e: BadGroupIdException) {
|
||||
Log.w(TAG, "[applyBlockedUpdate] Bad GV1 ID!")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
for (groupId in groupIdStrings) {
|
||||
db.update(TABLE_NAME, setBlocked, "$GROUP_ID = ?", arrayOf(groupId.toString()))
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful()
|
||||
} finally {
|
||||
db.endTransaction()
|
||||
val groupIdQuery = SqlUtil.buildFastCollectionQuery(GROUP_ID, groupIds.map { it.toString() })
|
||||
db.update(TABLE_NAME)
|
||||
.values(blockValues)
|
||||
.where(groupIdQuery.where, groupIdQuery.whereArgs)
|
||||
.run()
|
||||
}
|
||||
|
||||
AppDependencies.recipientCache.clear()
|
||||
|
||||
@@ -153,7 +153,7 @@ object SyncMessageProcessor {
|
||||
syncMessage.verified != null -> handleSynchronizeVerifiedMessage(context, syncMessage.verified!!)
|
||||
syncMessage.stickerPackOperation.isNotEmpty() -> handleSynchronizeStickerPackOperation(syncMessage.stickerPackOperation, 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.messageRequestResponse != null -> handleSynchronizeMessageRequestResponse(syncMessage.messageRequestResponse!!, envelope.timestamp!!)
|
||||
syncMessage.outgoingPayment != null -> handleSynchronizeOutgoingPayment(syncMessage.outgoingPayment!!, envelope.timestamp!!)
|
||||
@@ -1095,11 +1095,13 @@ object SyncMessageProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleSynchronizeBlockedListMessage(blockMessage: Blocked) {
|
||||
val addresses: List<SignalServiceAddress> = blockMessage.acis.mapNotNull { SignalServiceAddress.fromRaw(it, null).orNull() }
|
||||
val groupIds: List<ByteArray> = blockMessage.groupIds.map { it.toByteArray() }
|
||||
private fun handleSynchronizeBlockedListMessage(blockMessage: Blocked, envelopeTimestamp: Long) {
|
||||
val blockedAcis = blockMessage.acis.mapNotNull { ACI.parseOrNull(it) }
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user