Search in sources :

Example 21 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class MultiDeviceVerifiedUpdateJob method onRun.

@Override
public void onRun() throws IOException, UntrustedIdentityException {
    try {
        if (!TextSecurePreferences.isMultiDevice(context)) {
            Log.w(TAG, "Not multi device...");
            return;
        }
        if (destination == null) {
            Log.w(TAG, "No destination...");
            return;
        }
        Address canonicalDestination = Address.fromSerialized(destination);
        VerifiedMessage.VerifiedState verifiedState = getVerifiedState(verifiedStatus);
        VerifiedMessage verifiedMessage = new VerifiedMessage(canonicalDestination.toPhoneString(), new IdentityKey(identityKey, 0), verifiedState, timestamp);
        messageSender.sendMessage(SignalServiceSyncMessage.forVerified(verifiedMessage));
    } catch (InvalidKeyException e) {
        throw new IOException(e);
    }
}
Also used : IdentityKey(org.whispersystems.libsignal.IdentityKey) Address(org.thoughtcrime.securesms.database.Address) IOException(java.io.IOException) VerifiedMessage(org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException)

Example 22 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class MarkReadReceiver method process.

public static void process(@NonNull Context context, @NonNull List<MarkedMessageInfo> markedReadMessages) {
    if (markedReadMessages.isEmpty())
        return;
    List<SyncMessageId> syncMessageIds = new LinkedList<>();
    for (MarkedMessageInfo messageInfo : markedReadMessages) {
        scheduleDeletion(context, messageInfo.getExpirationInfo());
        syncMessageIds.add(messageInfo.getSyncMessageId());
    }
    ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceReadUpdateJob(context, syncMessageIds));
    Map<Address, List<SyncMessageId>> addressMap = Stream.of(markedReadMessages).map(MarkedMessageInfo::getSyncMessageId).collect(Collectors.groupingBy(SyncMessageId::getAddress));
    for (Address address : addressMap.keySet()) {
        List<Long> timestamps = Stream.of(addressMap.get(address)).map(SyncMessageId::getTimetamp).toList();
        ApplicationContext.getInstance(context).getJobManager().add(new SendReadReceiptJob(context, address, timestamps));
    }
}
Also used : SendReadReceiptJob(org.thoughtcrime.securesms.jobs.SendReadReceiptJob) Address(org.thoughtcrime.securesms.database.Address) List(java.util.List) LinkedList(java.util.LinkedList) SyncMessageId(org.thoughtcrime.securesms.database.MessagingDatabase.SyncMessageId) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo) MultiDeviceReadUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob) LinkedList(java.util.LinkedList)

Example 23 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class GroupManager method sendGroupUpdate.

private static GroupActionResult sendGroupUpdate(@NonNull Context context, @NonNull String groupId, @NonNull Set<Address> members, @Nullable String groupName, @Nullable byte[] avatar) {
    try {
        Attachment avatarAttachment = null;
        Address groupAddress = Address.fromSerialized(groupId);
        Recipient groupRecipient = Recipient.from(context, groupAddress, false);
        List<String> numbers = new LinkedList<>();
        for (Address member : members) {
            numbers.add(member.serialize());
        }
        GroupContext.Builder groupContextBuilder = GroupContext.newBuilder().setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupId))).setType(GroupContext.Type.UPDATE).addAllMembers(numbers);
        if (groupName != null)
            groupContextBuilder.setName(groupName);
        GroupContext groupContext = groupContextBuilder.build();
        if (avatar != null) {
            Uri avatarUri = SingleUseBlobProvider.getInstance().createUri(avatar);
            avatarAttachment = new UriAttachment(avatarUri, MediaUtil.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length, null, false);
        }
        OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(groupRecipient, groupContext, avatarAttachment, System.currentTimeMillis(), 0);
        long threadId = MessageSender.send(context, outgoingMessage, -1, false, null);
        return new GroupActionResult(groupRecipient, threadId);
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}
Also used : Address(org.thoughtcrime.securesms.database.Address) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) Uri(android.net.Uri) LinkedList(java.util.LinkedList) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Example 24 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class GroupMessageProcessor method storeMessage.

