Fix bug with skipping resend message on safety number change.
parent
dfa4f0c309
commit
5f9c0c3204
|
@ -24,6 +24,7 @@ import com.annimon.stream.Stream;
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.VerifyIdentityActivity;
|
import org.thoughtcrime.securesms.VerifyIdentityActivity;
|
||||||
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
||||||
|
import org.thoughtcrime.securesms.database.MmsSmsDatabase;
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ public final class SafetyNumberChangeDialog extends DialogFragment implements Sa
|
||||||
|
|
||||||
private static final String RECIPIENT_IDS_EXTRA = "recipient_ids";
|
private static final String RECIPIENT_IDS_EXTRA = "recipient_ids";
|
||||||
private static final String MESSAGE_ID_EXTRA = "message_id";
|
private static final String MESSAGE_ID_EXTRA = "message_id";
|
||||||
|
private static final String MESSAGE_TYPE_EXTRA = "message_type";
|
||||||
|
|
||||||
private SafetyNumberChangeViewModel viewModel;
|
private SafetyNumberChangeViewModel viewModel;
|
||||||
private SafetyNumberChangeAdapter adapter;
|
private SafetyNumberChangeAdapter adapter;
|
||||||
|
@ -62,6 +64,7 @@ public final class SafetyNumberChangeDialog extends DialogFragment implements Sa
|
||||||
Bundle arguments = new Bundle();
|
Bundle arguments = new Bundle();
|
||||||
arguments.putStringArray(RECIPIENT_IDS_EXTRA, ids.toArray(new String[0]));
|
arguments.putStringArray(RECIPIENT_IDS_EXTRA, ids.toArray(new String[0]));
|
||||||
arguments.putLong(MESSAGE_ID_EXTRA, messageRecord.getId());
|
arguments.putLong(MESSAGE_ID_EXTRA, messageRecord.getId());
|
||||||
|
arguments.putString(MESSAGE_TYPE_EXTRA, messageRecord.isMms() ? MmsSmsDatabase.MMS_TRANSPORT : MmsSmsDatabase.SMS_TRANSPORT);
|
||||||
SafetyNumberChangeDialog fragment = new SafetyNumberChangeDialog();
|
SafetyNumberChangeDialog fragment = new SafetyNumberChangeDialog();
|
||||||
fragment.setArguments(arguments);
|
fragment.setArguments(arguments);
|
||||||
return fragment;
|
return fragment;
|
||||||
|
@ -78,10 +81,12 @@ public final class SafetyNumberChangeDialog extends DialogFragment implements Sa
|
||||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
//noinspection ConstantConditions
|
||||||
List<RecipientId> recipientIds = Stream.of(getArguments().getStringArray(RECIPIENT_IDS_EXTRA)).map(RecipientId::from).toList();
|
List<RecipientId> recipientIds = Stream.of(getArguments().getStringArray(RECIPIENT_IDS_EXTRA)).map(RecipientId::from).toList();
|
||||||
long messageId = getArguments().getLong(MESSAGE_ID_EXTRA, -1);
|
long messageId = getArguments().getLong(MESSAGE_ID_EXTRA, -1);
|
||||||
|
String messageType = getArguments().getString(MESSAGE_TYPE_EXTRA, null);
|
||||||
|
|
||||||
viewModel = ViewModelProviders.of(this, new SafetyNumberChangeViewModel.Factory(recipientIds, (messageId != -1) ? messageId : null)).get(SafetyNumberChangeViewModel.class);
|
viewModel = ViewModelProviders.of(this, new SafetyNumberChangeViewModel.Factory(recipientIds, (messageId != -1) ? messageId : null, messageType)).get(SafetyNumberChangeViewModel.class);
|
||||||
viewModel.getChangedRecipients().observe(getViewLifecycleOwner(), adapter::submitList);
|
viewModel.getChangedRecipients().observe(getViewLifecycleOwner(), adapter::submitList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,11 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
||||||
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
||||||
import org.thoughtcrime.securesms.database.MmsDatabase;
|
import org.thoughtcrime.securesms.database.MmsDatabase;
|
||||||
|
import org.thoughtcrime.securesms.database.MmsSmsDatabase;
|
||||||
|
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
||||||
import org.thoughtcrime.securesms.database.SmsDatabase;
|
import org.thoughtcrime.securesms.database.SmsDatabase;
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||||
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
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.sms.MessageSender;
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
||||||
|
@ -30,15 +33,17 @@ import static org.whispersystems.libsignal.SessionCipher.SESSION_LOCK;
|
||||||
|
|
||||||
final class SafetyNumberChangeRepository {
|
final class SafetyNumberChangeRepository {
|
||||||
|
|
||||||
|
private static final String TAG = SafetyNumberChangeRepository.class.getSimpleName();
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
SafetyNumberChangeRepository(Context context) {
|
SafetyNumberChangeRepository(Context context) {
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull LiveData<SafetyNumberChangeState> getSafetyNumberChangeState(@NonNull List<RecipientId> recipientIds, @Nullable Long messageId) {
|
@NonNull LiveData<SafetyNumberChangeState> getSafetyNumberChangeState(@NonNull List<RecipientId> recipientIds, @Nullable Long messageId, @Nullable String messageType) {
|
||||||
MutableLiveData<SafetyNumberChangeState> liveData = new MutableLiveData<>();
|
MutableLiveData<SafetyNumberChangeState> liveData = new MutableLiveData<>();
|
||||||
SignalExecutors.BOUNDED.execute(() -> liveData.postValue(getSafetyNumberChangeStateInternal(recipientIds, messageId)));
|
SignalExecutors.BOUNDED.execute(() -> liveData.postValue(getSafetyNumberChangeStateInternal(recipientIds, messageId, messageType)));
|
||||||
return liveData;
|
return liveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,10 +60,10 @@ final class SafetyNumberChangeRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private @NonNull SafetyNumberChangeState getSafetyNumberChangeStateInternal(@NonNull List<RecipientId> recipientIds, @Nullable Long messageId) {
|
private @NonNull SafetyNumberChangeState getSafetyNumberChangeStateInternal(@NonNull List<RecipientId> recipientIds, @Nullable Long messageId, @Nullable String messageType) {
|
||||||
MessageRecord messageRecord = null;
|
MessageRecord messageRecord = null;
|
||||||
if (messageId != null) {
|
if (messageId != null && messageType != null) {
|
||||||
messageRecord = DatabaseFactory.getMmsSmsDatabase(context).getMessageRecord(messageId);
|
messageRecord = getMessageRecord(messageId, messageType);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Recipient> recipients = Stream.of(recipientIds).map(Recipient::resolved).toList();
|
List<Recipient> recipients = Stream.of(recipientIds).map(Recipient::resolved).toList();
|
||||||
|
@ -70,6 +75,23 @@ final class SafetyNumberChangeRepository {
|
||||||
return new SafetyNumberChangeState(changedRecipients, messageRecord);
|
return new SafetyNumberChangeState(changedRecipients, messageRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
private @Nullable MessageRecord getMessageRecord(Long messageId, String messageType) {
|
||||||
|
try {
|
||||||
|
switch (messageType) {
|
||||||
|
case MmsSmsDatabase.SMS_TRANSPORT:
|
||||||
|
return DatabaseFactory.getSmsDatabase(context).getMessage(messageId);
|
||||||
|
case MmsSmsDatabase.MMS_TRANSPORT:
|
||||||
|
return DatabaseFactory.getMmsDatabase(context).getMessageRecord(messageId);
|
||||||
|
default:
|
||||||
|
throw new AssertionError("no valid message type specified");
|
||||||
|
}
|
||||||
|
} catch (NoSuchMessageException e) {
|
||||||
|
Log.i(TAG, e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private TrustAndVerifyResult trustOrVerifyChangedRecipientsInternal(@NonNull List<ChangedRecipient> changedRecipients) {
|
private TrustAndVerifyResult trustOrVerifyChangedRecipientsInternal(@NonNull List<ChangedRecipient> changedRecipients) {
|
||||||
IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
|
IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
|
||||||
|
|
|
@ -19,9 +19,13 @@ public final class SafetyNumberChangeViewModel extends ViewModel {
|
||||||
private final SafetyNumberChangeRepository safetyNumberChangeRepository;
|
private final SafetyNumberChangeRepository safetyNumberChangeRepository;
|
||||||
private final LiveData<SafetyNumberChangeState> safetyNumberChangeState;
|
private final LiveData<SafetyNumberChangeState> safetyNumberChangeState;
|
||||||
|
|
||||||
private SafetyNumberChangeViewModel(@NonNull List<RecipientId> recipientIds, @Nullable Long messageId, SafetyNumberChangeRepository safetyNumberChangeRepository) {
|
private SafetyNumberChangeViewModel(@NonNull List<RecipientId> recipientIds,
|
||||||
|
@Nullable Long messageId,
|
||||||
|
@Nullable String messageType,
|
||||||
|
SafetyNumberChangeRepository safetyNumberChangeRepository)
|
||||||
|
{
|
||||||
this.safetyNumberChangeRepository = safetyNumberChangeRepository;
|
this.safetyNumberChangeRepository = safetyNumberChangeRepository;
|
||||||
safetyNumberChangeState = this.safetyNumberChangeRepository.getSafetyNumberChangeState(recipientIds, messageId);
|
safetyNumberChangeState = this.safetyNumberChangeRepository.getSafetyNumberChangeState(recipientIds, messageId, messageType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull LiveData<List<ChangedRecipient>> getChangedRecipients() {
|
@NonNull LiveData<List<ChangedRecipient>> getChangedRecipients() {
|
||||||
|
@ -40,16 +44,18 @@ public final class SafetyNumberChangeViewModel extends ViewModel {
|
||||||
public static final class Factory implements ViewModelProvider.Factory {
|
public static final class Factory implements ViewModelProvider.Factory {
|
||||||
private final List<RecipientId> recipientIds;
|
private final List<RecipientId> recipientIds;
|
||||||
private final Long messageId;
|
private final Long messageId;
|
||||||
|
private final String messageType;
|
||||||
|
|
||||||
public Factory(@NonNull List<RecipientId> recipientIds, @Nullable Long messageId) {
|
public Factory(@NonNull List<RecipientId> recipientIds, @Nullable Long messageId, @Nullable String messageType) {
|
||||||
this.recipientIds = recipientIds;
|
this.recipientIds = recipientIds;
|
||||||
this.messageId = messageId;
|
this.messageId = messageId;
|
||||||
|
this.messageType = messageType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
public @NonNull <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
SafetyNumberChangeRepository repo = new SafetyNumberChangeRepository(ApplicationDependencies.getApplication());
|
SafetyNumberChangeRepository repo = new SafetyNumberChangeRepository(ApplicationDependencies.getApplication());
|
||||||
return Objects.requireNonNull(modelClass.cast(new SafetyNumberChangeViewModel(recipientIds, messageId, repo)));
|
return Objects.requireNonNull(modelClass.cast(new SafetyNumberChangeViewModel(recipientIds, messageId, messageType, repo)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,18 +280,6 @@ public class MmsSmsDatabase extends Database {
|
||||||
else return id;
|
else return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable MessageRecord getMessageRecord(long messageId) {
|
|
||||||
try {
|
|
||||||
return DatabaseFactory.getSmsDatabase(context).getMessage(messageId);
|
|
||||||
} catch (NoSuchMessageException e1) {
|
|
||||||
try {
|
|
||||||
return DatabaseFactory.getMmsDatabase(context).getMessageRecord(messageId);
|
|
||||||
} catch (NoSuchMessageException e2) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void incrementDeliveryReceiptCount(SyncMessageId syncMessageId, long timestamp) {
|
public void incrementDeliveryReceiptCount(SyncMessageId syncMessageId, long timestamp) {
|
||||||
DatabaseFactory.getSmsDatabase(context).incrementReceiptCount(syncMessageId, true);
|
DatabaseFactory.getSmsDatabase(context).incrementReceiptCount(syncMessageId, true);
|
||||||
DatabaseFactory.getMmsDatabase(context).incrementReceiptCount(syncMessageId, timestamp, true);
|
DatabaseFactory.getMmsDatabase(context).incrementReceiptCount(syncMessageId, timestamp, true);
|
||||||
|
|
Loading…
Reference in New Issue