Search in sources :

Example 1 with SignalServiceGroup

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

the class GroupMessageProcessor method process.

@Nullable
public static Long process(@NonNull Context context, @NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, boolean outgoing) {
    if (!message.getGroupInfo().isPresent() || message.getGroupInfo().get().getGroupId() == null) {
        Log.w(TAG, "Received group message with no id! Ignoring...");
        return null;
    }
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    SignalServiceGroup group = message.getGroupInfo().get();
    byte[] id = group.getGroupId();
    GroupRecord record = database.getGroup(id);
    if (record != null && group.getType() == Type.UPDATE) {
        return handleGroupUpdate(context, masterSecret, envelope, group, record, outgoing);
    } else if (record == null && group.getType() == Type.UPDATE) {
        return handleGroupCreate(context, masterSecret, envelope, group, outgoing);
    } else if (record != null && group.getType() == Type.QUIT) {
        return handleGroupLeave(context, masterSecret, envelope, group, record, outgoing);
    } else if (record != null && group.getType() == Type.REQUEST_INFO) {
        return handleGroupInfoRequest(context, envelope, group, record);
    } else {
        Log.w(TAG, "Received unknown type, ignoring...");
        return null;
    }
}
Also used : GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) Nullable(android.support.annotation.Nullable)

Example 2 with SignalServiceGroup

use of org.whispersystems.signalservice.api.messages.SignalServiceGroup 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 SignalServiceGroup

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

the class RequestGroupInfoJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    SignalServiceGroup group = SignalServiceGroup.newBuilder(Type.REQUEST_INFO).withId(groupId).build();
    SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder().asGroupMessage(group).withTimestamp(System.currentTimeMillis()).build();
    messageSender.sendMessage(new SignalServiceAddress(source), message);
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup)

Example 4 with SignalServiceGroup

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

the class IdentityUpdateJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws Exception {
    Recipient recipient = RecipientFactory.getRecipientForId(context, recipientId, true);
    Recipients recipients = RecipientFactory.getRecipientsFor(context, recipient, true);
    String number = recipient.getNumber();
    long time = System.currentTimeMillis();
    SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
    GroupDatabase.Reader reader = groupDatabase.getGroups();
    GroupDatabase.GroupRecord groupRecord;
    while ((groupRecord = reader.getNext()) != null) {
        if (groupRecord.getMembers().contains(number) && groupRecord.isActive()) {
            SignalServiceGroup group = new SignalServiceGroup(groupRecord.getId());
            IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.of(group), 0);
            IncomingIdentityUpdateMessage groupUpdate = new IncomingIdentityUpdateMessage(incoming);
            smsDatabase.insertMessageInbox(groupUpdate);
        }
    }
    if (threadDatabase.getThreadIdIfExistsFor(recipients) != -1) {
        IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.<SignalServiceGroup>absent(), 0);
        IncomingIdentityUpdateMessage individualUpdate = new IncomingIdentityUpdateMessage(incoming);
        smsDatabase.insertMessageInbox(individualUpdate);
    }
}
Also used : IncomingIdentityUpdateMessage(org.thoughtcrime.securesms.sms.IncomingIdentityUpdateMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup)

Example 5 with SignalServiceGroup

use of org.whispersystems.signalservice.api.messages.SignalServiceGroup 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

SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)5 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 GroupRecord (org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)2 Nullable (android.support.annotation.Nullable)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Attachment (org.thoughtcrime.securesms.attachments.Attachment)1 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)1 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)1 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 IncomingIdentityUpdateMessage (org.thoughtcrime.securesms.sms.IncomingIdentityUpdateMessage)1 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)1 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)1