Search in sources :

Example 1 with NotPushRegisteredException

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

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 2 with NotPushRegisteredException

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

the class GroupCallUpdateSendJob method onRun.

@Override
protected void onRun() throws Exception {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    Recipient conversationRecipient = Recipient.resolved(recipientId);
    if (!conversationRecipient.isPushV2Group()) {
        throw new AssertionError("We have a recipient, but it's not a V2 Group");
    }
    List<Recipient> destinations = Stream.of(recipients).map(Recipient::resolved).toList();
    List<Recipient> completions = deliver(conversationRecipient, destinations);
    for (Recipient completion : completions) {
        recipients.remove(completion.getId());
    }
    Log.i(TAG, "Completed now: " + completions.size() + ", Remaining: " + recipients.size());
    if (!recipients.isEmpty()) {
        Log.w(TAG, "Still need to send to " + recipients.size() + " recipients. Retrying.");
        throw new RetryLaterException();
    }
}
Also used : NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException)

Example 3 with NotPushRegisteredException

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

the class SendReadReceiptJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException, UndeliverableMessageException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isReadReceiptsEnabled(context) || messageSentTimestamps.isEmpty())
        return;
    if (!RecipientUtil.isMessageRequestAccepted(context, threadId)) {
        Log.w(TAG, "Refusing to send receipts to untrusted recipient");
        return;
    }
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isSelf()) {
        Log.i(TAG, "Not sending to self, aborting.");
    }
    if (recipient.isBlocked()) {
        Log.w(TAG, "Refusing to send receipts to blocked recipient");
        return;
    }
    if (recipient.isGroup()) {
        Log.w(TAG, "Refusing to send receipts to group");
        return;
    }
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " not registered!");
        return;
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    SignalServiceAddress remoteAddress = RecipientUtil.toSignalServiceAddress(context, recipient);
    SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.READ, messageSentTimestamps, timestamp);
    SendMessageResult result = messageSender.sendReceipt(remoteAddress, UnidentifiedAccessUtil.getAccessFor(context, Recipient.resolved(recipientId)), receiptMessage);
    if (Util.hasItems(messageIds)) {
        SignalDatabase.messageLog().insertIfPossible(recipientId, timestamp, result, ContentHint.IMPLICIT, messageIds);
    }
}
Also used : NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult)

Example 4 with NotPushRegisteredException

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

the class SendViewedReceiptJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
        Log.w(TAG, "Read receipts not enabled!");
        return;
    }
    if (messageSentTimestamps.isEmpty()) {
        Log.w(TAG, "No sync timestamps!");
        return;
    }
    if (!RecipientUtil.isMessageRequestAccepted(context, threadId)) {
        Log.w(TAG, "Refusing to send receipts to untrusted recipient");
        return;
    }
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isSelf()) {
        Log.i(TAG, "Not sending view receipt to self.");
        return;
    }
    if (recipient.isBlocked()) {
        Log.w(TAG, "Refusing to send receipts to blocked recipient");
        return;
    }
    if (recipient.isGroup()) {
        Log.w(TAG, "Refusing to send receipts to group");
        return;
    }
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " not registered!");
        return;
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    SignalServiceAddress remoteAddress = RecipientUtil.toSignalServiceAddress(context, recipient);
    SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.VIEWED, messageSentTimestamps, timestamp);
    SendMessageResult result = messageSender.sendReceipt(remoteAddress, UnidentifiedAccessUtil.getAccessFor(context, Recipient.resolved(recipientId)), receiptMessage);
    if (Util.hasItems(messageIds)) {
        SignalDatabase.messageLog().insertIfPossible(recipientId, timestamp, result, ContentHint.IMPLICIT, messageIds);
    }
}
Also used : NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceReceiptMessage(org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SendMessageResult(org.whispersystems.signalservice.api.messages.SendMessageResult)

Example 5 with NotPushRegisteredException

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

the class RequestGroupInfoJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    SignalServiceGroup group = SignalServiceGroup.newBuilder(Type.REQUEST_INFO).withId(groupId.getDecodedId()).build();
    SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder().asGroupMessage(group).withTimestamp(System.currentTimeMillis()).build();
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    Recipient recipient = Recipient.resolved(source);
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " is unregistered!");
        return;
    }
    messageSender.sendDataMessage(RecipientUtil.toSignalServiceAddress(context, recipient), UnidentifiedAccessUtil.getAccessFor(context, recipient), ContentHint.IMPLICIT, message, IndividualSendEvents.EMPTY);
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup)

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