Search in sources :

Example 6 with NotPushRegisteredException

use of org.thoughtcrime.securesms.net.NotPushRegisteredException in project Signal-Android by signalapp.

the class MultiDeviceOutgoingPaymentSyncJob method onRun.

@Override
protected void onRun() throws Exception {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Not multi device, aborting...");
        return;
    }
    PaymentDatabase.PaymentTransaction payment = SignalDatabase.payments().getPayment(uuid);
    if (payment == null) {
        Log.w(TAG, "Payment not found " + uuid);
        return;
    }
    PaymentMetaData.MobileCoinTxoIdentification txoIdentification = payment.getPaymentMetaData().getMobileCoinTxoIdentification();
    boolean defrag = payment.isDefrag();
    Optional<SignalServiceAddress> uuid;
    if (!defrag && payment.getPayee().hasRecipientId()) {
        uuid = Optional.of(new SignalServiceAddress(Recipient.resolved(payment.getPayee().requireRecipientId()).requireServiceId()));
    } else {
        uuid = Optional.absent();
    }
    byte[] receipt = payment.getReceipt();
    if (receipt == null) {
        throw new AssertionError("Trying to sync payment before sent?");
    }
    OutgoingPaymentMessage outgoingPaymentMessage = new OutgoingPaymentMessage(uuid, payment.getAmount().requireMobileCoin(), payment.getFee().requireMobileCoin(), ByteString.copyFrom(receipt), payment.getBlockIndex(), payment.getTimestamp(), defrag ? Optional.absent() : Optional.of(payment.getPayee().requirePublicAddress().serialize()), defrag ? Optional.absent() : Optional.of(payment.getNote()), txoIdentification.getPublicKeyList(), txoIdentification.getKeyImagesList());
    ApplicationDependencies.getSignalServiceMessageSender().sendSyncMessage(SignalServiceSyncMessage.forOutgoingPayment(outgoingPaymentMessage), UnidentifiedAccessUtil.getAccessForSync(context));
}
Also used : PaymentMetaData(org.thoughtcrime.securesms.payments.proto.PaymentMetaData) OutgoingPaymentMessage(org.whispersystems.signalservice.api.messages.multidevice.OutgoingPaymentMessage) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) PaymentDatabase(org.thoughtcrime.securesms.database.PaymentDatabase)

Example 7 with NotPushRegisteredException

use of org.thoughtcrime.securesms.net.NotPushRegisteredException in project Signal-Android by signalapp.

the class MultiDeviceReadUpdateJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Not multi device...");
        return;
    }
    List<ReadMessage> readMessages = new LinkedList<>();
    for (SerializableSyncMessageId messageId : messageIds) {
        Recipient recipient = Recipient.resolved(RecipientId.from(messageId.recipientId));
        if (!recipient.isGroup() && recipient.isMaybeRegistered()) {
            readMessages.add(new ReadMessage(RecipientUtil.toSignalServiceAddress(context, recipient), messageId.timestamp));
        }
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    messageSender.sendSyncMessage(SignalServiceSyncMessage.forRead(readMessages), UnidentifiedAccessUtil.getAccessForSync(context));
}
Also used : ReadMessage(org.whispersystems.signalservice.api.messages.multidevice.ReadMessage) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LinkedList(java.util.LinkedList)

Example 8 with NotPushRegisteredException

use of org.thoughtcrime.securesms.net.NotPushRegisteredException in project Signal-Android by signalapp.

the class MultiDeviceBlockedUpdateJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Not multi device, aborting...");
        return;
    }
    RecipientDatabase database = SignalDatabase.recipients();
    try (RecipientReader reader = database.readerForBlocked(database.getBlocked())) {
        List<SignalServiceAddress> blockedIndividuals = new LinkedList<>();
        List<byte[]> blockedGroups = new LinkedList<>();
        Recipient recipient;
        while ((recipient = reader.getNext()) != null) {
            if (recipient.isPushGroup()) {
                blockedGroups.add(recipient.requireGroupId().getDecodedId());
            } else if (recipient.isMaybeRegistered() && (recipient.hasServiceId() || recipient.hasE164())) {
                blockedIndividuals.add(RecipientUtil.toSignalServiceAddress(context, recipient));
            }
        }
        SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
        messageSender.sendSyncMessage(SignalServiceSyncMessage.forBlocked(new BlockedListMessage(blockedIndividuals, blockedGroups)), UnidentifiedAccessUtil.getAccessForSync(context));
    }
}
Also used : RecipientReader(org.thoughtcrime.securesms.database.RecipientDatabase.RecipientReader) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) BlockedListMessage(org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage) LinkedList(java.util.LinkedList)

Example 9 with NotPushRegisteredException

use of org.thoughtcrime.securesms.net.NotPushRegisteredException in project Signal-Android by signalapp.

the class AttachmentUploadJob method onRun.