@Nullable
private static Long storeMessage(@NonNull Context context, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, @NonNull GroupContext storage, boolean outgoing) {
    if (group.getAvatar().isPresent()) {
        ApplicationContext.getInstance(context).getJobManager().add(new AvatarDownloadJob(context, group.getGroupId()));
    }
    try {
        if (outgoing) {
            MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
            Address addres = Address.fromExternal(context, GroupUtil.getEncodedId(group.getGroupId(), false));
            Recipient recipient = Recipient.from(context, addres, false);
            OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(recipient, storage, null, envelope.getTimestamp(), 0);
            long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
            long messageId = mmsDatabase.insertMessageOutbox(outgoingMessage, threadId, false, null);
            mmsDatabase.markAsSent(messageId, true);
            return threadId;
        } else {
            SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
            String body = Base64.encodeBytes(storage.toByteArray());
            IncomingTextMessage incoming = new IncomingTextMessage(Address.fromExternal(context, envelope.getSource()), envelope.getSourceDevice(), envelope.getTimestamp(), body, Optional.of(group), 0);
            IncomingGroupMessage groupMessage = new IncomingGroupMessage(incoming, storage, body);
            Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(groupMessage);
            if (insertResult.isPresent()) {
                MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
                return insertResult.get().getThreadId();
            } else {
                return null;
            }
        }
    } catch (MmsException e) {
        Log.w(TAG, e);
    }
    return null;
}
Also used : IncomingGroupMessage(org.thoughtcrime.securesms.sms.IncomingGroupMessage) InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) Address(org.thoughtcrime.securesms.database.Address) AvatarDownloadJob(org.thoughtcrime.securesms.jobs.AvatarDownloadJob) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ByteString(com.google.protobuf.ByteString) MmsException(org.thoughtcrime.securesms.mms.MmsException) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) Nullable(android.support.annotation.Nullable)

Example 25 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class GroupMessageProcessor method handleGroupCreate.

@Nullable
private static Long handleGroupCreate(@NonNull Context context, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, boolean outgoing) {
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    String id = GroupUtil.getEncodedId(group.getGroupId(), false);
    GroupContext.Builder builder = createGroupContext(group);
    builder.setType(GroupContext.Type.UPDATE);
    SignalServiceAttachment avatar = group.getAvatar().orNull();
    List<Address> members = group.getMembers().isPresent() ? new LinkedList<Address>() : null;
    if (group.getMembers().isPresent()) {
        for (String member : group.getMembers().get()) {
            members.add(Address.fromExternal(context, member));
        }
    }
    database.create(id, group.getName().orNull(), members, avatar != null && avatar.isPointer() ? avatar.asPointer() : null, envelope.getRelay());
    return storeMessage(context, envelope, group, builder.build(), outgoing);
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Address(org.thoughtcrime.securesms.database.Address) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ByteString(com.google.protobuf.ByteString) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) Nullable(android.support.annotation.Nullable)

Aggregations

Address (org.thoughtcrime.securesms.database.Address)40 Recipient (org.thoughtcrime.securesms.recipients.Recipient)13 LinkedList (java.util.LinkedList)10 Uri (android.net.Uri)9 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)7 Cursor (android.database.Cursor)6 ByteString (com.google.protobuf.ByteString)6 IOException (java.io.IOException)6 File (java.io.File)5 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)5 NonNull (android.support.annotation.NonNull)4 Attachment (org.thoughtcrime.securesms.attachments.Attachment)4 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)4 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)4 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)4 SuppressLint (android.annotation.SuppressLint)3 Nullable (android.support.annotation.Nullable)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ContentValues (android.content.ContentValues)2