Skip to content

Commit

Permalink
Fix bug where SN change dialog appeared unnecessarily.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal authored and greyson-signal committed Aug 14, 2020
1 parent 761de13 commit 5ced1a7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,7 @@ private void sendMessage() {

if ((recipient.isMmsGroup() || recipient.getEmail().isPresent()) && !isMmsEnabled) {
handleManualMmsRequired();
} else if (!forceSms && (identityRecords.isUnverified() || identityRecords.isUntrusted())) {
} else if (!forceSms && (identityRecords.isUnverified(true) || identityRecords.isUntrusted(true))) {
handleRecentSafetyNumberChange();
} else if (isMediaMessage) {
sendMediaMessage(forceSms, expiresIn, false, subscriptionId, initiating);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class SafetyNumberChangeDialog extends DialogFragment implements Sa

public static @NonNull SafetyNumberChangeDialog create(List<IdentityDatabase.IdentityRecord> identityRecords) {
List<String> ids = Stream.of(identityRecords)
.filterNot(IdentityDatabase.IdentityRecord::isFirstUse)
.map(record -> record.getRecipientId().serialize())
.distinct()
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void updateIdentityAfterSync(@NonNull RecipientId id, IdentityKey identit
boolean statusMatches = keyMatches && hasMatchingStatus(id, identityKey, verifiedStatus);

if (!keyMatches || !statusMatches) {
saveIdentityInternal(id, identityKey, verifiedStatus, false, System.currentTimeMillis(), true);
saveIdentityInternal(id, identityKey, verifiedStatus, !hadEntry, System.currentTimeMillis(), true);
Optional<IdentityRecord> record = getIdentity(id);
if (record.isPresent()) EventBus.getDefault().post(record.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,26 @@ private static boolean isUnverified(@NonNull Collection<IdentityRecord> identity
return false;
}

public boolean isUntrusted() {
public boolean isUnverified(boolean excludeFirstUse) {
for (IdentityRecord identityRecord : identityRecords) {
if (excludeFirstUse && identityRecord.isFirstUse()) {
continue;
}

if (identityRecord.getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
return true;
}
}

return false;
}

public boolean isUntrusted(boolean excludeFirstUse) {
for (IdentityRecord identityRecord : identityRecords) {
if (excludeFirstUse && identityRecord.isFirstUse()) {
continue;
}

if (isUntrusted(identityRecord)) {
return true;
}
Expand Down

0 comments on commit 5ced1a7

Please sign in to comment.