@Override
public void onRun() throws Exception {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    Data inputData = getInputData();
    ResumableUploadSpec resumableUploadSpec;
    if (forceV2) {
        Log.d(TAG, "Forcing utilization of V2");
        resumableUploadSpec = null;
    } else if (inputData != null && inputData.hasString(ResumableUploadSpecJob.KEY_RESUME_SPEC)) {
        Log.d(TAG, "Using attachments V3");
        resumableUploadSpec = ResumableUploadSpec.deserialize(inputData.getString(ResumableUploadSpecJob.KEY_RESUME_SPEC));
    } else {
        Log.d(TAG, "Using attachments V2");
        resumableUploadSpec = null;
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    AttachmentDatabase database = SignalDatabase.attachments();
    DatabaseAttachment databaseAttachment = database.getAttachment(attachmentId);
    if (databaseAttachment == null) {
        throw new InvalidAttachmentException("Cannot find the specified attachment.");
    }
    long timeSinceUpload = System.currentTimeMillis() - databaseAttachment.getUploadTimestamp();
    if (timeSinceUpload < UPLOAD_REUSE_THRESHOLD && !TextUtils.isEmpty(databaseAttachment.getLocation())) {
        Log.i(TAG, "We can re-use an already-uploaded file. It was uploaded " + timeSinceUpload + " ms ago. Skipping.");
        return;
    } else if (databaseAttachment.getUploadTimestamp() > 0) {
        Log.i(TAG, "This file was previously-uploaded, but too long ago to be re-used. Age: " + timeSinceUpload + " ms");
    }
    Log.i(TAG, "Uploading attachment for message " + databaseAttachment.getMmsId() + " with ID " + databaseAttachment.getAttachmentId());
    try (NotificationController notification = getNotificationForAttachment(databaseAttachment)) {
        SignalServiceAttachment localAttachment = getAttachmentFor(databaseAttachment, notification, resumableUploadSpec);
        SignalServiceAttachmentPointer remoteAttachment = messageSender.uploadAttachment(localAttachment.asStream());
        Attachment attachment = PointerAttachment.forPointer(Optional.of(remoteAttachment), null, databaseAttachment.getFastPreflightId()).get();
        database.updateAttachmentAfterUpload(databaseAttachment.getAttachmentId(), attachment, remoteAttachment.getUploadTimestamp());
    } catch (NonSuccessfulResumableUploadResponseCodeException e) {
        if (e.getCode() == 400) {
            Log.w(TAG, "Failed to upload due to a 400 when getting resumable upload information. Downgrading to attachments v2", e);
            forceV2 = true;
        }
    }
}
Also used : NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) Data(org.thoughtcrime.securesms.jobmanager.Data) PointerAttachment(org.thoughtcrime.securesms.attachments.PointerAttachment) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) NonSuccessfulResumableUploadResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResumableUploadResponseCodeException) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) ResumableUploadSpec(org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec) NotificationController(org.thoughtcrime.securesms.service.NotificationController)

Example 10 with NotPushRegisteredException

use of org.thoughtcrime.securesms.net.NotPushRegisteredException in project Signal-Android by signalapp.

the class TypingSendJob method onRun.

@Override
public void onRun() throws Exception {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isTypingIndicatorsEnabled(context)) {
        return;
    }
    Log.d(TAG, "Sending typing " + (typing ? "started" : "stopped") + " for thread " + threadId);
    Recipient recipient = SignalDatabase.threads().getRecipientForThreadId(threadId);
    if (recipient == null) {
        Log.w(TAG, "Tried to send a typing indicator to a non-existent thread.");
        return;
    }
    if (recipient.isBlocked()) {
        Log.w(TAG, "Not sending typing indicators to blocked recipients.");
        return;
    }
    if (recipient.isSelf()) {
        Log.w(TAG, "Not sending typing indicators to self.");
        return;
    }
    if (recipient.isPushV1Group() || recipient.isMmsGroup()) {
        Log.w(TAG, "Not sending typing indicators to unsupported groups.");
        return;
    }
    if (!recipient.isRegistered() || recipient.isForceSmsSelection()) {
        Log.w(TAG, "Not sending typing indicators to non-Signal recipients.");
        return;
    }
    List<Recipient> recipients = Collections.singletonList(recipient);
    Optional<byte[]> groupId = Optional.absent();
    if (recipient.isGroup()) {
        recipients = SignalDatabase.groups().getGroupMembers(recipient.requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
        groupId = Optional.of(recipient.requireGroupId().getDecodedId());
    }
    recipients = RecipientUtil.getEligibleForSending(Stream.of(recipients).map(Recipient::resolve).filter(r -> !r.isBlocked()).toList());
    SignalServiceTypingMessage typingMessage = new SignalServiceTypingMessage(typing ? Action.STARTED : Action.STOPPED, System.currentTimeMillis(), groupId);
    try {
        GroupSendUtil.sendTypingMessage(context, recipient.getGroupId().transform(GroupId::requireV2).orNull(), recipients, typingMessage, this::isCanceled);
    } catch (CancelationException e) {
        Log.w(TAG, "Canceled during send!");
    }
}
Also used : SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) SignalServiceTypingMessage(org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) RecipientUtil(org.thoughtcrime.securesms.recipients.RecipientUtil) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) Optional(org.whispersystems.libsignal.util.guava.Optional) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) List(java.util.List) GroupId(org.thoughtcrime.securesms.groups.GroupId) Job(org.thoughtcrime.securesms.jobmanager.Job) Action(org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage.Action) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupSendUtil(org.thoughtcrime.securesms.messages.GroupSendUtil) Collections(java.util.Collections) CancelationException(org.whispersystems.signalservice.api.CancelationException) SignalServiceTypingMessage(org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage) CancelationException(org.whispersystems.signalservice.api.CancelationException) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Aggregations

NotPushRegisteredException (org.thoughtcrime.securesms.net.NotPushRegisteredException)58 Recipient (org.thoughtcrime.securesms.recipients.Recipient)38 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)38 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)18 LinkedList (java.util.LinkedList)12 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)12 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)8 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)7 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)6 PaymentDatabase (org.thoughtcrime.securesms.database.PaymentDatabase)6 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)6 SignalServiceReceiptMessage (org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage)6 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)4 GroupId (org.thoughtcrime.securesms.groups.GroupId)4 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)4 Data (org.thoughtcrime.securesms.jobmanager.Data)3 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)3 SignalServiceSyncMessage (org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage)3 Uri (android.net.Uri)2 ParcelFileDescriptor (android.os.ParcelFileDescriptor)2