use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment in project Signal-Android by WhisperSystems.
the class PushMediaSendJob method deliver.
private void deliver(MasterSecret masterSecret, OutgoingMediaMessage message) throws RetryLaterException, InsecureFallbackApprovalException, UntrustedIdentityException, UndeliverableMessageException {
if (message.getRecipients() == null || message.getRecipients().getPrimaryRecipient() == null || message.getRecipients().getPrimaryRecipient().getNumber() == null) {
throw new UndeliverableMessageException("No destination address.");
}
SignalServiceMessageSender messageSender = messageSenderFactory.create();
try {
SignalServiceAddress address = getPushAddress(message.getRecipients().getPrimaryRecipient().getNumber());
List<Attachment> scaledAttachments = scaleAttachments(masterSecret, MediaConstraints.PUSH_CONSTRAINTS, message.getAttachments());
List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(masterSecret, scaledAttachments);
SignalServiceDataMessage mediaMessage = SignalServiceDataMessage.newBuilder().withBody(message.getBody()).withAttachments(attachmentStreams).withTimestamp(message.getSentTimeMillis()).withExpiration((int) (message.getExpiresIn() / 1000)).asExpirationUpdate(message.isExpirationUpdate()).build();
messageSender.sendMessage(address, mediaMessage);
} catch (InvalidNumberException | UnregisteredUserException e) {
Log.w(TAG, e);
throw new InsecureFallbackApprovalException(e);
} catch (FileNotFoundException e) {
Log.w(TAG, e);
throw new UndeliverableMessageException(e);
} catch (IOException e) {
Log.w(TAG, e);
throw new RetryLaterException(e);
}
}
use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment in project Signal-Android by WhisperSystems.
the class GroupMessageProcessor method handleGroupCreate.
@Nullable
private static Long handleGroupCreate(@NonNull Context context, @NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, boolean outgoing) {
GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
byte[] id = group.getGroupId();
GroupContext.Builder builder = createGroupContext(group);
builder.setType(GroupContext.Type.UPDATE);
SignalServiceAttachment avatar = group.getAvatar().orNull();
database.create(id, group.getName().orNull(), group.getMembers().orNull(), avatar != null && avatar.isPointer() ? avatar.asPointer() : null, envelope.getRelay());
return storeMessage(context, masterSecret, envelope, group, builder.build(), outgoing);
}
use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment in project Signal-Android by WhisperSystems.
the class PushDecryptJob method handleExpirationUpdate.
private void handleExpirationUpdate(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
String localNumber = TextSecurePreferences.getLocalNumber(context);
Recipients recipients = getMessageDestination(envelope, message);
IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, envelope.getSource(), localNumber, message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000, true, Optional.fromNullable(envelope.getRelay()), Optional.<String>absent(), message.getGroupInfo(), Optional.<List<SignalServiceAttachment>>absent());
database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1);
DatabaseFactory.getRecipientPreferenceDatabase(context).setExpireMessages(recipients, message.getExpiresInSeconds());
if (smsMessageId.isPresent()) {
DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
}
}
Aggregations