kopia lustrzana https://github.com/ryukoposting/Signal-Android
Ensure we enqueue a storage sync after a safety number change.
rodzic
55acd0f048
commit
dfcadde076
|
@ -71,13 +71,13 @@ public class SignalBaseIdentityKeyStore {
|
||||||
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
|
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
|
||||||
|
|
||||||
if (identityRecord == null) {
|
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);
|
cache.save(address.getName(), recipientId, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
|
||||||
return SaveResult.NEW;
|
return SaveResult.NEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!identityRecord.getIdentityKey().equals(identityKey)) {
|
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;
|
VerifiedStatus verifiedStatus;
|
||||||
|
|
||||||
if (identityRecord.getVerifiedStatus() == VerifiedStatus.VERIFIED ||
|
if (identityRecord.getVerifiedStatus() == VerifiedStatus.VERIFIED ||
|
||||||
|
@ -96,7 +96,7 @@ public class SignalBaseIdentityKeyStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNonBlockingApprovalRequired(identityRecord)) {
|
if (isNonBlockingApprovalRequired(identityRecord)) {
|
||||||
Log.i(TAG, "Setting approval status...");
|
Log.i(TAG, "Setting approval status for " + address);
|
||||||
cache.setApproval(address.getName(), recipientId, identityRecord, nonBlockingApproval);
|
cache.setApproval(address.getName(), recipientId, identityRecord, nonBlockingApproval);
|
||||||
return SaveResult.NON_BLOCKING_APPROVAL_REQUIRED;
|
return SaveResult.NON_BLOCKING_APPROVAL_REQUIRED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.database.model.IdentityStoreRecord;
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||||
|
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.thoughtcrime.securesms.util.Base64;
|
||||||
import org.signal.core.util.CursorUtil;
|
import org.signal.core.util.CursorUtil;
|
||||||
import org.thoughtcrime.securesms.util.IdentityUtil;
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
||||||
|
@ -141,6 +142,7 @@ public class IdentityDatabase extends Database {
|
||||||
{
|
{
|
||||||
saveIdentityInternal(addressName, recipientId, identityKey, verifiedStatus, firstUse, timestamp, nonBlockingApproval);
|
saveIdentityInternal(addressName, recipientId, identityKey, verifiedStatus, firstUse, timestamp, nonBlockingApproval);
|
||||||
SignalDatabase.recipients().markNeedsSync(recipientId);
|
SignalDatabase.recipients().markNeedsSync(recipientId);
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApproval(@NonNull String addressName, @NonNull RecipientId recipientId, boolean nonBlockingApproval) {
|
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));
|
database.update(TABLE_NAME, contentValues, ADDRESS + " = ?", SqlUtil.buildArgs(addressName));
|
||||||
|
|
||||||
SignalDatabase.recipients().markNeedsSync(recipientId);
|
SignalDatabase.recipients().markNeedsSync(recipientId);
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVerified(@NonNull String addressName, @NonNull RecipientId recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus) {
|
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);
|
Optional<IdentityRecord> record = getIdentityRecord(addressName);
|
||||||
if (record.isPresent()) EventBus.getDefault().post(record.get());
|
if (record.isPresent()) EventBus.getDefault().post(record.get());
|
||||||
SignalDatabase.recipients().markNeedsSync(recipientId);
|
SignalDatabase.recipients().markNeedsSync(recipientId);
|
||||||
|
StorageSyncHelper.scheduleSyncForDataChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateIdentityAfterSync(@NonNull String addressName, @NonNull RecipientId recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus) {
|
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 keyMatches = hasMatchingKey(addressName, identityKey);
|
||||||
boolean statusMatches = keyMatches && hasMatchingStatus(addressName, identityKey, verifiedStatus);
|
boolean statusMatches = keyMatches && hasMatchingStatus(addressName, identityKey, verifiedStatus);
|
||||||
|
|
||||||
|
@ -190,7 +196,8 @@ public class IdentityDatabase extends Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hadEntry && !keyMatches) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,7 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
||||||
.map(r -> r.getContact().get());
|
.map(r -> r.getContact().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@NonNull SignalContactRecord merge(@NonNull SignalContactRecord remote, @NonNull SignalContactRecord local, @NonNull StorageKeyGenerator keyGenerator) {
|
@NonNull SignalContactRecord merge(@NonNull SignalContactRecord remote, @NonNull SignalContactRecord local, @NonNull StorageKeyGenerator keyGenerator) {
|
||||||
String givenName;
|
String givenName;
|
||||||
String familyName;
|
String familyName;
|
||||||
|
@ -98,14 +99,25 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
||||||
familyName = local.getFamilyName().orElse("");
|
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();
|
byte[] unknownFields = remote.serializeUnknownFields();
|
||||||
ServiceId serviceId = local.getAddress().getServiceId() == ServiceId.UNKNOWN ? remote.getAddress().getServiceId() : local.getAddress().getServiceId();
|
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);
|
String e164 = OptionalUtil.or(remote.getAddress().getNumber(), local.getAddress().getNumber()).orElse(null);
|
||||||
SignalServiceAddress address = new SignalServiceAddress(serviceId, e164);
|
SignalServiceAddress address = new SignalServiceAddress(serviceId, e164);
|
||||||
byte[] profileKey = OptionalUtil.or(remote.getProfileKey(), local.getProfileKey()).orElse(null);
|
byte[] profileKey = OptionalUtil.or(remote.getProfileKey(), local.getProfileKey()).orElse(null);
|
||||||
String username = OptionalUtil.or(remote.getUsername(), local.getUsername()).orElse("");
|
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 blocked = remote.isBlocked();
|
||||||
boolean profileSharing = remote.isProfileSharingEnabled();
|
boolean profileSharing = remote.isProfileSharingEnabled();
|
||||||
boolean archived = remote.isArchived();
|
boolean archived = remote.isArchived();
|
||||||
|
|
|
@ -116,6 +116,8 @@ public final class IdentityUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void markIdentityUpdate(@NonNull Context context, @NonNull RecipientId recipientId) {
|
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();
|
long time = System.currentTimeMillis();
|
||||||
MessageDatabase smsDatabase = SignalDatabase.sms();
|
MessageDatabase smsDatabase = SignalDatabase.sms();
|
||||||
GroupDatabase groupDatabase = SignalDatabase.groups();
|
GroupDatabase groupDatabase = SignalDatabase.groups();
|
||||||
|
|
Ładowanie…
Reference in New Issue