Search in sources :

Example 41 with NotPushRegisteredException

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

the class RemoteDeleteSendJob method onRun.

@Override
protected void onRun() throws Exception {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    MessageDatabase db;
    MessageRecord message;
    if (isMms) {
        db = SignalDatabase.mms();
        message = SignalDatabase.mms().getMessageRecord(messageId);
    } else {
        db = SignalDatabase.sms();
        message = SignalDatabase.sms().getSmsMessage(messageId);
    }
    long targetSentTimestamp = message.getDateSent();
    Recipient conversationRecipient = SignalDatabase.threads().getRecipientForThreadId(message.getThreadId());
    if (conversationRecipient == null) {
        throw new AssertionError("We have a message, but couldn't find the thread!");
    }
    if (!message.isOutgoing()) {
        throw new IllegalStateException("Cannot delete a message that isn't yours!");
    }
    List<Recipient> destinations = Stream.of(recipients).map(Recipient::resolved).toList();
    List<Recipient> completions = deliver(conversationRecipient, destinations, targetSentTimestamp);
    for (Recipient completion : completions) {
        recipients.remove(completion.getId());
    }
    Log.i(TAG, "Completed now: " + completions.size() + ", Remaining: " + recipients.size());
    if (recipients.isEmpty()) {
        db.markAsSent(messageId, true);
    } else {
        Log.w(TAG, "Still need to send to " + recipients.size() + " recipients. Retrying.");
        throw new RetryLaterException();
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException)

Example 42 with NotPushRegisteredException

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

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)

Example 43 with NotPushRegisteredException

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

the class SendDeliveryReceiptJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException, UndeliverableMessageException {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
    Recipient recipient = Recipient.resolved(recipientId);
    if (recipient.isSelf()) {
        Log.i(TAG, "Not sending to self, abort");
        return;
    }
    if (recipient.isUnregistered()) {
        Log.w(TAG, recipient.getId() + " is unregistered!");
        return;
    }
    SignalServiceAddress remoteAddress = RecipientUtil.toSignalServiceAddress(context, recipient);
    SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY, Collections.singletonList(messageSentTimestamp), timestamp);
    SendMessageResult result = messageSender.sendReceipt(remoteAddress, UnidentifiedAccessUtil.getAccessFor(context, recipient), receiptMessage);
    if (messageId != null) {
        SignalDatabase.messageLog().insertIfPossible(recipientId, timestamp, result, ContentHint.IMPLICIT, messageId);
    }
}
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 44 with NotPushRegisteredException

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

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

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

the class ReactionSendJob method onRun.

@Override
protected void onRun() throws Exception {
    if (!Recipient.self().isRegistered()) {
        throw new NotPushRegisteredException();
    }
    ReactionDatabase reactionDatabase = SignalDatabase.reactions();
    MessageRecord message;
    if (messageId.isMms()) {
        message = SignalDatabase.mms().getMessageRecord(messageId.getId());
    } else {
        message = SignalDatabase.sms().getSmsMessage(messageId.getId());
    }
    Recipient targetAuthor = message.isOutgoing() ? Recipient.self() : message.getIndividualRecipient();
    long targetSentTimestamp = message.getDateSent();
    if (targetAuthor.getId().equals(SignalStore.releaseChannelValues().getReleaseChannelRecipientId())) {
        return;
    }
    if (!remove && !reactionDatabase.hasReaction(messageId, reaction)) {
        Log.w(TAG, "Went to add a reaction, but it's no longer present on the message!");
        return;
    }
    if (remove && reactionDatabase.hasReaction(messageId, reaction)) {
        Log.w(TAG, "Went to remove a reaction, but it's still there!");
        return;
    }
    Recipient conversationRecipient = SignalDatabase.threads().getRecipientForThreadId(message.getThreadId());
    if (conversationRecipient == null) {
        throw new AssertionError("We have a message, but couldn't find the thread!");
    }
    if (conversationRecipient.isPushV1Group() || conversationRecipient.isMmsGroup()) {
        Log.w(TAG, "Cannot send reactions to legacy groups.");
        return;
    }
    List<Recipient> resolved = recipients.stream().map(Recipient::resolved).collect(Collectors.toList());
    List<RecipientId> unregistered = resolved.stream().filter(Recipient::isUnregistered).map(Recipient::getId).collect(Collectors.toList());
    List<Recipient> destinations = resolved.stream().filter(Recipient::isMaybeRegistered).collect(Collectors.toList());
    List<Recipient> completions = deliver(conversationRecipient, destinations, targetAuthor, targetSentTimestamp);
    recipients.removeAll(unregistered);
    recipients.removeAll(completions.stream().map(Recipient::getId).collect(Collectors.toList()));
    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 : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) NotPushRegisteredException(org.thoughtcrime.securesms.net.NotPushRegisteredException) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) ReactionDatabase(org.thoughtcrime.securesms.database.ReactionDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException)

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