Search in sources :

Example 1 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class ReviewUtil method getDuplicatedRecipients.

@WorkerThread
@NonNull
public static List<ReviewRecipient> getDuplicatedRecipients(@NonNull GroupId.V2 groupId) {
    Context context = ApplicationDependencies.getApplication();
    List<MessageRecord> profileChangeRecords = getProfileChangeRecordsForGroup(context, groupId);
    if (profileChangeRecords.isEmpty()) {
        return Collections.emptyList();
    }
    List<Recipient> members = SignalDatabase.groups().getGroupMembers(groupId, GroupDatabase.MemberSet.FULL_MEMBERS_INCLUDING_SELF);
    List<ReviewRecipient> changed = Stream.of(profileChangeRecords).distinctBy(record -> record.getRecipient().getId()).map(record -> new ReviewRecipient(record.getRecipient().resolve(), getProfileChangeDetails(record))).filter(recipient -> !recipient.getRecipient().isSystemContact()).toList();
    List<ReviewRecipient> results = new LinkedList<>();
    for (ReviewRecipient recipient : changed) {
        if (results.contains(recipient)) {
            continue;
        }
        members.remove(recipient.getRecipient());
        for (Recipient member : members) {
            if (Objects.equals(member.getDisplayName(context), recipient.getRecipient().getDisplayName(context))) {
                results.add(recipient);
                results.add(new ReviewRecipient(member));
            }
        }
    }
    return results;
}
Also used : Context(android.content.Context) Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Base64(org.thoughtcrime.securesms.util.Base64) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) WorkerThread(androidx.annotation.WorkerThread) IOException(java.io.IOException) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ProfileChangeDetails(org.thoughtcrime.securesms.database.model.databaseprotos.ProfileChangeDetails) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) GroupId(org.thoughtcrime.securesms.groups.GroupId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LinkedList(java.util.LinkedList) Collections(java.util.Collections) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LinkedList(java.util.LinkedList) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 2 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class ReviewCardDialogFragment method getRepository.

@NonNull
private ReviewCardRepository getRepository() throws BadGroupIdException {
    RecipientId recipientId = getRecipientId();
    GroupId.V2 groupId = getGroupId();
    if (recipientId != null) {
        return new ReviewCardRepository(requireContext(), recipientId);
    } else if (groupId != null) {
        return new ReviewCardRepository(requireContext(), groupId);
    } else {
        throw new AssertionError();
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) GroupId(org.thoughtcrime.securesms.groups.GroupId) NonNull(androidx.annotation.NonNull)

Example 3 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class GroupDatabase method getAllExpectedV2Ids.

/**
 * Key: The 'expected' V2 ID (i.e. what a V1 ID would map to when migrated)
 * Value: The matching V1 ID
 */
@NonNull
public Map<GroupId.V2, GroupId.V1> getAllExpectedV2Ids() {
    Map<GroupId.V2, GroupId.V1> result = new HashMap<>();
    String[] projection = new String[] { GROUP_ID, EXPECTED_V2_ID };
    String query = EXPECTED_V2_ID + " NOT NULL";
    try (Cursor cursor = databaseHelper.getSignalReadableDatabase().query(TABLE_NAME, projection, query, null, null, null, null)) {
        while (cursor.moveToNext()) {
            GroupId.V1 groupId = GroupId.parseOrThrow(cursor.getString(cursor.getColumnIndexOrThrow(GROUP_ID))).requireV1();
            GroupId.V2 expectedId = GroupId.parseOrThrow(cursor.getString(cursor.getColumnIndexOrThrow(EXPECTED_V2_ID))).requireV2();
            result.put(expectedId, groupId);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Cursor(android.database.Cursor) GroupId(org.thoughtcrime.securesms.groups.GroupId) NonNull(androidx.annotation.NonNull)

Example 4 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class GroupDatabase method getOrCreateMmsGroupForMembers.

public GroupId.Mms getOrCreateMmsGroupForMembers(List<RecipientId> members) {
    Collections.sort(members);
    Cursor cursor = databaseHelper.getSignalReadableDatabase().query(TABLE_NAME, new String[] { GROUP_ID }, MEMBERS + " = ? AND " + MMS + " = ?", new String[] { RecipientId.toSerializedList(members), "1" }, null, null, null);
    try {
        if (cursor != null && cursor.moveToNext()) {
            return GroupId.parseOrThrow(cursor.getString(cursor.getColumnIndexOrThrow(GROUP_ID))).requireMms();
        } else {
            GroupId.Mms groupId = GroupId.createMms(new SecureRandom());
            create(groupId, null, members);
            return groupId;
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : SecureRandom(java.security.SecureRandom) Cursor(android.database.Cursor) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 5 with GroupId

use of org.thoughtcrime.securesms.groups.GroupId in project Signal-Android by WhisperSystems.

the class GroupDatabase method getGroupMembers.

@WorkerThread
@NonNull
public List<Recipient> getGroupMembers(@NonNull GroupId groupId, @NonNull MemberSet memberSet) {
    if (groupId.isV2()) {
        return getGroup(groupId).transform(g -> g.requireV2GroupProperties().getMemberRecipients(memberSet)).or(Collections.emptyList());
    } else {
        List<RecipientId> currentMembers = getCurrentMembers(groupId);
        List<Recipient> recipients = new ArrayList<>(currentMembers.size());
        for (RecipientId member : currentMembers) {
            Recipient resolved = Recipient.resolved(member);
            if (memberSet.includeSelf || !resolved.isSelf()) {
                recipients.add(resolved);
            }
        }
        return recipients;
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) GroupMigrationMembershipChange(org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange) NonNull(androidx.annotation.NonNull) RequestGroupV2InfoJob(org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob) GroupAccessControl(org.thoughtcrime.securesms.groups.GroupAccessControl) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) SecureRandom(java.security.SecureRandom) Member(org.signal.storageservice.protos.groups.Member) SenderKeyUtil(org.thoughtcrime.securesms.crypto.SenderKeyUtil) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) SqlUtil(org.thoughtcrime.securesms.util.SqlUtil) Locale(java.util.Locale) Map(java.util.Map) DecryptedGroupChange(org.signal.storageservice.protos.groups.local.DecryptedGroupChange) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupsV2StateProcessor(org.thoughtcrime.securesms.groups.v2.processing.GroupsV2StateProcessor) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ACI(org.whispersystems.signalservice.api.push.ACI) DecryptedGroupUtil(org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) EnabledState(org.signal.storageservice.protos.groups.local.EnabledState) Set(java.util.Set) SetUtil(org.thoughtcrime.securesms.util.SetUtil) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) InvalidInputException(org.signal.zkgroup.InvalidInputException) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) GroupId(org.thoughtcrime.securesms.groups.GroupId) ContentValues(android.content.ContentValues) Context(android.content.Context) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) WorkerThread(androidx.annotation.WorkerThread) HashMap(java.util.HashMap) AccessControl(org.signal.storageservice.protos.groups.AccessControl) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) LinkedList(java.util.LinkedList) DistributionId(org.whispersystems.signalservice.api.push.DistributionId) Cursor(android.database.Cursor) GroupChangeReconstruct(org.whispersystems.signalservice.api.groupsv2.GroupChangeReconstruct) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) UuidUtil(org.whispersystems.signalservice.api.util.UuidUtil) TextUtils(android.text.TextUtils) Optional(org.whispersystems.libsignal.util.guava.Optional) CursorUtil(org.thoughtcrime.securesms.util.CursorUtil) Closeable(java.io.Closeable) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Aggregations

GroupId (org.thoughtcrime.securesms.groups.GroupId)41 Recipient (org.thoughtcrime.securesms.recipients.Recipient)26 NonNull (androidx.annotation.NonNull)22 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)13 Context (android.content.Context)12 List (java.util.List)11 Log (org.signal.core.util.logging.Log)11 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)11 Collections (java.util.Collections)10 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)10 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)10 Optional (org.whispersystems.libsignal.util.guava.Optional)10 Nullable (androidx.annotation.Nullable)9 IOException (java.io.IOException)9 LinkedList (java.util.LinkedList)8 Collectors (java.util.stream.Collectors)8 SignalStore (org.thoughtcrime.securesms.keyvalue.SignalStore)8 SendMessageResult (org.whispersystems.signalservice.api.messages.SendMessageResult)8 Intent (android.content.Intent)7 Stream (com.annimon.stream.Stream)7