Ensure ACI/PNI are associated after processing a PNI promotion message.

This commit is contained in:
Greyson Parrelli 2023-11-29 10:02:47 -05:00 committed by Cody Henthorne
parent 15f1201a76
commit 4a0abbbee7
2 changed files with 13 additions and 3 deletions

View file

@ -7,7 +7,6 @@ import android.text.TextUtils
import androidx.annotation.WorkerThread
import androidx.core.content.contentValuesOf
import org.intellij.lang.annotations.Language
import org.signal.core.util.SetUtil
import org.signal.core.util.SqlUtil
import org.signal.core.util.SqlUtil.appendArg
import org.signal.core.util.SqlUtil.buildArgs
@ -36,14 +35,12 @@ import org.signal.storageservice.protos.groups.local.DecryptedGroup
import org.thoughtcrime.securesms.contacts.paged.ContactSearchSortOrder
import org.thoughtcrime.securesms.contacts.paged.collections.ContactSearchIterator
import org.thoughtcrime.securesms.crypto.SenderKeyUtil
import org.thoughtcrime.securesms.database.SignalDatabase.Companion.messages
import org.thoughtcrime.securesms.database.SignalDatabase.Companion.recipients
import org.thoughtcrime.securesms.database.model.GroupRecord
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.groups.BadGroupIdException
import org.thoughtcrime.securesms.groups.GroupId
import org.thoughtcrime.securesms.groups.GroupId.Push
import org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange
import org.thoughtcrime.securesms.groups.v2.processing.GroupsV2StateProcessor
import org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob
import org.thoughtcrime.securesms.keyvalue.SignalStore
@ -60,6 +57,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPoin
import org.whispersystems.signalservice.api.push.DistributionId
import org.whispersystems.signalservice.api.push.ServiceId
import org.whispersystems.signalservice.api.push.ServiceId.ACI
import org.whispersystems.signalservice.api.push.ServiceId.PNI
import java.io.Closeable
import java.security.SecureRandom
import java.util.Optional
@ -867,6 +865,14 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
Log.i(TAG, removed.size.toString() + " members were removed from group " + groupId + ". Rotating the DistributionId " + distributionId)
SenderKeyUtil.rotateOurKey(distributionId)
}
change.promotePendingPniAciMembers.forEach { member ->
recipients.getAndPossiblyMergePnpVerified(
aci = ACI.parseOrNull(member.aciBytes),
pni = PNI.parseOrNull(member.pniBytes),
e164 = null
)
}
}
writableDatabase.withinTransaction { database ->

View file

@ -197,6 +197,10 @@ sealed class ServiceId(val libSignalServiceId: LibSignalServiceId) {
}
}
/** Parses a [ByteString] as a PNI, regardless if the `PNI:` prefix is present or not. Only use this if you are certain that what you're reading is a PNI. */
@JvmStatic
fun parseOrNull(bytes: ByteString): PNI? = parseOrNull(bytes.toByteArray())
/** Parses a string as a PNI, regardless if the `PNI:` prefix is present or not. Only use this if you are certain that what you're reading is a PNI. */
@JvmStatic
@Throws(IllegalArgumentException::class)