Search in sources :

Example 1 with SingleUseBlobProvider

use of org.thoughtcrime.securesms.providers.SingleUseBlobProvider in project Signal-Android by signalapp.

the class MmsDownloadJob method storeRetrievedMms.

private void storeRetrievedMms(String contentLocation, long messageId, long threadId, RetrieveConf retrieved, int subscriptionId, @Nullable Address notificationFrom) throws MmsException, NoSessionException, DuplicateMessageException, InvalidMessageException, LegacyMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    SingleUseBlobProvider provider = SingleUseBlobProvider.getInstance();
    Optional<Address> group = Optional.absent();
    Set<Address> members = new HashSet<>();
    String body = null;
    List<Attachment> attachments = new LinkedList<>();
    Address from;
    if (retrieved.getFrom() != null) {
        from = Address.fromExternal(context, Util.toIsoString(retrieved.getFrom().getTextString()));
    } else if (notificationFrom != null) {
        from = notificationFrom;
    } else {
        from = Address.UNKNOWN;
    }
    if (retrieved.getTo() != null) {
        for (EncodedStringValue toValue : retrieved.getTo()) {
            members.add(Address.fromExternal(context, Util.toIsoString(toValue.getTextString())));
        }
    }
    if (retrieved.getCc() != null) {
        for (EncodedStringValue ccValue : retrieved.getCc()) {
            members.add(Address.fromExternal(context, Util.toIsoString(ccValue.getTextString())));
        }
    }
    members.add(from);
    members.add(Address.fromExternal(context, TextSecurePreferences.getLocalNumber(context)));
    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());
                String name = null;
                if (part.getName() != null)
                    name = Util.toIsoString(part.getName());
                attachments.add(new UriAttachment(uri, Util.toIsoString(part.getContentType()), AttachmentDatabase.TRANSFER_PROGRESS_DONE, part.getData().length, name, false));
            }
        }
    }
    if (members.size() > 2) {
        group = Optional.of(Address.fromSerialized(DatabaseFactory.getGroupDatabase(context).getOrCreateGroupForMembers(new LinkedList<>(members), true)));
    }
    IncomingMediaMessage message = new IncomingMediaMessage(from, group, body, retrieved.getDate() * 1000L, attachments, subscriptionId, 0, false);
    Optional<InsertResult> insertResult = database.insertMessageInbox(message, contentLocation, threadId);
    if (insertResult.isPresent()) {
        database.delete(messageId);
        MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) EncodedStringValue(com.google.android.mms.pdu_alt.EncodedStringValue) Address(org.thoughtcrime.securesms.database.Address) PduBody(com.google.android.mms.pdu_alt.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(com.google.android.mms.pdu_alt.PduPart) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) HashSet(java.util.HashSet)

Example 2 with SingleUseBlobProvider

use of org.thoughtcrime.securesms.providers.SingleUseBlobProvider 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)

Aggregations

Uri (android.net.Uri)2 LinkedList (java.util.LinkedList)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)2 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)2 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)2 IncomingMediaMessage (org.thoughtcrime.securesms.mms.IncomingMediaMessage)2 SingleUseBlobProvider (org.thoughtcrime.securesms.providers.SingleUseBlobProvider)2 EncodedStringValue (com.google.android.mms.pdu_alt.EncodedStringValue)1 PduBody (com.google.android.mms.pdu_alt.PduBody)1 PduPart (com.google.android.mms.pdu_alt.PduPart)1 HashSet (java.util.HashSet)1 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)1 Address (org.thoughtcrime.securesms.database.Address)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