mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 18:00:02 +01:00
Save PNI's from CDSv2 for all users.
This commit is contained in:
committed by
Alex Hart
parent
13853c708e
commit
327cd93e3c
@@ -2231,82 +2231,13 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
getAndPossiblyMerge(null, record.pni, record.e164)
|
||||
}
|
||||
|
||||
fun bulkUpdatedRegisteredStatus(registered: Map<RecipientId, ServiceId?>, unregistered: Collection<RecipientId>) {
|
||||
writableDatabase.withinTransaction {
|
||||
val registeredWithServiceId: Set<RecipientId> = getRegisteredWithServiceIds()
|
||||
val needsMarkRegistered: Map<RecipientId, ServiceId?> = registered - registeredWithServiceId
|
||||
|
||||
for ((recipientId, serviceId) in needsMarkRegistered) {
|
||||
val values = ContentValues().apply {
|
||||
put(REGISTERED, RegisteredState.REGISTERED.id)
|
||||
put(UNREGISTERED_TIMESTAMP, 0)
|
||||
if (serviceId != null) {
|
||||
put(ACI_COLUMN, serviceId.toString().lowercase())
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (update(recipientId, values)) {
|
||||
setStorageIdIfNotSet(recipientId)
|
||||
ApplicationDependencies.getDatabaseObserver().notifyRecipientChanged(recipientId)
|
||||
}
|
||||
} catch (e: SQLiteConstraintException) {
|
||||
Log.w(TAG, "[bulkUpdateRegisteredStatus] Hit a conflict when trying to update $recipientId. Possibly merging.")
|
||||
val e164 = getRecord(recipientId).e164
|
||||
val newId = getAndPossiblyMerge(serviceId, e164)
|
||||
Log.w(TAG, "[bulkUpdateRegisteredStatus] Merged into $newId")
|
||||
}
|
||||
}
|
||||
|
||||
for (id in unregistered) {
|
||||
markUnregistered(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles inserts the (e164, UUID) pairs, which could result in merges. Does not mark users as
|
||||
* registered.
|
||||
*
|
||||
* @return A mapping of (RecipientId, UUID)
|
||||
*/
|
||||
fun bulkProcessCdsResult(mapping: Map<String, ACI?>): Map<RecipientId, ACI?> {
|
||||
val db = writableDatabase
|
||||
val aciMap: MutableMap<RecipientId, ACI?> = mutableMapOf()
|
||||
|
||||
db.beginTransaction()
|
||||
try {
|
||||
for ((e164, aci) in mapping) {
|
||||
var aciEntry = if (aci != null) getByAci(aci) else Optional.empty()
|
||||
|
||||
if (aciEntry.isPresent) {
|
||||
val idChanged = setPhoneNumber(aciEntry.get(), e164)
|
||||
if (idChanged) {
|
||||
aciEntry = getByAci(aci!!)
|
||||
}
|
||||
}
|
||||
|
||||
val id = if (aciEntry.isPresent) aciEntry.get() else getOrInsertFromE164(e164)
|
||||
aciMap[id] = aci
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful()
|
||||
} finally {
|
||||
db.endTransaction()
|
||||
}
|
||||
|
||||
return aciMap
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes CDSv2 results, merging recipients as necessary. Does not mark users as
|
||||
* registered.
|
||||
*
|
||||
* Important: This is under active development and is not suitable for actual use.
|
||||
*
|
||||
* @return A set of [RecipientId]s that were updated/inserted.
|
||||
*/
|
||||
fun bulkProcessCdsV2Result(mapping: Map<String, CdsV2Result>): Set<RecipientId> {
|
||||
fun bulkProcessCdsResult(mapping: Map<String, CdsV2Result>): Set<RecipientId> {
|
||||
val ids: MutableSet<RecipientId> = mutableSetOf()
|
||||
val db = writableDatabase
|
||||
|
||||
@@ -2324,8 +2255,11 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
return ids
|
||||
}
|
||||
|
||||
fun bulkUpdatedRegisteredStatusV2(registered: Set<RecipientId>, unregistered: Collection<RecipientId>) {
|
||||
fun bulkUpdatedRegisteredStatus(registered: Set<RecipientId>, unregistered: Collection<RecipientId>) {
|
||||
writableDatabase.withinTransaction {
|
||||
val existingRegistered: Set<RecipientId> = getRegistered()
|
||||
val needsMarkRegistered: Set<RecipientId> = registered - existingRegistered
|
||||
|
||||
val registeredValues = contentValuesOf(
|
||||
REGISTERED to RegisteredState.REGISTERED.id,
|
||||
UNREGISTERED_TIMESTAMP to 0
|
||||
@@ -2333,7 +2267,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
|
||||
val newlyRegistered: MutableSet<RecipientId> = mutableSetOf()
|
||||
|
||||
for (id in registered) {
|
||||
for (id in needsMarkRegistered) {
|
||||
if (update(id, registeredValues)) {
|
||||
newlyRegistered += id
|
||||
setStorageIdIfNotSet(id)
|
||||
@@ -3034,26 +2968,16 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
return operations
|
||||
}
|
||||
|
||||
fun getRegistered(): List<RecipientId> {
|
||||
val results: MutableList<RecipientId> = LinkedList()
|
||||
fun getRegistered(): Set<RecipientId> {
|
||||
val results: MutableSet<RecipientId> = mutableSetOf()
|
||||
|
||||
readableDatabase.query(TABLE_NAME, ID_PROJECTION, "$REGISTERED = ? and $HIDDEN = ?", arrayOf("1", "${Recipient.HiddenState.NOT_HIDDEN.serialize()}"), null, null, null).use { cursor ->
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
results.add(RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ID))))
|
||||
results += RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ID)))
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
fun getRegisteredWithServiceIds(): Set<RecipientId> {
|
||||
return readableDatabase
|
||||
.select(ID)
|
||||
.from(TABLE_NAME)
|
||||
.where("$REGISTERED = ? and $HIDDEN = ? AND $ACI_COLUMN NOT NULL", 1, Recipient.HiddenState.NOT_HIDDEN.serialize())
|
||||
.run()
|
||||
.readToSet { cursor ->
|
||||
RecipientId.from(cursor.requireLong(ID))
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
fun getSystemContacts(): List<RecipientId> {
|
||||
@@ -3082,7 +3006,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
return readableDatabase
|
||||
.select(E164)
|
||||
.from(TABLE_NAME)
|
||||
.where("$REGISTERED = ? and $HIDDEN = ? AND $E164 NOT NULL", 1, Recipient.HiddenState.NOT_HIDDEN.serialize())
|
||||
.where("$REGISTERED = ? and $HIDDEN = ? AND $E164 NOT NULL", RegisteredState.REGISTERED.id, Recipient.HiddenState.NOT_HIDDEN.serialize())
|
||||
.run()
|
||||
.readToSet { cursor ->
|
||||
cursor.requireNonNullString(E164)
|
||||
|
||||
Reference in New Issue
Block a user