Search in sources :

Example 1 with GroupRecord

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

the class ConversationActivity method isActiveGroup.

private boolean isActiveGroup() {
    if (!isGroupConversation())
        return false;
    try {
        byte[] groupId = GroupUtil.getDecodedId(getRecipients().getPrimaryRecipient().getNumber());
        GroupRecord record = DatabaseFactory.getGroupDatabase(this).getGroup(groupId);
        return record != null && record.isActive();
    } catch (IOException e) {
        Log.w("ConversationActivity", e);
        return false;
    }
}
Also used : IOException(java.io.IOException) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord)

Example 2 with GroupRecord

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

the class ContactAccessor method getNumbersForThreadSearchFilter.

public List<String> getNumbersForThreadSearchFilter(Context context, String constraint) {
    LinkedList<String> numberList = new LinkedList<>();
    Cursor cursor = null;
    try {
        cursor = context.getContentResolver().query(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(constraint)), null, null, null, null);
        while (cursor != null && cursor.moveToNext()) {
            numberList.add(cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER)));
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    GroupDatabase.Reader reader = null;
    GroupRecord record;
    try {
        reader = DatabaseFactory.getGroupDatabase(context).getGroupsFilteredByTitle(constraint);
        while ((record = reader.getNext()) != null) {
            numberList.add(record.getEncodedId());
        }
    } finally {
        if (reader != null)
            reader.close();
    }
    return numberList;
}
Also used : GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) MergeCursor(android.database.MergeCursor) Cursor(android.database.Cursor) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) LinkedList(java.util.LinkedList)

Example 3 with GroupRecord

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

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

GroupRecord (org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord)4 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)3 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)2 Cursor (android.database.Cursor)1 MergeCursor (android.database.MergeCursor)1 Nullable (android.support.annotation.Nullable)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)1 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)1 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)1 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)1