mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-26 03:40:56 +01:00
Utilize RecipientIdCache during message processing.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user