Add the ability to migrate GV1 groups to GV2.

Co-authored-by: Alan Evans <alan@signal.org>
This commit is contained in:
Greyson Parrelli
2020-10-15 15:49:09 -04:00
committed by Alan Evans
parent 2d1bf33902
commit 6bb9d27d4e
34 changed files with 818 additions and 132 deletions

View File

@@ -234,12 +234,32 @@ public class Recipient {
/**
* A version of {@link #external(Context, String)} that should be used when you know the
* identifier is a groupId.
*
* Important: This will throw an exception if the groupId you're using could have been migrated.
* If you're dealing with inbound data, you should be using
* {@link #externalPossiblyMigratedGroup(Context, GroupId)}, or checking the database before
* calling this method.
*/
@WorkerThread
public static @NonNull Recipient externalGroup(@NonNull Context context, @NonNull GroupId groupId) {
public static @NonNull Recipient externalGroupExact(@NonNull Context context, @NonNull GroupId groupId) {
return Recipient.resolved(DatabaseFactory.getRecipientDatabase(context).getOrInsertFromGroupId(groupId));
}
/**
* Will give you one of:
* - The recipient that matches the groupId specified exactly
* - The recipient whose V1 ID would map to the provided V2 ID
* - The recipient whose V2 ID would be derived from the provided V1 ID
* - A newly-created recipient for the provided ID if none of the above match
*
* Important: You could get back a recipient with a different groupId than the one you provided.
* You should be very cautious when using the groupId on the returned recipient.
*/
@WorkerThread
public static @NonNull Recipient externalPossiblyMigratedGroup(@NonNull Context context, @NonNull GroupId groupId) {
return Recipient.resolved(DatabaseFactory.getRecipientDatabase(context).getOrInsertFromPossiblyMigratedGroupId(groupId));
}
/**
* Returns a fully-populated {@link Recipient} based off of a string identifier, creating one in
* the database if necessary. The identifier may be a uuid, phone number, email,