Search in sources :

Example 16 with Address

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

the class GroupManager method createGroup.

@NonNull
public static GroupActionResult createGroup(@NonNull Context context, @NonNull Set<Recipient> members, @Nullable Bitmap avatar, @Nullable String name, boolean mms) {
    final byte[] avatarBytes = BitmapUtil.toByteArray(avatar);
    final GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
    final String groupId = GroupUtil.getEncodedId(groupDatabase.allocateGroupId(), mms);
    final Recipient groupRecipient = Recipient.from(context, Address.fromSerialized(groupId), false);
    final Set<Address> memberAddresses = getMemberAddresses(members);
    memberAddresses.add(Address.fromSerialized(TextSecurePreferences.getLocalNumber(context)));
    groupDatabase.create(groupId, name, new LinkedList<>(memberAddresses), null, null);
    if (!mms) {
        groupDatabase.updateAvatar(groupId, avatarBytes);
        DatabaseFactory.getRecipientDatabase(context).setProfileSharing(groupRecipient, true);
        return sendGroupUpdate(context, groupId, memberAddresses, name, avatarBytes);
    } else {
        long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION);
        return new GroupActionResult(groupRecipient, threadId);
    }
}
Also used : Address(org.thoughtcrime.securesms.database.Address) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ByteString(com.google.protobuf.ByteString) NonNull(android.support.annotation.NonNull)

Example 17 with Address

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

the class GroupMessageProcessor method handleGroupUpdate.

@Nullable
private static Long handleGroupUpdate(@NonNull Context context, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, @NonNull GroupRecord groupRecord, boolean outgoing) {
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    String id = GroupUtil.getEncodedId(group.getGroupId(), false);
    Set<Address> recordMembers = new HashSet<>(groupRecord.getMembers());
    Set<Address> messageMembers = new HashSet<>();
    for (String messageMember : group.getMembers().get()) {
        messageMembers.add(Address.fromExternal(context, messageMember));
    }
    Set<Address> addedMembers = new HashSet<>(messageMembers);
    addedMembers.removeAll(recordMembers);
    Set<Address> missingMembers = new HashSet<>(recordMembers);
    missingMembers.removeAll(messageMembers);
    GroupContext.Builder builder = createGroupContext(group);
    builder.setType(GroupContext.Type.UPDATE);
    if (addedMembers.size() > 0) {
        Set<Address> unionMembers = new HashSet<>(recordMembers);
        unionMembers.addAll(messageMembers);
        database.updateMembers(id, new LinkedList<>(unionMembers));
        builder.clearMembers();
        for (Address addedMember : addedMembers) {
            builder.addMembers(addedMember.serialize());
        }
    } 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, 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) HashSet(java.util.HashSet) Nullable(android.support.annotation.Nullable)

Example 18 with Address

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

the class GroupMessageProcessor method handleGroupLeave.

private static Long handleGroupLeave(@NonNull Context context, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, @NonNull GroupRecord record, boolean outgoing) {
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    String id = GroupUtil.getEncodedId(group.getGroupId(), false);
    List<Address> members = record.getMembers();
    GroupContext.Builder builder = createGroupContext(group);
    builder.setType(GroupContext.Type.QUIT);
    if (members.contains(Address.fromExternal(context, envelope.getSource()))) {
        database.remove(id, Address.fromExternal(context, envelope.getSource()));
        if (outgoing)
            database.setActive(id, false);
        return storeMessage(context, envelope, group, builder.build(), outgoing);
    }
    return null;
}
Also used : 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)

Example 19 with Address

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

the class VoiceCallShare method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (getIntent().getData() != null && "content".equals(getIntent().getData().getScheme())) {
        Cursor cursor = null;
        try {
            cursor = getContentResolver().query(getIntent().getData(), null, null, null, null);
            if (cursor != null && cursor.moveToNext()) {
                String destination = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.RawContacts.Data.DATA1));
                Address address = Address.fromExternal(this, destination);
                if (!TextUtils.isEmpty(destination)) {
                    Intent serviceIntent = new Intent(this, WebRtcCallService.class);
                    serviceIntent.setAction(WebRtcCallService.ACTION_OUTGOING_CALL);
                    serviceIntent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, address);
                    startService(serviceIntent);
                    Intent activityIntent = new Intent(this, WebRtcCallActivity.class);
                    activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(activityIntent);
                }
            }
        } finally {
            if (cursor != null)
                cursor.close();
        }
    }
    finish();
}
Also used : Address(org.thoughtcrime.securesms.database.Address) Intent(android.content.Intent) Cursor(android.database.Cursor)

Example 20 with Address

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

the class MultiDeviceGroupUpdateJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws Exception {
    File contactDataFile = createTempFile("multidevice-contact-update");
    GroupDatabase.Reader reader = null;
    GroupDatabase.GroupRecord record;
    try {
        DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(new FileOutputStream(contactDataFile));
        reader = DatabaseFactory.getGroupDatabase(context).getGroups();
        while ((record = reader.getNext()) != null) {
            if (!record.isMms()) {
                List<String> members = new LinkedList<>();
                for (Address member : record.getMembers()) {
                    members.add(member.serialize());
                }
                Recipient recipient = Recipient.from(context, Address.fromSerialized(GroupUtil.getEncodedId(record.getId(), record.isMms())), false);
                Optional<Integer> expirationTimer = recipient.getExpireMessages() > 0 ? Optional.of(recipient.getExpireMessages()) : Optional.absent();
                out.write(new DeviceGroup(record.getId(), Optional.fromNullable(record.getTitle()), members, getAvatar(record.getAvatar()), record.isActive(), expirationTimer));
            }
        }
        out.close();
        if (contactDataFile.exists() && contactDataFile.length() > 0) {
            sendUpdate(messageSender, contactDataFile);
        } else {
            Log.w(TAG, "No groups present for sync message...");
        }
    } finally {
        if (contactDataFile != null)
            contactDataFile.delete();
        if (reader != null)
            reader.close();
    }
}
Also used : Address(org.thoughtcrime.securesms.database.Address) DeviceGroup(org.whispersystems.signalservice.api.messages.multidevice.DeviceGroup) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LinkedList(java.util.LinkedList) FileOutputStream(java.io.FileOutputStream) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) File(java.io.File) DeviceGroupsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsOutputStream)

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