Search in sources :

Example 6 with GroupDatabase

use of org.thoughtcrime.securesms.database.GroupDatabase in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleSynchronizeSentMessage.

private void handleSynchronizeSentMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SentTranscriptMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
    Long threadId;
    if (message.getMessage().isEndSession()) {
        threadId = handleSynchronizeSentEndSessionMessage(masterSecret, message, smsMessageId);
    } else if (message.getMessage().isGroupUpdate()) {
        threadId = GroupMessageProcessor.process(context, masterSecret, envelope, message.getMessage(), true);
    } else if (message.getMessage().isExpirationUpdate()) {
        threadId = handleSynchronizeSentExpirationUpdate(masterSecret, message, smsMessageId);
    } else if (message.getMessage().getAttachments().isPresent()) {
        threadId = handleSynchronizeSentMediaMessage(masterSecret, message, smsMessageId);
    } else {
        threadId = handleSynchronizeSentTextMessage(masterSecret, message, smsMessageId);
    }
    if (message.getMessage().getGroupInfo().isPresent() && groupDatabase.isUnknownGroup(message.getMessage().getGroupInfo().get().getGroupId())) {
        handleUnknownGroupMessage(envelope, message.getMessage().getGroupInfo().get());
    }
    if (threadId != null) {
        DatabaseFactory.getThreadDatabase(getContext()).setRead(threadId, true);
        MessageNotifier.updateNotification(getContext(), masterSecret.getMasterSecret().orNull());
    }
    MessageNotifier.setLastDesktopActivityTimestamp(message.getTimestamp());
}
Also used : GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase)

Example 7 with GroupDatabase

use of org.thoughtcrime.securesms.database.GroupDatabase 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 8 with GroupDatabase

use of org.thoughtcrime.securesms.database.GroupDatabase 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)

Example 9 with GroupDatabase

use of org.thoughtcrime.securesms.database.GroupDatabase in project Signal-Android by WhisperSystems.

the class GroupMessageProcessor method handleGroupCreate.

@Nullable
private static Long handleGroupCreate(@NonNull Context context, @NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, boolean outgoing) {
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    byte[] id = group.getGroupId();
    GroupContext.Builder builder = createGroupContext(group);
    builder.setType(GroupContext.Type.UPDATE);
    SignalServiceAttachment avatar = group.getAvatar().orNull();
    database.create(id, group.getName().orNull(), group.getMembers().orNull(), avatar != null && avatar.isPointer() ? avatar.asPointer() : null, envelope.getRelay());
    return storeMessage(context, masterSecret, envelope, group, builder.build(), outgoing);
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) Nullable(android.support.annotation.Nullable)

Example 10 with GroupDatabase

use of org.thoughtcrime.securesms.database.GroupDatabase in project Signal-Android by WhisperSystems.

the class AvatarDownloadJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws IOException {
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    GroupDatabase.GroupRecord record = database.getGroup(groupId);
    File attachment = null;
    try {
        if (record != null) {
            long avatarId = record.getAvatarId();
            String contentType = record.getAvatarContentType();
            byte[] key = record.getAvatarKey();
            String relay = record.getRelay();
            Optional<byte[]> digest = Optional.fromNullable(record.getAvatarDigest());
            if (avatarId == -1 || key == null) {
                return;
            }
            if (digest.isPresent()) {
                Log.w(TAG, "Downloading group avatar with digest: " + Hex.toString(digest.get()));
            }
            attachment = File.createTempFile("avatar", "tmp", context.getCacheDir());
            attachment.deleteOnExit();
            SignalServiceAttachmentPointer pointer = new SignalServiceAttachmentPointer(avatarId, contentType, key, relay, digest);
            InputStream inputStream = receiver.retrieveAttachment(pointer, attachment, MAX_AVATAR_SIZE);
            Bitmap avatar = BitmapUtil.createScaledBitmap(context, new AttachmentModel(attachment, key), 500, 500);
            database.updateAvatar(groupId, avatar);
            inputStream.close();
        }
    } catch (BitmapDecodingException | NonSuccessfulResponseCodeException | InvalidMessageException e) {
        Log.w(TAG, e);
    } finally {
        if (attachment != null)
            attachment.delete();
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) InputStream(java.io.InputStream) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) Bitmap(android.graphics.Bitmap) AttachmentModel(org.thoughtcrime.securesms.mms.AttachmentStreamUriLoader.AttachmentModel) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) File(java.io.File) BitmapDecodingException(org.thoughtcrime.securesms.util.BitmapDecodingException)

Aggregations

GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)11 ByteString (com.google.protobuf.ByteString)4 Nullable (android.support.annotation.Nullable)3 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)3 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)3 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)3 GroupRecord (org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)2 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)2 Bitmap (android.graphics.Bitmap)1 NonNull (android.support.annotation.NonNull)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 SignalProtocolStoreImpl (org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl)1 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)1 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)1 AttachmentModel (org.thoughtcrime.securesms.mms.AttachmentStreamUriLoader.AttachmentModel)1