Search in sources :

Example 1 with SignalServiceAttachment

use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment in project Signal-Android by WhisperSystems.

the class GroupMessageProcessor method handleGroupUpdate.

@Nullable
private static Long handleGroupUpdate(@NonNull Context context, @NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, @NonNull GroupRecord groupRecord, boolean outgoing) {
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    byte[] id = group.getGroupId();
    Set<String> recordMembers = new HashSet<>(groupRecord.getMembers());
    Set<String> messageMembers = new HashSet<>(group.getMembers().get());
    Set<String> addedMembers = new HashSet<>(messageMembers);
    addedMembers.removeAll(recordMembers);
    Set<String> missingMembers = new HashSet<>(recordMembers);
    missingMembers.removeAll(messageMembers);
    GroupContext.Builder builder = createGroupContext(group);
    builder.setType(GroupContext.Type.UPDATE);
    if (addedMembers.size() > 0) {
        Set<String> unionMembers = new HashSet<>(recordMembers);
        unionMembers.addAll(messageMembers);
        database.updateMembers(id, new LinkedList<>(unionMembers));
        builder.clearMembers().addAllMembers(addedMembers);
    } else {
        builder.clearMembers();
    }
    if (missingMembers.size() > 0) {
    // TODO We should tell added and missing about each-other.
    }
    if (group.getName().isPresent() || group.getAvatar().isPresent()) {
        SignalServiceAttachment avatar = group.getAvatar().orNull();
        database.update(id, group.getName().orNull(), avatar != null ? avatar.asPointer() : null);
    }
    if (group.getName().isPresent() && group.getName().get().equals(groupRecord.getTitle())) {
        builder.clearName();
    }
    if (!groupRecord.isActive())
        database.setActive(id, true);
    return storeMessage(context, masterSecret, envelope, group, builder.build(), outgoing);
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ByteString(com.google.protobuf.ByteString) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) HashSet(java.util.HashSet) Nullable(android.support.annotation.Nullable)

Example 2 with SignalServiceAttachment

use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment 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);
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Example 3 with SignalServiceAttachment

use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment 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;
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) ProgressListener(org.whispersystems.signalservice.api.messages.SignalServiceAttachment.ProgressListener) InputStream(java.io.InputStream) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) PartProgressEvent(org.thoughtcrime.securesms.events.PartProgressEvent) IOException(java.io.IOException) LinkedList(java.util.LinkedList)

Example 4 with SignalServiceAttachment

use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment in project Signal-Android by WhisperSystems.

the class PointerAttachment method forPointers.

public static List<Attachment> forPointers(@NonNull MasterSecretUnion masterSecret, Optional<List<SignalServiceAttachment>> pointers) {
    List<Attachment> results = new LinkedList<>();
    if (pointers.isPresent()) {
        for (SignalServiceAttachment pointer : pointers.get()) {
            if (pointer.isPointer()) {
                String encryptedKey = MediaKey.getEncrypted(masterSecret, pointer.asPointer().getKey());
                results.add(new PointerAttachment(pointer.getContentType(), AttachmentDatabase.TRANSFER_PROGRESS_AUTO_PENDING, pointer.asPointer().getSize().or(0), String.valueOf(pointer.asPointer().getId()), encryptedKey, pointer.asPointer().getRelay().orNull(), pointer.asPointer().getDigest().orNull()));
            }
        }
    }
    return results;
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) LinkedList(java.util.LinkedList)

Example 5 with SignalServiceAttachment

use of org.whispersystems.signalservice.api.messages.SignalServiceAttachment in project Signal-Android by WhisperSystems.

the class PushGroupUpdateJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
    GroupRecord record = groupDatabase.getGroup(groupId);
    SignalServiceAttachment avatar = null;
    if (record == null) {
        Log.w(TAG, "No information for group record info request: " + new String(groupId));
        return;
    }
    if (record.getAvatar() != null) {
        avatar = SignalServiceAttachmentStream.newStreamBuilder().withContentType("image/jpeg").withStream(new ByteArrayInputStream(record.getAvatar())).withLength(record.getAvatar().length).build();
    }
    SignalServiceGroup groupContext = SignalServiceGroup.newBuilder(Type.UPDATE).withAvatar(avatar).withId(groupId).withMembers(record.getMembers()).withName(record.getTitle()).build();
    SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder().asGroupMessage(groupContext).withTimestamp(System.currentTimeMillis()).build();
    messageSender.sendMessage(new SignalServiceAddress(source), message);
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup)

Aggregations

SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)8 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)3 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)3 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)3 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)3 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)3 Nullable (android.support.annotation.Nullable)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)2 ByteString (com.google.protobuf.ByteString)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 GroupRecord (org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 PartProgressEvent (org.thoughtcrime.securesms.events.PartProgressEvent)1