Search in sources :

Example 1 with UriAttachment

use of org.thoughtcrime.securesms.attachments.UriAttachment in project Signal-Android by WhisperSystems.

the class MmsDownloadJob method storeRetrievedMms.

private void storeRetrievedMms(MasterSecret masterSecret, String contentLocation, long messageId, long threadId, RetrieveConf retrieved, int subscriptionId) throws MmsException, NoSessionException, DuplicateMessageException, InvalidMessageException, LegacyMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    SingleUseBlobProvider provider = SingleUseBlobProvider.getInstance();
    String from = null;
    List<String> to = new LinkedList<>();
    List<String> cc = new LinkedList<>();
    String body = null;
    List<Attachment> attachments = new LinkedList<>();
    if (retrieved.getFrom() != null) {
        from = Util.toIsoString(retrieved.getFrom().getTextString());
    }
    if (retrieved.getTo() != null) {
        for (EncodedStringValue toValue : retrieved.getTo()) {
            to.add(Util.toIsoString(toValue.getTextString()));
        }
    }
    if (retrieved.getCc() != null) {
        for (EncodedStringValue ccValue : retrieved.getCc()) {
            cc.add(Util.toIsoString(ccValue.getTextString()));
        }
    }
    if (retrieved.getBody() != null) {
        body = PartParser.getMessageText(retrieved.getBody());
        PduBody media = PartParser.getSupportedMediaParts(retrieved.getBody());
        for (int i = 0; i < media.getPartsNum(); i++) {
            PduPart part = media.getPart(i);
            if (part.getData() != null) {
                Uri uri = provider.createUri(part.getData());
                attachments.add(new UriAttachment(uri, Util.toIsoString(part.getContentType()), AttachmentDatabase.TRANSFER_PROGRESS_DONE, part.getData().length));
            }
        }
    }
    IncomingMediaMessage message = new IncomingMediaMessage(from, to, cc, body, retrieved.getDate() * 1000L, attachments, subscriptionId, 0, false);
    Optional<InsertResult> insertResult = database.insertMessageInbox(new MasterSecretUnion(masterSecret), message, contentLocation, threadId);
    if (insertResult.isPresent()) {
        database.delete(messageId);
        MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) EncodedStringValue(ws.com.google.android.mms.pdu.EncodedStringValue) MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) PduBody(ws.com.google.android.mms.pdu.PduBody) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) Uri(android.net.Uri) LinkedList(java.util.LinkedList) SingleUseBlobProvider(org.thoughtcrime.securesms.providers.SingleUseBlobProvider) PduPart(ws.com.google.android.mms.pdu.PduPart) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 2 with UriAttachment

use of org.thoughtcrime.securesms.attachments.UriAttachment in project Signal-Android by WhisperSystems.

the class GroupManager method sendGroupUpdate.

private static GroupActionResult sendGroupUpdate(@NonNull Context context, @NonNull MasterSecret masterSecret, @NonNull byte[] groupId, @NonNull Set<String> e164numbers, @Nullable String groupName, @Nullable byte[] avatar) {
    Attachment avatarAttachment = null;
    String groupRecipientId = GroupUtil.getEncodedId(groupId);
    Recipients groupRecipient = RecipientFactory.getRecipientsFromString(context, groupRecipientId, false);
    GroupContext.Builder groupContextBuilder = GroupContext.newBuilder().setId(ByteString.copyFrom(groupId)).setType(GroupContext.Type.UPDATE).addAllMembers(e164numbers);
    if (groupName != null)
        groupContextBuilder.setName(groupName);
    GroupContext groupContext = groupContextBuilder.build();
    if (avatar != null) {
        Uri avatarUri = SingleUseBlobProvider.getInstance().createUri(avatar);
        avatarAttachment = new UriAttachment(avatarUri, ContentType.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length);
    }
    OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(groupRecipient, groupContext, avatarAttachment, System.currentTimeMillis(), 0);
    long threadId = MessageSender.send(context, masterSecret, outgoingMessage, -1, false);
    return new GroupActionResult(groupRecipient, threadId);
}
Also used : OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) ByteString(com.google.protobuf.ByteString) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) Uri(android.net.Uri) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Aggregations

Uri (android.net.Uri)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)2 ByteString (com.google.protobuf.ByteString)1 LinkedList (java.util.LinkedList)1 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)1 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 IncomingMediaMessage (org.thoughtcrime.securesms.mms.IncomingMediaMessage)1 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)1 SingleUseBlobProvider (org.thoughtcrime.securesms.providers.SingleUseBlobProvider)1 Recipients (org.thoughtcrime.securesms.recipients.Recipients)1 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)1 EncodedStringValue (ws.com.google.android.mms.pdu.EncodedStringValue)1 PduBody (ws.com.google.android.mms.pdu.PduBody)1 PduPart (ws.com.google.android.mms.pdu.PduPart)1