kopia lustrzana https://github.com/ryukoposting/Signal-Android
Utilize RecipientIdCache during message processing.
rodzic
1fb3290038
commit
260575d139
|
@ -49,12 +49,12 @@ public class TextSecureIdentityKeyStore implements IdentityKeyStore {
|
|||
public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey, boolean nonBlockingApproval) {
|
||||
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
||||
IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
|
||||
Recipient recipient = Recipient.external(context, address.getName());
|
||||
Optional<IdentityRecord> identityRecord = identityDatabase.getIdentity(recipient.getId());
|
||||
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
|
||||
Optional<IdentityRecord> identityRecord = identityDatabase.getIdentity(recipientId);
|
||||
|
||||
if (!identityRecord.isPresent()) {
|
||||
Log.i(TAG, "Saving new identity...");
|
||||
identityDatabase.saveIdentity(recipient.getId(), identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
|
||||
identityDatabase.saveIdentity(recipientId, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -70,15 +70,15 @@ public class TextSecureIdentityKeyStore implements IdentityKeyStore {
|
|||
verifiedStatus = VerifiedStatus.DEFAULT;
|
||||
}
|
||||
|
||||
identityDatabase.saveIdentity(recipient.getId(), identityKey, verifiedStatus, false, System.currentTimeMillis(), nonBlockingApproval);
|
||||
IdentityUtil.markIdentityUpdate(context, recipient.getId());
|
||||
identityDatabase.saveIdentity(recipientId, identityKey, verifiedStatus, false, System.currentTimeMillis(), nonBlockingApproval);
|
||||
IdentityUtil.markIdentityUpdate(context, recipientId);
|
||||
SessionUtil.archiveSiblingSessions(context, address);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isNonBlockingApprovalRequired(identityRecord.get())) {
|
||||
Log.i(TAG, "Setting approval status...");
|
||||
identityDatabase.setApproval(recipient.getId(), nonBlockingApproval);
|
||||
identityDatabase.setApproval(recipientId, nonBlockingApproval);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ public class TextSecureIdentityKeyStore implements IdentityKeyStore {
|
|||
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(address.getName())) {
|
||||
IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
|
||||
RecipientId ourRecipientId = Recipient.self().getId();
|
||||
RecipientId theirRecipientId = Recipient.external(context, address.getName()).getId();
|
||||
RecipientId theirRecipientId = RecipientId.fromExternalPush(address.getName());
|
||||
|
||||
if (ourRecipientId.equals(theirRecipientId)) {
|
||||
return identityKey.equals(IdentityKeyUtil.getIdentityKey(context));
|
||||
|
@ -122,7 +122,7 @@ public class TextSecureIdentityKeyStore implements IdentityKeyStore {
|
|||
@Override
|
||||
public IdentityKey getIdentity(SignalProtocolAddress address) {
|
||||
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(address.getName())) {
|
||||
RecipientId recipientId = Recipient.external(context, address.getName()).getId();
|
||||
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
|
||||
Optional<IdentityRecord> record = DatabaseFactory.getIdentityDatabase(context).getIdentity(recipientId);
|
||||
|
||||
if (record.isPresent()) {
|
||||
|
|
|
@ -32,7 +32,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
|||
@Override
|
||||
public SessionRecord loadSession(@NonNull SignalProtocolAddress address) {
|
||||
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
||||
RecipientId recipientId = Recipient.external(context, address.getName()).getId();
|
||||
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
|
||||
SessionRecord sessionRecord = DatabaseFactory.getSessionDatabase(context).load(recipientId, address.getDeviceId());
|
||||
|
||||
if (sessionRecord == null) {
|
||||
|
@ -47,7 +47,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
|||
@Override
|
||||
public void storeSession(@NonNull SignalProtocolAddress address, @NonNull SessionRecord record) {
|
||||
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
||||
RecipientId id = Recipient.external(context, address.getName()).getId();
|
||||
RecipientId id = RecipientId.fromExternalPush(address.getName());
|
||||
DatabaseFactory.getSessionDatabase(context).store(id, address.getDeviceId(), record);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
|||
public boolean containsSession(SignalProtocolAddress address) {
|
||||
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
||||
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(address.getName())) {
|
||||
RecipientId recipientId = Recipient.external(context, address.getName()).getId();
|
||||
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
|
||||
SessionRecord sessionRecord = DatabaseFactory.getSessionDatabase(context).load(recipientId, address.getDeviceId());
|
||||
|
||||
return sessionRecord != null &&
|
||||
|
@ -72,7 +72,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
|||
public void deleteSession(SignalProtocolAddress address) {
|
||||
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
||||
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(address.getName())) {
|
||||
RecipientId recipientId = Recipient.external(context, address.getName()).getId();
|
||||
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
|
||||
DatabaseFactory.getSessionDatabase(context).delete(recipientId, address.getDeviceId());
|
||||
} else {
|
||||
Log.w(TAG, "Tried to delete session for " + address.toString() + ", but none existed!");
|
||||
|
@ -84,7 +84,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
|||
public void deleteAllSessions(String name) {
|
||||
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
||||
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(name)) {
|
||||
RecipientId recipientId = Recipient.external(context, name).getId();
|
||||
RecipientId recipientId = RecipientId.fromExternalPush(name);
|
||||
DatabaseFactory.getSessionDatabase(context).deleteAllFor(recipientId);
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
|||
public List<Integer> getSubDeviceSessions(String name) {
|
||||
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
||||
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(name)) {
|
||||
RecipientId recipientId = Recipient.external(context, name).getId();
|
||||
RecipientId recipientId = RecipientId.fromExternalPush(name);
|
||||
return DatabaseFactory.getSessionDatabase(context).getSubDevices(recipientId);
|
||||
} else {
|
||||
Log.w(TAG, "Tried to get sub device sessions for " + name + ", but none existed!");
|
||||
|
@ -107,7 +107,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
|||
public void archiveSession(SignalProtocolAddress address) {
|
||||
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
||||
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(address.getName())) {
|
||||
RecipientId recipientId = Recipient.external(context, address.getName()).getId();
|
||||
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
|
||||
archiveSession(recipientId, address.getDeviceId());
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
|||
public void archiveSiblingSessions(@NonNull SignalProtocolAddress address) {
|
||||
try (SignalSessionLock.Lock unused = DatabaseSessionLock.INSTANCE.acquire()) {
|
||||
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(address.getName())) {
|
||||
RecipientId recipientId = Recipient.external(context, address.getName()).getId();
|
||||
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
|
||||
List<SessionDatabase.SessionRow> sessions = DatabaseFactory.getSessionDatabase(context).getAllFor(recipientId);
|
||||
|
||||
for (SessionDatabase.SessionRow row : sessions) {
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
|||
import org.thoughtcrime.securesms.util.DelimiterUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -56,6 +57,20 @@ public class RecipientId implements Parcelable, Comparable<RecipientId> {
|
|||
return from(address.getUuid().orNull(), address.getNumber().orNull(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for when you have a string that could be either a UUID or an e164. This was primarily
|
||||
* created for interacting with protocol stores.
|
||||
* @param identifier A UUID or e164
|
||||
*/
|
||||
@AnyThread
|
||||
public static @NonNull RecipientId fromExternalPush(@NonNull String identifier) {
|
||||
if (UuidUtil.isUuid(identifier)) {
|
||||
return from(UuidUtil.parseOrThrow(identifier), null);
|
||||
} else {
|
||||
return from(null, identifier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates that the pairing is from a high-trust source.
|
||||
* See {@link Recipient#externalHighTrustPush(Context, SignalServiceAddress)}
|
||||
|
|
Ładowanie…
Reference in New Issue