use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.
the class RemappedRecords method remap.
@NonNull
Set<RecipientId> remap(@NonNull Collection<RecipientId> recipientIds) {
ensureRecipientMapIsPopulated();
Set<RecipientId> remapped = new LinkedHashSet<>();
for (RecipientId original : recipientIds) {
if (recipientMap.containsKey(original)) {
remapped.add(recipientMap.get(original));
} else {
remapped.add(original);
}
}
return remapped;
}
use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.
the class RemappedRecordsDatabase method getAllRecipientMappings.
@NonNull
Map<RecipientId, RecipientId> getAllRecipientMappings() {
SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
Map<RecipientId, RecipientId> recipientMap = new HashMap<>();
db.beginTransaction();
try {
List<Mapping> mappings = getAllMappings(Recipients.TABLE_NAME);
for (Mapping mapping : mappings) {
RecipientId oldId = RecipientId.from(mapping.getOldId());
RecipientId newId = RecipientId.from(mapping.getNewId());
recipientMap.put(oldId, newId);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return recipientMap;
}
use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.
the class ConfirmPaymentRepository method confirmPayment.
@AnyThread
void confirmPayment(@NonNull ConfirmPaymentState state, @NonNull Consumer<ConfirmPaymentResult> consumer) {
Log.i(TAG, "confirmPayment");
SignalExecutors.BOUNDED.execute(() -> {
Balance balance = wallet.getCachedBalance();
if (state.getTotal().requireMobileCoin().greaterThan(balance.getFullAmount().requireMobileCoin())) {
Log.w(TAG, "The total was greater than the wallet's balance");
consumer.accept(new ConfirmPaymentResult.Error());
return;
}
Payee payee = state.getPayee();
RecipientId recipientId;
MobileCoinPublicAddress mobileCoinPublicAddress;
if (payee.hasRecipientId()) {
recipientId = payee.requireRecipientId();
try {
mobileCoinPublicAddress = ProfileUtil.getAddressForRecipient(Recipient.resolved(recipientId));
} catch (IOException e) {
Log.w(TAG, "Failed to get address for recipient " + recipientId);
consumer.accept(new ConfirmPaymentResult.Error());
return;
} catch (PaymentsAddressException e) {
Log.w(TAG, "Failed to get address for recipient " + recipientId);
consumer.accept(new ConfirmPaymentResult.Error(e.getCode()));
return;
}
} else if (payee.hasPublicAddress()) {
recipientId = null;
mobileCoinPublicAddress = payee.requirePublicAddress();
} else
throw new AssertionError();
UUID paymentUuid = PaymentSendJob.enqueuePayment(recipientId, mobileCoinPublicAddress, Util.emptyIfNull(state.getNote()), state.getAmount().requireMobileCoin(), state.getFee().requireMobileCoin());
Log.i(TAG, "confirmPayment: PaymentSendJob enqueued");
consumer.accept(new ConfirmPaymentResult.Success(paymentUuid));
});
}
use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.
the class VerifyDisplayFragment method initializeFingerprint.
private void initializeFingerprint() {
RecipientId recipientId = getArguments().getParcelable(RECIPIENT_ID);
IdentityKeyParcelable localIdentityParcelable = getArguments().getParcelable(LOCAL_IDENTITY);
IdentityKeyParcelable remoteIdentityParcelable = getArguments().getParcelable(REMOTE_IDENTITY);
this.localIdentity = localIdentityParcelable.get();
this.recipient = Recipient.live(recipientId);
this.remoteIdentity = remoteIdentityParcelable.get();
int version;
byte[] localId;
byte[] remoteId;
// noinspection WrongThread
Recipient resolved = recipient.resolve();
if (FeatureFlags.verifyV2() && resolved.getServiceId().isPresent()) {
Log.i(TAG, "Using UUID (version 2).");
version = 2;
localId = Recipient.self().requireServiceId().toByteArray();
remoteId = resolved.requireServiceId().toByteArray();
} else if (!FeatureFlags.verifyV2() && resolved.getE164().isPresent()) {
Log.i(TAG, "Using E164 (version 1).");
version = 1;
localId = Recipient.self().requireE164().getBytes();
remoteId = resolved.requireE164().getBytes();
} else {
Log.w(TAG, String.format(Locale.ENGLISH, "Could not show proper verification! verifyV2: %s, hasUuid: %s, hasE164: %s", FeatureFlags.verifyV2(), resolved.getServiceId().isPresent(), resolved.getE164().isPresent()));
new MaterialAlertDialogBuilder(requireContext()).setMessage(getString(R.string.VerifyIdentityActivity_you_must_first_exchange_messages_in_order_to_view, resolved.getDisplayName(requireContext()))).setPositiveButton(android.R.string.ok, (dialog, which) -> requireActivity().finish()).setOnDismissListener(dialog -> {
requireActivity().finish();
dialog.dismiss();
}).show();
return;
}
this.recipient.observe(this, this::setRecipientText);
SimpleTask.run(() -> new NumericFingerprintGenerator(5200).createFor(version, localId, localIdentity, remoteId, remoteIdentity), fingerprint -> {
if (getActivity() == null)
return;
VerifyDisplayFragment.this.fingerprint = fingerprint;
setFingerprintViews(fingerprint, true);
initializeOptionsMenu();
});
}
use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.
the class VerifyDisplayFragment method updateVerifyButton.
private void updateVerifyButton(boolean verified, boolean update) {
currentVerifiedState = verified;
if (verified) {
verifyButton.setText(R.string.verify_display_fragment__clear_verification);
} else {
verifyButton.setText(R.string.verify_display_fragment__mark_as_verified);
}
if (update) {
final RecipientId recipientId = recipient.getId();
final Context context = requireContext().getApplicationContext();
SignalExecutors.BOUNDED.execute(() -> {
try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
if (verified) {
Log.i(TAG, "Saving identity: " + recipientId);
ApplicationDependencies.getProtocolStore().aci().identities().saveIdentityWithoutSideEffects(recipientId, remoteIdentity, IdentityDatabase.VerifiedStatus.VERIFIED, false, System.currentTimeMillis(), true);
} else {
ApplicationDependencies.getProtocolStore().aci().identities().setVerified(recipientId, remoteIdentity, IdentityDatabase.VerifiedStatus.DEFAULT);
}
ApplicationDependencies.getJobManager().add(new MultiDeviceVerifiedUpdateJob(recipientId, remoteIdentity, verified ? IdentityDatabase.VerifiedStatus.VERIFIED : IdentityDatabase.VerifiedStatus.DEFAULT));
StorageSyncHelper.scheduleSyncForDataChange();
IdentityUtil.markIdentityVerified(context, recipient.get(), verified, false);
}
});
}
}
Aggregations