mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Remove concept of 'highTrust' that is no longer necessary.
This commit is contained in:
committed by
Alex Hart
parent
d17896ea09
commit
04cf8676cc
@@ -231,7 +231,7 @@ public class GroupDatabase extends Database {
|
||||
|
||||
databaseHelper.getSignalWritableDatabase().update(TABLE_NAME, values, GROUP_ID + " = ?", SqlUtil.buildArgs(id));
|
||||
|
||||
Recipient.live(Recipient.externalGroupExact(context, id).getId()).refresh();
|
||||
Recipient.live(Recipient.externalGroupExact(id).getId()).refresh();
|
||||
}
|
||||
|
||||
Optional<GroupRecord> getGroup(Cursor cursor) {
|
||||
@@ -915,7 +915,7 @@ public class GroupDatabase extends Database {
|
||||
if (UuidUtil.UNKNOWN_UUID.equals(uuid)) {
|
||||
Log.w(TAG, "Seen unknown UUID in members list");
|
||||
} else {
|
||||
RecipientId id = RecipientId.from(ServiceId.from(uuid), null);
|
||||
RecipientId id = RecipientId.from(ServiceId.from(uuid));
|
||||
Optional<RecipientId> remapped = RemappedRecords.getInstance().getRecipient(id);
|
||||
|
||||
if (remapped.isPresent()) {
|
||||
@@ -1373,7 +1373,7 @@ public class GroupDatabase extends Database {
|
||||
if (UuidUtil.UNKNOWN_UUID.equals(uuid)) {
|
||||
unknownMembers++;
|
||||
} else if (includeSelf || !selfUuid.equals(uuid)) {
|
||||
recipients.add(RecipientId.from(ServiceId.from(uuid), null));
|
||||
recipients.add(RecipientId.from(ServiceId.from(uuid)));
|
||||
}
|
||||
}
|
||||
if (memberSet.includePending) {
|
||||
@@ -1381,7 +1381,7 @@ public class GroupDatabase extends Database {
|
||||
if (UuidUtil.UNKNOWN_UUID.equals(uuid)) {
|
||||
unknownPending++;
|
||||
} else if (includeSelf || !selfUuid.equals(uuid)) {
|
||||
recipients.add(RecipientId.from(ServiceId.from(uuid), null));
|
||||
recipients.add(RecipientId.from(ServiceId.from(uuid)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ public class IdentityDatabase extends Database {
|
||||
boolean firstUse = CursorUtil.requireBoolean(cursor, FIRST_USE);
|
||||
IdentityKey identity = new IdentityKey(Base64.decode(serializedIdentity), 0);
|
||||
|
||||
return new IdentityRecord(RecipientId.fromExternalPush(addressName), identity, VerifiedStatus.forState(verifiedStatus), firstUse, timestamp, nonblockingApproval);
|
||||
return new IdentityRecord(RecipientId.fromSidOrE164(addressName), identity, VerifiedStatus.forState(verifiedStatus), firstUse, timestamp, nonblockingApproval);
|
||||
}
|
||||
|
||||
private void saveIdentityInternal(@NonNull String addressName,
|
||||
|
||||
@@ -121,7 +121,7 @@ public final class MentionUtil {
|
||||
return Stream.of(BodyRangeList.parseFrom(data).getRangesList())
|
||||
.filter(bodyRange -> bodyRange.getAssociatedValueCase() == BodyRangeList.BodyRange.AssociatedValueCase.MENTIONUUID)
|
||||
.map(mention -> {
|
||||
RecipientId id = Recipient.externalPush(ServiceId.parseOrThrow(mention.getMentionUuid()), null, false).getId();
|
||||
RecipientId id = Recipient.externalPush(ServiceId.parseOrThrow(mention.getMentionUuid())).getId();
|
||||
return new Mention(id, mention.getStart(), mention.getLength());
|
||||
})
|
||||
.toList();
|
||||
|
||||
@@ -2162,7 +2162,7 @@ public class MmsDatabase extends MessageDatabase {
|
||||
MessageGroupContext.GroupV2Properties groupV2Properties = outgoingGroupUpdateMessage.requireGroupV2Properties();
|
||||
members.addAll(Stream.of(groupV2Properties.getAllActivePendingAndRemovedMembers())
|
||||
.distinct()
|
||||
.map(uuid -> RecipientId.from(ServiceId.from(uuid), null))
|
||||
.map(uuid -> RecipientId.from(ServiceId.from(uuid)))
|
||||
.toList());
|
||||
members.remove(Recipient.self().getId());
|
||||
} else {
|
||||
|
||||
@@ -419,11 +419,12 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
return getByColumn(USERNAME, username)
|
||||
}
|
||||
|
||||
fun getAndPossiblyMerge(serviceId: ServiceId?, e164: String?, highTrust: Boolean): RecipientId {
|
||||
return getAndPossiblyMerge(serviceId, e164, highTrust, false)
|
||||
fun getAndPossiblyMerge(serviceId: ServiceId?, e164: String?): RecipientId {
|
||||
return getAndPossiblyMerge(serviceId, e164, changeSelf = false)
|
||||
}
|
||||
|
||||
fun getAndPossiblyMerge(serviceId: ServiceId?, e164: String?, highTrust: Boolean, changeSelf: Boolean): RecipientId {
|
||||
@VisibleForTesting
|
||||
fun getAndPossiblyMerge(serviceId: ServiceId?, e164: String?, changeSelf: Boolean): RecipientId {
|
||||
require(!(serviceId == null && e164 == null)) { "Must provide an ACI or E164!" }
|
||||
|
||||
val db = writableDatabase
|
||||
@@ -435,7 +436,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
|
||||
db.beginTransaction()
|
||||
try {
|
||||
val fetch: RecipientFetch = fetchRecipient(serviceId, e164, highTrust, changeSelf)
|
||||
val fetch: RecipientFetch = fetchRecipient(serviceId, e164, changeSelf = changeSelf)
|
||||
|
||||
if (fetch.logBundle != null) {
|
||||
Log.w(TAG, fetch.toString())
|
||||
@@ -537,7 +538,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
return serviceIdToProfileKey
|
||||
}
|
||||
|
||||
private fun fetchRecipient(serviceId: ServiceId?, e164: String?, highTrust: Boolean, changeSelf: Boolean): RecipientFetch {
|
||||
private fun fetchRecipient(serviceId: ServiceId?, e164: String?, changeSelf: Boolean): RecipientFetch {
|
||||
val byE164 = e164?.let { getByE164(it) } ?: Optional.empty()
|
||||
val byAci = serviceId?.let { getByServiceId(it) } ?: Optional.empty()
|
||||
|
||||
@@ -548,20 +549,20 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
)
|
||||
|
||||
if (byAci.isPresent && byE164.isPresent && byAci.get() == byE164.get()) {
|
||||
return RecipientFetch.Match(byAci.get(), null)
|
||||
return RecipientFetch.Match(byAci.get(), logs.label("L0"))
|
||||
}
|
||||
|
||||
if (byAci.isPresent && byE164.isAbsent()) {
|
||||
val aciRecord: RecipientRecord = getRecord(byAci.get())
|
||||
logs = logs.copy(bySid = aciRecord.toLogDetails())
|
||||
|
||||
if (highTrust && e164 != null && (changeSelf || serviceId != SignalStore.account().aci)) {
|
||||
if (e164 != null && (changeSelf || serviceId != SignalStore.account().aci)) {
|
||||
val changedNumber: RecipientId? = if (aciRecord.e164 != null && aciRecord.e164 != e164) aciRecord.id else null
|
||||
return RecipientFetch.MatchAndUpdateE164(byAci.get(), e164, changedNumber, logs.label("L1"))
|
||||
} else if (e164 == null) {
|
||||
return RecipientFetch.Match(byAci.get(), null)
|
||||
} else {
|
||||
return RecipientFetch.Match(byAci.get(), logs.label("L2"))
|
||||
} else {
|
||||
return RecipientFetch.Match(byAci.get(), logs.label("L3"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,25 +570,19 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
val e164Record: RecipientRecord = getRecord(byE164.get())
|
||||
logs = logs.copy(byE164 = e164Record.toLogDetails())
|
||||
|
||||
if (highTrust && serviceId != null && e164Record.serviceId == null) {
|
||||
return RecipientFetch.MatchAndUpdateAci(byE164.get(), serviceId, logs.label("L3"))
|
||||
} else if (highTrust && serviceId != null && e164Record.serviceId != SignalStore.account().aci) {
|
||||
return RecipientFetch.InsertAndReassignE164(serviceId, e164, byE164.get(), logs.label("L4"))
|
||||
if (serviceId != null && e164Record.serviceId == null) {
|
||||
return RecipientFetch.MatchAndUpdateAci(byE164.get(), serviceId, logs.label("L4"))
|
||||
} else if (serviceId != null && e164Record.serviceId != SignalStore.account().aci) {
|
||||
return RecipientFetch.InsertAndReassignE164(serviceId, e164, byE164.get(), logs.label("L5"))
|
||||
} else if (serviceId != null) {
|
||||
return RecipientFetch.Insert(serviceId, null, logs.label("L5"))
|
||||
return RecipientFetch.Insert(serviceId, null, logs.label("L6"))
|
||||
} else {
|
||||
return RecipientFetch.Match(byE164.get(), null)
|
||||
return RecipientFetch.Match(byE164.get(), logs.label("L7"))
|
||||
}
|
||||
}
|
||||
|
||||
if (byAci.isAbsent() && byE164.isAbsent()) {
|
||||
if (highTrust) {
|
||||
return RecipientFetch.Insert(serviceId, e164, logs.label("L6"))
|
||||
} else if (serviceId != null) {
|
||||
return RecipientFetch.Insert(serviceId, null, logs.label("L7"))
|
||||
} else {
|
||||
return RecipientFetch.Insert(null, e164, logs.label("L8"))
|
||||
}
|
||||
return RecipientFetch.Insert(serviceId, e164, logs.label("L8"))
|
||||
}
|
||||
|
||||
require(byAci.isPresent && byE164.isPresent && byAci.get() != byE164.get()) { "Assumed conditions at this point." }
|
||||
@@ -598,18 +593,14 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
logs = logs.copy(bySid = aciRecord.toLogDetails(), byE164 = e164Record.toLogDetails())
|
||||
|
||||
if (e164Record.serviceId == null) {
|
||||
if (highTrust) {
|
||||
val changedNumber: RecipientId? = if (aciRecord.e164 != null) aciRecord.id else null
|
||||
return RecipientFetch.MatchAndMerge(sidId = byAci.get(), e164Id = byE164.get(), changedNumber = changedNumber, logs.label("L9"))
|
||||
} else {
|
||||
return RecipientFetch.Match(byAci.get(), logs.label("L10"))
|
||||
}
|
||||
val changedNumber: RecipientId? = if (aciRecord.e164 != null) aciRecord.id else null
|
||||
return RecipientFetch.MatchAndMerge(sidId = byAci.get(), e164Id = byE164.get(), changedNumber = changedNumber, logs.label("L9"))
|
||||
} else {
|
||||
if (highTrust && e164Record.serviceId != SignalStore.account().aci) {
|
||||
if (e164Record.serviceId != SignalStore.account().aci) {
|
||||
val changedNumber: RecipientId? = if (aciRecord.e164 != null) aciRecord.id else null
|
||||
return RecipientFetch.MatchAndReassignE164(id = byAci.get(), e164Id = byE164.get(), e164 = e164!!, changedNumber = changedNumber, logs.label("L11"))
|
||||
return RecipientFetch.MatchAndReassignE164(id = byAci.get(), e164Id = byE164.get(), e164 = e164!!, changedNumber = changedNumber, logs.label("L10"))
|
||||
} else {
|
||||
return RecipientFetch.Match(byAci.get(), logs.label("L12"))
|
||||
return RecipientFetch.Match(byAci.get(), logs.label("L11"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -868,7 +859,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
val recipientId: RecipientId
|
||||
if (id < 0) {
|
||||
Log.w(TAG, "[applyStorageSyncContactInsert] Failed to insert. Possibly merging.")
|
||||
recipientId = getAndPossiblyMerge(if (insert.address.hasValidServiceId()) insert.address.serviceId else null, insert.address.number.orElse(null), true)
|
||||
recipientId = getAndPossiblyMerge(if (insert.address.hasValidServiceId()) insert.address.serviceId else null, insert.address.number.orElse(null))
|
||||
db.update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(recipientId))
|
||||
} else {
|
||||
recipientId = RecipientId.from(id)
|
||||
@@ -905,7 +896,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
var recipientId = getByColumn(STORAGE_SERVICE_ID, Base64.encodeBytes(update.old.id.raw)).get()
|
||||
|
||||
Log.w(TAG, "[applyStorageSyncContactUpdate] Found user $recipientId. Possibly merging.")
|
||||
recipientId = getAndPossiblyMerge(if (update.new.address.hasValidServiceId()) update.new.address.serviceId else null, update.new.address.number.orElse(null), true)
|
||||
recipientId = getAndPossiblyMerge(if (update.new.address.hasValidServiceId()) update.new.address.serviceId else null, update.new.address.number.orElse(null))
|
||||
|
||||
Log.w(TAG, "[applyStorageSyncContactUpdate] Merged into $recipientId")
|
||||
db.update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(recipientId))
|
||||
@@ -960,7 +951,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
throw AssertionError("Had an update, but it didn't match any rows!")
|
||||
}
|
||||
|
||||
val recipient = Recipient.externalGroupExact(context, GroupId.v1orThrow(update.old.groupId))
|
||||
val recipient = Recipient.externalGroupExact(GroupId.v1orThrow(update.old.groupId))
|
||||
threads.applyStorageSyncUpdate(recipient.id, update.new)
|
||||
recipient.live().refresh()
|
||||
}
|
||||
@@ -971,7 +962,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
val values = getValuesForStorageGroupV2(insert, true)
|
||||
|
||||
writableDatabase.insertOrThrow(TABLE_NAME, null, values)
|
||||
val recipient = Recipient.externalGroupExact(context, groupId)
|
||||
val recipient = Recipient.externalGroupExact(groupId)
|
||||
|
||||
Log.i(TAG, "Creating restore placeholder for $groupId")
|
||||
groups.create(
|
||||
@@ -1001,7 +992,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
}
|
||||
|
||||
val masterKey = update.old.masterKeyOrThrow
|
||||
val recipient = Recipient.externalGroupExact(context, GroupId.v2(masterKey))
|
||||
val recipient = Recipient.externalGroupExact(GroupId.v2(masterKey))
|
||||
|
||||
updateExtras(recipient.id) {
|
||||
it.setHideStory(update.new.shouldHideStory())
|
||||
@@ -1149,7 +1140,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
}
|
||||
|
||||
for (id in groups.allGroupV2Ids) {
|
||||
val recipient = Recipient.externalGroupExact(context, id!!)
|
||||
val recipient = Recipient.externalGroupExact(id!!)
|
||||
val recipientId = recipient.id
|
||||
val existing: RecipientRecord = getRecordForSync(recipientId) ?: throw AssertionError()
|
||||
val key = existing.storageId ?: throw AssertionError()
|
||||
@@ -1909,7 +1900,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
Log.w(TAG, "[setPhoneNumber] Hit a conflict when trying to update $id. Possibly merging.")
|
||||
|
||||
val existing: RecipientRecord = getRecord(id)
|
||||
val newId = getAndPossiblyMerge(existing.serviceId, e164, true)
|
||||
val newId = getAndPossiblyMerge(existing.serviceId, e164)
|
||||
Log.w(TAG, "[setPhoneNumber] Resulting id: $newId")
|
||||
|
||||
db.setTransactionSuccessful()
|
||||
@@ -1961,7 +1952,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
db.beginTransaction()
|
||||
try {
|
||||
val id = Recipient.self().id
|
||||
val newId = getAndPossiblyMerge(SignalStore.account().requireAci(), e164, highTrust = true, changeSelf = true)
|
||||
val newId = getAndPossiblyMerge(SignalStore.account().requireAci(), e164, changeSelf = true)
|
||||
|
||||
if (id == newId) {
|
||||
Log.i(TAG, "[updateSelfPhone] Phone updated for self")
|
||||
@@ -2044,7 +2035,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
Log.w(TAG, "[markRegistered] Hit a conflict when trying to update $id. Possibly merging.")
|
||||
|
||||
val existing = getRecord(id)
|
||||
val newId = getAndPossiblyMerge(serviceId, existing.e164, true)
|
||||
val newId = getAndPossiblyMerge(serviceId, existing.e164)
|
||||
Log.w(TAG, "[markRegistered] Merged into $newId")
|
||||
|
||||
db.setTransactionSuccessful()
|
||||
@@ -2099,7 +2090,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
} 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(aci, e164, true)
|
||||
val newId = getAndPossiblyMerge(aci, e164)
|
||||
Log.w(TAG, "[bulkUpdateRegisteredStatus] Merged into $newId")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1254,14 +1254,14 @@ public class ThreadDatabase extends Database {
|
||||
pinnedRecipient = Recipient.externalPush(pinned.getContact().get());
|
||||
} else if (pinned.getGroupV1Id().isPresent()) {
|
||||
try {
|
||||
pinnedRecipient = Recipient.externalGroupExact(context, GroupId.v1(pinned.getGroupV1Id().get()));
|
||||
pinnedRecipient = Recipient.externalGroupExact(GroupId.v1(pinned.getGroupV1Id().get()));
|
||||
} catch (BadGroupIdException e) {
|
||||
Log.w(TAG, "Failed to parse pinned groupV1 ID!", e);
|
||||
pinnedRecipient = null;
|
||||
}
|
||||
} else if (pinned.getGroupV2MasterKey().isPresent()) {
|
||||
try {
|
||||
pinnedRecipient = Recipient.externalGroupExact(context, GroupId.v2(new GroupMasterKey(pinned.getGroupV2MasterKey().get())));
|
||||
pinnedRecipient = Recipient.externalGroupExact(GroupId.v2(new GroupMasterKey(pinned.getGroupV2MasterKey().get())));
|
||||
} catch (InvalidInputException e) {
|
||||
Log.w(TAG, "Failed to parse pinned groupV2 master key!", e);
|
||||
pinnedRecipient = null;
|
||||
@@ -1524,7 +1524,7 @@ public class ThreadDatabase extends Database {
|
||||
if (threadRecipient.isPushV2Group()) {
|
||||
MessageRecord.InviteAddState inviteAddState = record.getGv2AddInviteState();
|
||||
if (inviteAddState != null) {
|
||||
RecipientId from = RecipientId.from(ServiceId.from(inviteAddState.getAddedOrInvitedBy()), null);
|
||||
RecipientId from = RecipientId.from(ServiceId.from(inviteAddState.getAddedOrInvitedBy()));
|
||||
if (inviteAddState.isInvited()) {
|
||||
Log.i(TAG, "GV2 invite message request from " + from);
|
||||
return Extra.forGroupV2invite(from, individualRecipientId);
|
||||
|
||||
@@ -99,7 +99,7 @@ public class GroupCallUpdateMessageFactory implements UpdateDescription.Spannabl
|
||||
return context.getString(R.string.MessageRecord_unknown);
|
||||
}
|
||||
|
||||
Recipient recipient = Recipient.resolved(RecipientId.from(serviceId, null));
|
||||
Recipient recipient = Recipient.resolved(RecipientId.from(serviceId));
|
||||
|
||||
if (recipient.isSelf()) {
|
||||
return context.getString(R.string.MessageRecord_you);
|
||||
|
||||
@@ -779,7 +779,7 @@ final class GroupsV2UpdateMessageProducer {
|
||||
@DrawableRes int iconResource)
|
||||
{
|
||||
ServiceId serviceId = ServiceId.fromByteStringOrUnknown(uuid1Bytes);
|
||||
RecipientId recipientId = RecipientId.from(serviceId, null);
|
||||
RecipientId recipientId = RecipientId.from(serviceId);
|
||||
|
||||
return UpdateDescription.mentioning(
|
||||
Collections.singletonList(serviceId),
|
||||
@@ -800,8 +800,8 @@ final class GroupsV2UpdateMessageProducer {
|
||||
ServiceId sid1 = ServiceId.fromByteStringOrUnknown(uuid1Bytes);
|
||||
ServiceId sid2 = ServiceId.fromByteStringOrUnknown(uuid2Bytes);
|
||||
|
||||
RecipientId recipientId1 = RecipientId.from(sid1, null);
|
||||
RecipientId recipientId2 = RecipientId.from(sid2, null);
|
||||
RecipientId recipientId1 = RecipientId.from(sid1);
|
||||
RecipientId recipientId2 = RecipientId.from(sid2);
|
||||
|
||||
return UpdateDescription.mentioning(
|
||||
Arrays.asList(sid1, sid2),
|
||||
@@ -821,7 +821,7 @@ final class GroupsV2UpdateMessageProducer {
|
||||
@DrawableRes int iconResource)
|
||||
{
|
||||
ServiceId serviceId = ServiceId.fromByteStringOrUnknown(uuid1Bytes);
|
||||
RecipientId recipientId = RecipientId.from(serviceId, null);
|
||||
RecipientId recipientId = RecipientId.from(serviceId);
|
||||
|
||||
return UpdateDescription.mentioning(
|
||||
Collections.singletonList(serviceId),
|
||||
@@ -842,7 +842,7 @@ final class GroupsV2UpdateMessageProducer {
|
||||
@DrawableRes int iconResource)
|
||||
{
|
||||
ServiceId serviceId = ServiceId.fromByteStringOrUnknown(uuid1Bytes);
|
||||
RecipientId recipientId = RecipientId.from(serviceId, null);
|
||||
RecipientId recipientId = RecipientId.from(serviceId);
|
||||
|
||||
return UpdateDescription.mentioning(
|
||||
Collections.singletonList(serviceId),
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class LiveUpdateMessage {
|
||||
}
|
||||
|
||||
List<LiveData<Recipient>> allMentionedRecipients = Stream.of(updateDescription.getMentioned())
|
||||
.map(uuid -> Recipient.resolved(RecipientId.from(uuid, null)).live().getLiveData())
|
||||
.map(uuid -> Recipient.resolved(RecipientId.from(uuid)).live().getLiveData())
|
||||
.toList();
|
||||
|
||||
LiveData<?> mentionedRecipientChangeStream = allMentionedRecipients.isEmpty() ? LiveDataUtil.just(new Object())
|
||||
|
||||
Reference in New Issue
Block a user