use of org.thoughtcrime.securesms.attachments.Attachment in project Signal-Android by WhisperSystems.
the class AttachmentDatabase method insertAttachmentsForMessage.
void insertAttachmentsForMessage(@NonNull MasterSecretUnion masterSecret, long mmsId, @NonNull List<Attachment> attachments) throws MmsException {
Log.w(TAG, "insertParts(" + attachments.size() + ")");
for (Attachment attachment : attachments) {
AttachmentId attachmentId = insertAttachment(masterSecret, mmsId, attachment);
Log.w(TAG, "Inserted attachment at ID: " + attachmentId);
}
}
use of org.thoughtcrime.securesms.attachments.Attachment in project Signal-Android by WhisperSystems.
the class PushGroupSendJob method deliver.
private void deliver(MasterSecret masterSecret, OutgoingMediaMessage message, long filterRecipientId) throws IOException, RecipientFormattingException, InvalidNumberException, EncapsulatedExceptions, UndeliverableMessageException {
SignalServiceMessageSender messageSender = messageSenderFactory.create();
byte[] groupId = GroupUtil.getDecodedId(message.getRecipients().getPrimaryRecipient().getNumber());
Recipients recipients = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false);
List<Attachment> scaledAttachments = scaleAttachments(masterSecret, MediaConstraints.PUSH_CONSTRAINTS, message.getAttachments());
List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(masterSecret, scaledAttachments);
List<SignalServiceAddress> addresses;
if (filterRecipientId >= 0)
addresses = getPushAddresses(filterRecipientId);
else
addresses = getPushAddresses(recipients);
if (message.isGroup()) {
OutgoingGroupMediaMessage groupMessage = (OutgoingGroupMediaMessage) message;
GroupContext groupContext = groupMessage.getGroupContext();
SignalServiceAttachment avatar = attachmentStreams.isEmpty() ? null : attachmentStreams.get(0);
SignalServiceGroup.Type type = groupMessage.isGroupQuit() ? SignalServiceGroup.Type.QUIT : SignalServiceGroup.Type.UPDATE;
SignalServiceGroup group = new SignalServiceGroup(type, groupId, groupContext.getName(), groupContext.getMembersList(), avatar);
SignalServiceDataMessage groupDataMessage = new SignalServiceDataMessage(message.getSentTimeMillis(), group, null, null);
messageSender.sendMessage(addresses, groupDataMessage);
} else {
SignalServiceGroup group = new SignalServiceGroup(groupId);
SignalServiceDataMessage groupMessage = new SignalServiceDataMessage(message.getSentTimeMillis(), group, attachmentStreams, message.getBody(), false, (int) (message.getExpiresIn() / 1000), message.isExpirationUpdate());
messageSender.sendMessage(addresses, groupMessage);
}
}
use of org.thoughtcrime.securesms.attachments.Attachment in project Signal-Android by WhisperSystems.
the class PushSendJob method getAttachmentsFor.
protected List<SignalServiceAttachment> getAttachmentsFor(MasterSecret masterSecret, List<Attachment> parts) {
List<SignalServiceAttachment> attachments = new LinkedList<>();
for (final Attachment attachment : parts) {
if (ContentType.isImageType(attachment.getContentType()) || ContentType.isAudioType(attachment.getContentType()) || ContentType.isVideoType(attachment.getContentType())) {
try {
if (attachment.getDataUri() == null || attachment.getSize() == 0)
throw new IOException("Assertion failed, outgoing attachment has no data!");
InputStream is = PartAuthority.getAttachmentStream(context, masterSecret, attachment.getDataUri());
attachments.add(SignalServiceAttachment.newStreamBuilder().withStream(is).withContentType(attachment.getContentType()).withLength(attachment.getSize()).withListener(new ProgressListener() {
@Override
public void onAttachmentProgress(long total, long progress) {
EventBus.getDefault().postSticky(new PartProgressEvent(attachment, total, progress));
}
}).build());
} catch (IOException ioe) {
Log.w(TAG, "Couldn't open attachment", ioe);
}
}
}
return attachments;
}
use of org.thoughtcrime.securesms.attachments.Attachment 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.thoughtcrime.securesms.attachments.Attachment in project Signal-Android by WhisperSystems.
the class MediaNetworkRequirement method isPresent.
@Override
public boolean isPresent() {
final AttachmentId attachmentId = new AttachmentId(partRowId, partUniqueId);
final AttachmentDatabase db = DatabaseFactory.getAttachmentDatabase(context);
final Attachment attachment = db.getAttachment(attachmentId);
if (attachment == null) {
Log.w(TAG, "attachment was null, returning vacuous true");
return true;
}
Log.w(TAG, "part transfer progress is " + attachment.getTransferState());
switch(attachment.getTransferState()) {
case AttachmentDatabase.TRANSFER_PROGRESS_STARTED:
return true;
case AttachmentDatabase.TRANSFER_PROGRESS_AUTO_PENDING:
final Set<String> allowedTypes = getAllowedAutoDownloadTypes();
final boolean isAllowed = allowedTypes.contains(MediaUtil.getDiscreteMimeType(attachment.getContentType()));
// *modifying the database* just by calling isPresent().
if (isAllowed)
db.setTransferState(messageId, attachmentId, AttachmentDatabase.TRANSFER_PROGRESS_STARTED);
return isAllowed;
default:
return false;
}
}
Aggregations