use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.
the class SendRetryReceiptJob method onRun.
@Override
protected void onRun() throws Exception {
Recipient recipient = Recipient.resolved(recipientId);
if (recipient.isUnregistered()) {
Log.w(TAG, recipient.getId() + " not registered!");
return;
}
SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, recipient);
Optional<UnidentifiedAccessPair> access = UnidentifiedAccessUtil.getAccessFor(context, recipient);
Optional<byte[]> group = groupId.transform(GroupId::getDecodedId);
Log.i(TAG, "Sending retry receipt for " + errorMessage.getTimestamp() + " to " + recipientId + ", device: " + errorMessage.getDeviceId());
ApplicationDependencies.getSignalServiceMessageSender().sendRetryReceipt(address, access, group, errorMessage);
}
use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.
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.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.
the class PaymentNotificationSendJob method onRun.
@Override
protected void onRun() throws Exception {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
PaymentDatabase paymentDatabase = SignalDatabase.payments();
Recipient recipient = Recipient.resolved(recipientId);
if (recipient.isUnregistered()) {
Log.w(TAG, recipientId + " not registered!");
return;
}
SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, recipient);
Optional<UnidentifiedAccessPair> unidentifiedAccess = UnidentifiedAccessUtil.getAccessFor(context, recipient);
PaymentDatabase.PaymentTransaction payment = paymentDatabase.getPayment(uuid);
if (payment == null) {
Log.w(TAG, "Could not find payment, cannot send notification " + uuid);
return;
}
if (payment.getReceipt() == null) {
Log.w(TAG, "Could not find payment receipt, cannot send notification " + uuid);
return;
}
SignalServiceDataMessage dataMessage = SignalServiceDataMessage.newBuilder().withPayment(new SignalServiceDataMessage.Payment(new SignalServiceDataMessage.PaymentNotification(payment.getReceipt(), payment.getNote()))).build();
SendMessageResult sendMessageResult = messageSender.sendDataMessage(address, unidentifiedAccess, ContentHint.DEFAULT, dataMessage, IndividualSendEvents.EMPTY);
if (sendMessageResult.getIdentityFailure() != null) {
Log.w(TAG, "Identity failure for " + recipient.getId());
} else if (sendMessageResult.isUnregisteredFailure()) {
Log.w(TAG, "Unregistered failure for " + recipient.getId());
} else if (sendMessageResult.getSuccess() == null) {
throw new RetryLaterException();
} else {
Log.i(TAG, String.format("Payment notification sent to %s for %s", recipientId, uuid));
}
}
use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.
the class SignalServiceMessageSender method buildGroupTargetInfo.
private GroupTargetInfo buildGroupTargetInfo(List<SignalServiceAddress> recipients) {
List<String> addressNames = recipients.stream().map(SignalServiceAddress::getIdentifier).collect(Collectors.toList());
Set<SignalProtocolAddress> destinations = store.getAllAddressesWithActiveSessions(addressNames);
Map<String, List<Integer>> devicesByAddressName = new HashMap<>();
destinations.addAll(recipients.stream().map(a -> new SignalProtocolAddress(a.getIdentifier(), SignalServiceAddress.DEFAULT_DEVICE_ID)).collect(Collectors.toList()));
for (SignalProtocolAddress destination : destinations) {
List<Integer> devices = devicesByAddressName.containsKey(destination.getName()) ? devicesByAddressName.get(destination.getName()) : new LinkedList<>();
devices.add(destination.getDeviceId());
devicesByAddressName.put(destination.getName(), devices);
}
Map<SignalServiceAddress, List<Integer>> recipientDevices = new HashMap<>();
for (SignalServiceAddress recipient : recipients) {
if (devicesByAddressName.containsKey(recipient.getIdentifier())) {
recipientDevices.put(recipient, devicesByAddressName.get(recipient.getIdentifier()));
}
}
return new GroupTargetInfo(new ArrayList<>(destinations), recipientDevices);
}
use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by WhisperSystems.
the class SignalServiceMessageSender method sendDataMessage.
/**
* Sends a message to a group using client-side fanout.
*
* @param partialListener A listener that will be called when an individual send is completed. Will be invoked on an arbitrary background thread, *not*
* the calling thread.
*/
public List<SendMessageResult> sendDataMessage(List<SignalServiceAddress> recipients, List<Optional<UnidentifiedAccessPair>> unidentifiedAccess, boolean isRecipientUpdate, ContentHint contentHint, SignalServiceDataMessage message, LegacyGroupEvents sendEvents, PartialSendCompleteListener partialListener, CancelationSignal cancelationSignal) throws IOException, UntrustedIdentityException {
Log.d(TAG, "[" + message.getTimestamp() + "] Sending a data message to " + recipients.size() + " recipients.");
Content content = createMessageContent(message);
EnvelopeContent envelopeContent = EnvelopeContent.encrypted(content, contentHint, message.getGroupId());
long timestamp = message.getTimestamp();
List<SendMessageResult> results = sendMessage(recipients, getTargetUnidentifiedAccess(unidentifiedAccess), timestamp, envelopeContent, false, partialListener, cancelationSignal);
boolean needsSyncInResults = false;
sendEvents.onMessageSent();
for (SendMessageResult result : results) {
if (result.getSuccess() != null && result.getSuccess().isNeedsSync()) {
needsSyncInResults = true;
break;
}
}
if (needsSyncInResults || store.isMultiDevice()) {
Optional<SignalServiceAddress> recipient = Optional.absent();
if (!message.getGroupContext().isPresent() && recipients.size() == 1) {
recipient = Optional.of(recipients.get(0));
}
Content syncMessage = createMultiDeviceSentTranscriptContent(content, recipient, timestamp, results, isRecipientUpdate);
EnvelopeContent syncMessageContent = EnvelopeContent.encrypted(syncMessage, ContentHint.IMPLICIT, Optional.absent());
sendMessage(localAddress, Optional.absent(), timestamp, syncMessageContent, false, null);
}
sendEvents.onSyncMessageSent();
return results;
}
Aggregations