mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-08 22:58:33 +00:00
Create GV2 group behind feature flag.
This commit is contained in:
parent
6cf33897c0
commit
ee9270845a
@ -442,7 +442,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
@Override
|
||||
protected Optional<GroupActionResult> doInBackground(Void... aVoid) {
|
||||
return Optional.of(GroupManager.createGroup(activity, members, avatar, name, false));
|
||||
return Optional.of(GroupManager.createGroupV1(activity, members, BitmapUtil.toByteArray(avatar), name, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.thoughtcrime.securesms.groups;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -15,6 +14,7 @@ import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -27,15 +27,40 @@ public final class GroupManager {
|
||||
|
||||
private static final String TAG = Log.tag(GroupManager.class);
|
||||
|
||||
@WorkerThread
|
||||
public static @NonNull GroupActionResult createGroup(@NonNull Context context,
|
||||
@NonNull Set<Recipient> members,
|
||||
@Nullable Bitmap avatar,
|
||||
@Nullable byte[] avatar,
|
||||
@Nullable String name,
|
||||
boolean mms)
|
||||
throws GroupChangeBusyException, GroupChangeFailedException, IOException
|
||||
{
|
||||
Set<RecipientId> addresses = getMemberIds(members);
|
||||
boolean shouldAttemptToCreateV2 = !mms && FeatureFlags.groupsV2create();
|
||||
Set<RecipientId> memberIds = getMemberIds(members);
|
||||
|
||||
return GroupManagerV1.createGroup(context, addresses, avatar, name, mms);
|
||||
if (shouldAttemptToCreateV2) {
|
||||
try {
|
||||
try (GroupManagerV2.GroupCreator groupCreator = new GroupManagerV2(context).create()) {
|
||||
return groupCreator.createGroup(memberIds, name, avatar);
|
||||
}
|
||||
} catch (MembershipNotSuitableForV2Exception e) {
|
||||
Log.w(TAG, "Attempted to make a GV2, but membership was not suitable, falling back to GV1", e);
|
||||
|
||||
return GroupManagerV1.createGroup(context, memberIds, avatar, name, false);
|
||||
}
|
||||
} else {
|
||||
return GroupManagerV1.createGroup(context, memberIds, avatar, name, mms);
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static @NonNull GroupActionResult createGroupV1(@NonNull Context context,
|
||||
@NonNull Set<Recipient> members,
|
||||
@Nullable byte[] avatar,
|
||||
@Nullable String name,
|
||||
boolean mms)
|
||||
{
|
||||
return GroupManagerV1.createGroup(context, getMemberIds(members), avatar, name, mms);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
@ -50,11 +50,10 @@ final class GroupManagerV1 {
|
||||
|
||||
static @NonNull GroupActionResult createGroup(@NonNull Context context,
|
||||
@NonNull Set<RecipientId> memberIds,
|
||||
@Nullable Bitmap avatar,
|
||||
@Nullable byte[] avatarBytes,
|
||||
@Nullable String name,
|
||||
boolean mms)
|
||||
{
|
||||
final byte[] avatarBytes = BitmapUtil.toByteArray(avatar);
|
||||
final GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
|
||||
final SecureRandom secureRandom = new SecureRandom();
|
||||
final GroupId groupId = mms ? GroupId.createMms(secureRandom) : GroupId.createV1(secureRandom);
|
||||
|
@ -61,6 +61,7 @@ public final class FeatureFlags {
|
||||
private static final String NEW_GROUP_UI = "android.newGroupUI";
|
||||
private static final String REACT_WITH_ANY_EMOJI = "android.reactWithAnyEmoji";
|
||||
private static final String GROUPS_V2 = "android.groupsv2";
|
||||
private static final String GROUPS_V2_CREATE = "android.groupsv2.create";
|
||||
|
||||
/**
|
||||
* We will only store remote values for flags in this set. If you want a flag to be controllable
|
||||
@ -262,6 +263,11 @@ public final class FeatureFlags {
|
||||
return org.whispersystems.signalservice.FeatureFlags.ZK_GROUPS && getBoolean(GROUPS_V2, false);
|
||||
}
|
||||
|
||||
/** Groups v2 send and receive. */
|
||||
public static boolean groupsV2create() {
|
||||
return groupsV2() && getBoolean(GROUPS_V2_CREATE, false);
|
||||
}
|
||||
|
||||
/** Only for rendering debug info. */
|
||||
public static synchronized @NonNull Map<String, Object> getMemoryValues() {
|
||||
return new TreeMap<>(REMOTE_VALUES);
|
||||
|
Loading…
x
Reference in New Issue
Block a user