mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Fix ID remapping issues when getting group membership.
This commit is contained in:
committed by
Alex Hart
parent
d7bf4f178f
commit
178f5e80e3
@@ -581,7 +581,7 @@ private static final String[] GROUP_PROJECTION = {
|
||||
throw new AssertionError("V2 master key but no group state");
|
||||
}
|
||||
groupId.requireV2();
|
||||
groupMembers = getV2GroupMembers(context, groupState, true);
|
||||
groupMembers = getV2GroupMembers(groupState, true);
|
||||
contentValues.put(V2_MASTER_KEY, groupMasterKey.serialize());
|
||||
contentValues.put(V2_REVISION, groupState.getRevision());
|
||||
contentValues.put(V2_DECRYPTED_GROUP, groupState.toByteArray());
|
||||
@@ -720,7 +720,7 @@ private static final String[] GROUP_PROJECTION = {
|
||||
contentValues.put(UNMIGRATED_V1_MEMBERS, unmigratedV1Members.isEmpty() ? null : RecipientId.toSerializedList(unmigratedV1Members));
|
||||
}
|
||||
|
||||
List<RecipientId> groupMembers = getV2GroupMembers(context, decryptedGroup, true);
|
||||
List<RecipientId> groupMembers = getV2GroupMembers(decryptedGroup, true);
|
||||
contentValues.put(TITLE, title);
|
||||
contentValues.put(V2_REVISION, decryptedGroup.getRevision());
|
||||
contentValues.put(V2_DECRYPTED_GROUP, decryptedGroup.toByteArray());
|
||||
@@ -885,7 +885,15 @@ private static final String[] GROUP_PROJECTION = {
|
||||
if (UuidUtil.UNKNOWN_UUID.equals(uuid)) {
|
||||
Log.w(TAG, "Seen unknown UUID in members list");
|
||||
} else {
|
||||
groupMembers.add(RecipientId.from(ACI.from(uuid), null));
|
||||
RecipientId id = RecipientId.from(ACI.from(uuid), null);
|
||||
Optional<RecipientId> remapped = RemappedRecords.getInstance().getRecipient(id);
|
||||
|
||||
if (remapped.isPresent()) {
|
||||
Log.w(TAG, "Saw that " + id + " remapped to " + remapped + ". Using the mapping.");
|
||||
groupMembers.add(remapped.get());
|
||||
} else {
|
||||
groupMembers.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -894,7 +902,7 @@ private static final String[] GROUP_PROJECTION = {
|
||||
return groupMembers;
|
||||
}
|
||||
|
||||
private static @NonNull List<RecipientId> getV2GroupMembers(@NonNull Context context, @NonNull DecryptedGroup decryptedGroup, boolean shouldRetry) {
|
||||
private static @NonNull List<RecipientId> getV2GroupMembers(@NonNull DecryptedGroup decryptedGroup, boolean shouldRetry) {
|
||||
List<UUID> uuids = DecryptedGroupUtil.membersToUuidList(decryptedGroup.getMembersList());
|
||||
List<RecipientId> ids = uuidsToRecipientIds(uuids);
|
||||
|
||||
@@ -902,7 +910,8 @@ private static final String[] GROUP_PROJECTION = {
|
||||
if (shouldRetry) {
|
||||
Log.w(TAG, "Found remapped records where we shouldn't. Clearing cache and trying again.");
|
||||
RecipientId.clearCache();
|
||||
return getV2GroupMembers(context, decryptedGroup, false);
|
||||
RemappedRecords.getInstance().resetCache();
|
||||
return getV2GroupMembers(decryptedGroup, false);
|
||||
} else {
|
||||
throw new IllegalStateException("Remapped records in group membership!");
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package org.thoughtcrime.securesms.database;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.libsignal.util.guava.Preconditions;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -88,6 +87,7 @@ class RemappedRecords {
|
||||
*/
|
||||
void addRecipient(@NonNull RecipientId oldId, @NonNull RecipientId newId) {
|
||||
Log.w(TAG, "[Recipient] Remapping " + oldId + " to " + newId);
|
||||
Preconditions.checkArgument(!oldId.equals(newId), "Cannot remap an ID to the same thing!");
|
||||
ensureInTransaction();
|
||||
ensureRecipientMapIsPopulated();
|
||||
recipientMap.put(oldId, newId);
|
||||
@@ -99,12 +99,20 @@ class RemappedRecords {
|
||||
*/
|
||||
void addThread(long oldId, long newId) {
|
||||
Log.w(TAG, "[Thread] Remapping " + oldId + " to " + newId);
|
||||
Preconditions.checkArgument(oldId != newId, "Cannot remap an ID to the same thing!");
|
||||
ensureInTransaction();
|
||||
ensureThreadMapIsPopulated();
|
||||
threadMap.put(oldId, newId);
|
||||
SignalDatabase.remappedRecords().addThreadMapping(oldId, newId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears out the memory cache. The next read will pull values from disk.
|
||||
*/
|
||||
void resetCache() {
|
||||
recipientMap = null;
|
||||
}
|
||||
|
||||
private void ensureRecipientMapIsPopulated() {
|
||||
if (recipientMap == null) {
|
||||
recipientMap = SignalDatabase.remappedRecords().getAllRecipientMappings();
|
||||
|
||||
Reference in New Issue
Block a user