Ensure we enqueue a storage sync after a safety number change.

fork-5.53.8
Greyson Parrelli 2022-04-20 10:49:15 -04:00 zatwierdzone przez Alex Hart
rodzic 55acd0f048
commit dfcadde076
4 zmienionych plików z 28 dodań i 7 usunięć

Wyświetl plik

@ -71,13 +71,13 @@ public class SignalBaseIdentityKeyStore {
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
if (identityRecord == null) {
Log.i(TAG, "Saving new identity...");
Log.i(TAG, "Saving new identity for " + address);
cache.save(address.getName(), recipientId, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
return SaveResult.NEW;
}
if (!identityRecord.getIdentityKey().equals(identityKey)) {
Log.i(TAG, "Replacing existing identity... Existing: " + identityRecord.getIdentityKey().hashCode() + " New: " + identityKey.hashCode());
Log.i(TAG, "Replacing existing identity for " + address + " | Existing: " + identityRecord.getIdentityKey().hashCode() + ", New: " + identityKey.hashCode());
VerifiedStatus verifiedStatus;
if (identityRecord.getVerifiedStatus() == VerifiedStatus.VERIFIED ||
@ -96,7 +96,7 @@ public class SignalBaseIdentityKeyStore {
}
if (isNonBlockingApprovalRequired(identityRecord)) {
Log.i(TAG, "Setting approval status...");
Log.i(TAG, "Setting approval status for " + address);
cache.setApproval(address.getName(), recipientId, identityRecord, nonBlockingApproval);
return SaveResult.NON_BLOCKING_APPROVAL_REQUIRED;
}

Wyświetl plik

@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.database.model.IdentityStoreRecord;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
import org.thoughtcrime.securesms.util.Base64;
import org.signal.core.util.CursorUtil;
import org.thoughtcrime.securesms.util.IdentityUtil;
@ -141,6 +142,7 @@ public class IdentityDatabase extends Database {
{
saveIdentityInternal(addressName, recipientId, identityKey, verifiedStatus, firstUse, timestamp, nonBlockingApproval);
SignalDatabase.recipients().markNeedsSync(recipientId);
StorageSyncHelper.scheduleSyncForDataChange();
}
public void setApproval(@NonNull String addressName, @NonNull RecipientId recipientId, boolean nonBlockingApproval) {
@ -152,6 +154,7 @@ public class IdentityDatabase extends Database {
database.update(TABLE_NAME, contentValues, ADDRESS + " = ?", SqlUtil.buildArgs(addressName));
SignalDatabase.recipients().markNeedsSync(recipientId);
StorageSyncHelper.scheduleSyncForDataChange();
}
public void setVerified(@NonNull String addressName, @NonNull RecipientId recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus) {
@ -169,11 +172,14 @@ public class IdentityDatabase extends Database {
Optional<IdentityRecord> record = getIdentityRecord(addressName);
if (record.isPresent()) EventBus.getDefault().post(record.get());
SignalDatabase.recipients().markNeedsSync(recipientId);
StorageSyncHelper.scheduleSyncForDataChange();
}
}
public void updateIdentityAfterSync(@NonNull String addressName, @NonNull RecipientId recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus) {
boolean hadEntry = getIdentityRecord(addressName).isPresent();
Optional<IdentityRecord> existingRecord = getIdentityRecord(addressName);
boolean hadEntry = existingRecord.isPresent();
boolean keyMatches = hasMatchingKey(addressName, identityKey);
boolean statusMatches = keyMatches && hasMatchingStatus(addressName, identityKey, verifiedStatus);
@ -190,7 +196,8 @@ public class IdentityDatabase extends Database {
}
if (hadEntry && !keyMatches) {
IdentityUtil.markIdentityUpdate(context, RecipientId.fromExternalPush(addressName));
Log.w(TAG, "Updated identity key during storage sync for " + addressName + " | Existing: " + existingRecord.get().getIdentityKey().hashCode() + ", New: " + identityKey.hashCode());
IdentityUtil.markIdentityUpdate(context, recipientId);
}
}

Wyświetl plik

@ -86,6 +86,7 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
.map(r -> r.getContact().get());
}
@Override
@NonNull SignalContactRecord merge(@NonNull SignalContactRecord remote, @NonNull SignalContactRecord local, @NonNull StorageKeyGenerator keyGenerator) {
String givenName;
String familyName;
@ -98,14 +99,25 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
familyName = local.getFamilyName().orElse("");
}
IdentityState identityState;
byte[] identityKey;
if ((remote.getIdentityState() != local.getIdentityState() && remote.getIdentityKey().isPresent()) ||
(remote.getIdentityKey().isPresent() && !local.getIdentityKey().isPresent()))
{
identityState = remote.getIdentityState();
identityKey = remote.getIdentityKey().get();
} else {
identityState = local.getIdentityState();
identityKey = local.getIdentityKey().orElse(null);
}
byte[] unknownFields = remote.serializeUnknownFields();
ServiceId serviceId = local.getAddress().getServiceId() == ServiceId.UNKNOWN ? remote.getAddress().getServiceId() : local.getAddress().getServiceId();
String e164 = OptionalUtil.or(remote.getAddress().getNumber(), local.getAddress().getNumber()).orElse(null);
SignalServiceAddress address = new SignalServiceAddress(serviceId, e164);
byte[] profileKey = OptionalUtil.or(remote.getProfileKey(), local.getProfileKey()).orElse(null);
String username = OptionalUtil.or(remote.getUsername(), local.getUsername()).orElse("");
IdentityState identityState = remote.getIdentityKey().isPresent() ? remote.getIdentityState() : local.getIdentityState();
byte[] identityKey = OptionalUtil.or(remote.getIdentityKey(), local.getIdentityKey()).orElse(null);
boolean blocked = remote.isBlocked();
boolean profileSharing = remote.isProfileSharingEnabled();
boolean archived = remote.isArchived();

Wyświetl plik

@ -116,6 +116,8 @@ public final class IdentityUtil {
}
public static void markIdentityUpdate(@NonNull Context context, @NonNull RecipientId recipientId) {
Log.w(TAG, "Inserting safety number change event(s) for " + recipientId, new Throwable());
long time = System.currentTimeMillis();
MessageDatabase smsDatabase = SignalDatabase.sms();
GroupDatabase groupDatabase = SignalDatabase.groups();