mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Proper handling of GV1->GV2 migrations in storage service.
This commit is contained in:
committed by
Cody Henthorne
parent
e8f0038c36
commit
cd58c09be3
@@ -41,10 +41,12 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Trace
|
||||
@@ -677,7 +679,7 @@ public final class GroupDatabase extends Database {
|
||||
return RecipientId.toSerializedList(groupMembers);
|
||||
}
|
||||
|
||||
public List<GroupId.V2> getAllGroupV2Ids() {
|
||||
public @NonNull List<GroupId.V2> getAllGroupV2Ids() {
|
||||
List<GroupId.V2> result = new LinkedList<>();
|
||||
|
||||
try (Cursor cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, new String[]{ GROUP_ID }, null, null, null, null, null)) {
|
||||
@@ -692,6 +694,28 @@ public final class GroupDatabase extends Database {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Key: The 'expected' V2 ID (i.e. what a V1 ID would map to when migrated)
|
||||
* Value: The matching V1 ID
|
||||
*/
|
||||
public @NonNull 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.getReadableDatabase().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;
|
||||
}
|
||||
|
||||
public static class Reader implements Closeable {
|
||||
|
||||
private final Cursor cursor;
|
||||
|
||||
Reference in New Issue
Block a user