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();
}
}
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);
}
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);
}
}
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);
}
}
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();
}
}
Aggregations