Add additional fallback logic for change dialog.

This commit is contained in:
Cody Henthorne
2021-07-13 19:37:00 -04:00
committed by Greyson Parrelli
parent 14565b0864
commit 55c69cd50a
10 changed files with 60 additions and 210 deletions

View File

@@ -92,6 +92,7 @@ import org.thoughtcrime.securesms.conversation.ConversationMessage.ConversationM
import org.thoughtcrime.securesms.conversation.colors.Colorizer;
import org.thoughtcrime.securesms.conversation.colors.ColorizerView;
import org.thoughtcrime.securesms.conversation.ui.error.EnableCallNotificationSettingsDialog;
import org.thoughtcrime.securesms.conversation.ui.error.SafetyNumberChangeDialog;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessageDatabase;
import org.thoughtcrime.securesms.database.MmsDatabase;
@@ -1585,6 +1586,11 @@ public class ConversationFragment extends LoggingFragment {
RecaptchaProofBottomSheetFragment.show(getChildFragmentManager());
}
@Override
public void onIncomingIdentityMismatchClicked(@NonNull RecipientId recipientId) {
SafetyNumberChangeDialog.show(getParentFragmentManager(), recipientId);
}
@Override
public void onVoiceNotePause(@NonNull Uri uri) {
listener.onVoiceNotePause(uri);

View File

@@ -65,7 +65,6 @@ import com.google.android.exoplayer2.source.MediaSource;
import org.jetbrains.annotations.NotNull;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.BindableConversationItem;
import org.thoughtcrime.securesms.ConfirmIdentityDialog;
import org.thoughtcrime.securesms.MediaPreviewActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
@@ -121,7 +120,6 @@ import org.thoughtcrime.securesms.revealable.ViewOnceMessageView;
import org.thoughtcrime.securesms.revealable.ViewOnceUtil;
import org.thoughtcrime.securesms.stickers.StickerUrl;
import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.InterceptableLongClickCopyLinkSpan;
import org.thoughtcrime.securesms.util.LongClickMovementMethod;
import org.thoughtcrime.securesms.util.Projection;
@@ -1450,16 +1448,6 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
/// Event handlers
private void handleApproveIdentity() {
List<IdentityKeyMismatch> mismatches = messageRecord.getIdentityKeyMismatches();
if (mismatches.size() != 1) {
throw new AssertionError("Identity mismatch count: " + mismatches.size());
}
new ConfirmIdentityDialog(context, messageRecord, mismatches.get(0)).show();
}
private Spannable getLongMessageSpan(@NonNull MessageRecord messageRecord) {
String message;
Runnable action;
@@ -1810,7 +1798,9 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
eventListener.onMessageWithRecaptchaNeededClicked(messageRecord);
}
} else if (!messageRecord.isOutgoing() && messageRecord.isIdentityMismatchFailure()) {
handleApproveIdentity();
if (eventListener != null) {
eventListener.onIncomingIdentityMismatchClicked(messageRecord.getIndividualRecipient().getId());
}
} else if (messageRecord.isPendingInsecureSmsFallback()) {
handleMessageApproval();
}

View File

@@ -46,11 +46,22 @@ public final class SafetyNumberChangeDialog extends DialogFragment implements Sa
private static final String MESSAGE_TYPE_EXTRA = "message_type";
private static final String CONTINUE_TEXT_RESOURCE_EXTRA = "continue_text_resource";
private static final String CANCEL_TEXT_RESOURCE_EXTRA = "cancel_text_resource";
private static final String SKIP_CALLBACKS_EXTRA = "skip_callbacks_extra";
private SafetyNumberChangeViewModel viewModel;
private SafetyNumberChangeAdapter adapter;
private View dialogView;
public static void show(@NonNull FragmentManager fragmentManager, @NonNull RecipientId recipientId) {
Bundle arguments = new Bundle();
arguments.putStringArray(RECIPIENT_IDS_EXTRA, new String[] { recipientId.serialize() });
arguments.putInt(CONTINUE_TEXT_RESOURCE_EXTRA, R.string.safety_number_change_dialog__accept);
arguments.putBoolean(SKIP_CALLBACKS_EXTRA, true);
SafetyNumberChangeDialog fragment = new SafetyNumberChangeDialog();
fragment.setArguments(arguments);
fragment.show(fragmentManager, SAFETY_NUMBER_DIALOG);
}
public static void show(@NonNull FragmentManager fragmentManager, @NonNull List<IdentityDatabase.IdentityRecord> identityRecords) {
List<String> ids = Stream.of(identityRecords)
.filterNot(IdentityDatabase.IdentityRecord::isFirstUse)
@@ -196,9 +207,11 @@ public final class SafetyNumberChangeDialog extends DialogFragment implements Sa
private void handleSendAnyway(DialogInterface dialogInterface, int which) {
Log.d(TAG, "handleSendAnyway");
boolean skipCallbacks = requireArguments().getBoolean(SKIP_CALLBACKS_EXTRA, false);
Activity activity = getActivity();
Callback callback;
if (activity instanceof Callback) {
if (activity instanceof Callback && !skipCallbacks) {
callback = (Callback) activity;
} else {
callback = null;
@@ -241,7 +254,9 @@ public final class SafetyNumberChangeDialog extends DialogFragment implements Sa
public interface Callback {
void onSendAnywayAfterSafetyNumberChange(@NonNull List<RecipientId> changedRecipients);
void onMessageResentAfterSafetyNumberChange();
void onCanceled();
}
}

View File

@@ -29,6 +29,7 @@ import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.signalservice.api.SignalSessionLock;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.Collection;
import java.util.List;
@@ -124,13 +125,14 @@ final class SafetyNumberChangeRepository {
try(SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
for (ChangedRecipient changedRecipient : changedRecipients) {
SignalProtocolAddress mismatchAddress = new SignalProtocolAddress(changedRecipient.getRecipient().requireServiceId(), 1);
SignalProtocolAddress mismatchAddress = new SignalProtocolAddress(changedRecipient.getRecipient().requireServiceId(), SignalServiceAddress.DEFAULT_DEVICE_ID);
TextSecureIdentityKeyStore identityKeyStore = new TextSecureIdentityKeyStore(context);
Log.d(TAG, "Saving identity for: " + changedRecipient.getRecipient().getId() + " " + changedRecipient.getIdentityRecord().getIdentityKey().hashCode());
TextSecureIdentityKeyStore.SaveResult result = identityKeyStore.saveIdentity(mismatchAddress, changedRecipient.getIdentityRecord().getIdentityKey(), true);
Log.d(TAG, "Saving identity result: " + result);
if (result == TextSecureIdentityKeyStore.SaveResult.NO_CHANGE) {
Log.i(TAG, "Archiving sessions explicitly as they appear to be out of sync.");
SessionUtil.archiveSession(context, changedRecipient.getRecipient().getId(), SignalServiceAddress.DEFAULT_DEVICE_ID);
SessionUtil.archiveSiblingSessions(context, mismatchAddress);
DatabaseFactory.getSenderKeySharedDatabase(context).deleteAllFor(changedRecipient.getRecipient().getId());
}