Search in sources :

Example 21 with SignalServiceAttachmentPointer

use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer in project libsignal-service-java by signalapp.

the class SignalServiceCipher method createGroupInfo.

private SignalServiceGroup createGroupInfo(DataMessage content) throws ProtocolInvalidMessageException {
    if (!content.hasGroup())
        return null;
    SignalServiceGroup.Type type;
    switch(content.getGroup().getType()) {
        case DELIVER:
            type = SignalServiceGroup.Type.DELIVER;
            break;
        case UPDATE:
            type = SignalServiceGroup.Type.UPDATE;
            break;
        case QUIT:
            type = SignalServiceGroup.Type.QUIT;
            break;
        case REQUEST_INFO:
            type = SignalServiceGroup.Type.REQUEST_INFO;
            break;
        default:
            type = SignalServiceGroup.Type.UNKNOWN;
            break;
    }
    if (content.getGroup().getType() != DELIVER) {
        String name = null;
        List<SignalServiceAddress> members = null;
        SignalServiceAttachmentPointer avatar = null;
        if (content.getGroup().hasName()) {
            name = content.getGroup().getName();
        }
        if (content.getGroup().getMembersCount() > 0) {
            members = new ArrayList<>(content.getGroup().getMembersCount());
            for (SignalServiceProtos.GroupContext.Member member : content.getGroup().getMembersList()) {
                if (SignalServiceAddress.isValidAddress(member.getUuid(), member.getE164())) {
                    members.add(new SignalServiceAddress(UuidUtil.parseOrNull(member.getUuid()), member.getE164()));
                } else {
                    throw new ProtocolInvalidMessageException(new InvalidMessageException("GroupContext.Member had no address!"), null, 0);
                }
            }
        } else if (content.getGroup().getMembersE164Count() > 0) {
            members = new ArrayList<>(content.getGroup().getMembersE164Count());
            for (String member : content.getGroup().getMembersE164List()) {
                members.add(new SignalServiceAddress(null, member));
            }
        }
        if (content.getGroup().hasAvatar()) {
            AttachmentPointer pointer = content.getGroup().getAvatar();
            avatar = new SignalServiceAttachmentPointer(pointer.getId(), pointer.getContentType(), pointer.getKey().toByteArray(), Optional.of(pointer.getSize()), Optional.<byte[]>absent(), 0, 0, Optional.fromNullable(pointer.hasDigest() ? pointer.getDigest().toByteArray() : null), Optional.<String>absent(), false, Optional.<String>absent(), Optional.<String>absent());
        }
        return new SignalServiceGroup(type, content.getGroup().getId().toByteArray(), name, members, avatar);
    }
    return new SignalServiceGroup(content.getGroup().getId().toByteArray());
}
Also used : ProtocolInvalidMessageException(org.signal.libsignal.metadata.ProtocolInvalidMessageException) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) ProtocolInvalidMessageException(org.signal.libsignal.metadata.ProtocolInvalidMessageException) ArrayList(java.util.ArrayList) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) ByteString(com.google.protobuf.ByteString) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) AttachmentPointer(org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer)

Example 22 with SignalServiceAttachmentPointer

use of org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer in project Signal-Android by signalapp.

the class PushSendJob method getAttachmentPointerFor.

@Nullable
protected SignalServiceAttachment getAttachmentPointerFor(Attachment attachment) {
    if (TextUtils.isEmpty(attachment.getLocation())) {
        Log.w(TAG, "empty content id");
        return null;
    }
    if (TextUtils.isEmpty(attachment.getKey())) {
        Log.w(TAG, "empty encrypted key");
        return null;
    }
    try {
        final SignalServiceAttachmentRemoteId remoteId = SignalServiceAttachmentRemoteId.from(attachment.getLocation());
        final byte[] key = Base64.decode(attachment.getKey());
        int width = attachment.getWidth();
        int height = attachment.getHeight();
        if ((width == 0 || height == 0) && MediaUtil.hasVideoThumbnail(context, attachment.getUri())) {
            Bitmap thumbnail = MediaUtil.getVideoThumbnail(context, attachment.getUri(), 1000);
            if (thumbnail != null) {
                width = thumbnail.getWidth();
                height = thumbnail.getHeight();
            }
        }
        return new SignalServiceAttachmentPointer(attachment.getCdnNumber(), remoteId, attachment.getContentType(), key, Optional.of(Util.toIntExact(attachment.getSize())), Optional.absent(), width, height, Optional.fromNullable(attachment.getDigest()), Optional.fromNullable(attachment.getFileName()), attachment.isVoiceNote(), attachment.isBorderless(), attachment.isVideoGif(), Optional.fromNullable(attachment.getCaption()), Optional.fromNullable(attachment.getBlurHash()).transform(BlurHash::getHash), attachment.getUploadTimestamp());
    } catch (IOException | ArithmeticException e) {
        Log.w(TAG, e);
        return null;
    }
}
Also used : Bitmap(android.graphics.Bitmap) SignalServiceAttachmentRemoteId(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) IOException(java.io.IOException) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) Nullable(androidx.annotation.Nullable)

Aggregations

SignalServiceAttachmentPointer (org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer)22 IOException (java.io.IOException)10 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)9 File (java.io.File)8 InputStream (java.io.InputStream)8 SignalServiceAttachmentRemoteId (org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId)8 NonSuccessfulResponseCodeException (org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException)7 AttachmentDatabase (org.thoughtcrime.securesms.database.AttachmentDatabase)5 Bitmap (android.graphics.Bitmap)4 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)4 SignalServiceMessageReceiver (org.whispersystems.signalservice.api.SignalServiceMessageReceiver)4 MissingConfigurationException (org.whispersystems.signalservice.api.push.exceptions.MissingConfigurationException)4 GroupRecord (org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord)3 PartProgressEvent (org.thoughtcrime.securesms.events.PartProgressEvent)3 Nullable (androidx.annotation.Nullable)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)2 PointerAttachment (org.thoughtcrime.securesms.attachments.PointerAttachment)2 Data (org.thoughtcrime.securesms.jobmanager.Data)2 NetworkConstraint (org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)2