Skip to content

Commit

Permalink
Add disable GV2 creation option to internal preferences UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal committed Jul 15, 2020
1 parent d02d506 commit 833ca8c
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,7 @@ private void initializeCursor() {
RecyclerViewConcatenateAdapterStickyHeader concatenateAdapter = new RecyclerViewConcatenateAdapterStickyHeader();

if (listCallback != null) {
if (FeatureFlags.groupsV2create() && FeatureFlags.internalUser()) {
headerAdapter = new FixedViewsAdapter(createNewGroupItem(listCallback), createNewGroupsV1GroupItem(listCallback));
} else {
headerAdapter = new FixedViewsAdapter(createNewGroupItem(listCallback));
}
headerAdapter = new FixedViewsAdapter(createNewGroupItem(listCallback));
headerAdapter.hide();
concatenateAdapter.addAdapter(headerAdapter);
}
Expand Down Expand Up @@ -316,13 +312,6 @@ private View createNewGroupItem(@NonNull ListCallback listCallback) {
return view;
}

private View createNewGroupsV1GroupItem(@NonNull ListCallback listCallback) {
View view = LayoutInflater.from(requireContext())
.inflate(R.layout.contact_selection_new_group_v1_item, (ViewGroup) requireView(), false);
view.setOnClickListener(v -> listCallback.onNewGroup(true));
return view;
}

private void initializeNoContactsPermission() {
swipeRefresh.setVisibility(View.GONE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class GroupCreator implements Closeable {
GroupCandidate self = groupCandidateHelper.recipientIdToCandidate(Recipient.self().getId());
Set<GroupCandidate> candidates = new HashSet<>(groupCandidateHelper.recipientIdsToCandidates(members));

if (SignalStore.internalValues().forceGv2Invites()) {
if (SignalStore.internalValues().gv2ForceInvites()) {
candidates = GroupCandidate.withoutProfileKeyCredentials(candidates);
}

Expand Down Expand Up @@ -193,7 +193,7 @@ class GroupEditor implements Closeable {

Set<GroupCandidate> groupCandidates = groupCandidateHelper.recipientIdsToCandidates(new HashSet<>(newMembers));

if (SignalStore.internalValues().forceGv2Invites()) {
if (SignalStore.internalValues().gv2ForceInvites()) {
groupCandidates = GroupCandidate.withoutProfileKeyCredentials(groupCandidates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

public class CreateGroupActivity extends ContactSelectionActivity {

private static String TAG = Log.tag(CreateGroupActivity.class);
private static final String TAG = Log.tag(CreateGroupActivity.class);

private static final int MINIMUM_GROUP_SIZE = 1;
private static final short REQUEST_CODE_ADD_DETAILS = 17275;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public final class InternalValues extends SignalStoreValues {

public static final String GV2_DO_NOT_CREATE_GV2 = "internal.gv2.do_not_create_gv2";
public static final String GV2_FORCE_INVITES = "internal.gv2.force_invites";
public static final String GV2_IGNORE_SERVER_CHANGES = "internal.gv2.ignore_server_changes";
public static final String GV2_IGNORE_P2P_CHANGES = "internal.gv2.ignore_p2p_changes";
Expand All @@ -16,7 +17,17 @@ public final class InternalValues extends SignalStoreValues {
void onFirstEverAppLaunch() {
}

public synchronized boolean forceGv2Invites() {
/**
* Do not attempt to create GV2 groups, i.e. will force creation of GV1 or MMS groups.
*/
public synchronized boolean gv2DoNotCreateGv2Groups() {
return FeatureFlags.internalUser() && getBoolean(GV2_DO_NOT_CREATE_GV2, false);
}

/**
* Members will not be added directly to a GV2 even if they could be.
*/
public synchronized boolean gv2ForceInvites() {
return FeatureFlags.internalUser() && getBoolean(GV2_FORCE_INVITES, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, String root

PreferenceDataStore preferenceDataStore = SignalStore.getPreferenceDataStore();

initializeSwitchPreference(preferenceDataStore, InternalValues.GV2_FORCE_INVITES, SignalStore.internalValues().forceGv2Invites());
initializeSwitchPreference(preferenceDataStore, InternalValues.GV2_DO_NOT_CREATE_GV2, SignalStore.internalValues().gv2DoNotCreateGv2Groups());
initializeSwitchPreference(preferenceDataStore, InternalValues.GV2_FORCE_INVITES, SignalStore.internalValues().gv2ForceInvites());
initializeSwitchPreference(preferenceDataStore, InternalValues.GV2_IGNORE_SERVER_CHANGES, SignalStore.internalValues().gv2IgnoreServerChanges());
initializeSwitchPreference(preferenceDataStore, InternalValues.GV2_IGNORE_P2P_CHANGES, SignalStore.internalValues().gv2IgnoreP2PChanges());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ public static boolean groupsV2() {
return getBoolean(GROUPS_V2, false);
}

/** Groups v2 send and receive. */
/** Attempt groups v2 creation. */
public static boolean groupsV2create() {
return groupsV2() && getBoolean(GROUPS_V2_CREATE, false);
return groupsV2() &&
getBoolean(GROUPS_V2_CREATE, false) &&
!SignalStore.internalValues().gv2DoNotCreateGv2Groups();
}

/**
Expand Down
18 changes: 0 additions & 18 deletions app/src/main/res/layout/contact_selection_new_group_v1_item.xml

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1431,8 +1431,6 @@
<string name="contact_selection_activity__enter_name_or_number">Enter name or number</string>
<string name="contact_selection_activity__invite_to_signal">Invite to Signal</string>
<string name="contact_selection_activity__new_group">New group</string>
<!-- temporary for internal testing -->
<string name="contact_selection_activity__new_gv1_group" translatable="false">New old style group (GV1)</string>

<!-- contact_filter_toolbar -->
<string name="contact_filter_toolbar__clear_entered_text_description">Clear entered text</string>
Expand Down Expand Up @@ -1961,6 +1959,8 @@
<!-- Internal only preferences -->
<string name="preferences__internal_preferences" translatable="false">Internal Preferences</string>
<string name="preferences__internal_preferences_groups_v2" translatable="false">Groups V2</string>
<string name="preferences__internal_do_not_create_gv2" translatable="false">Do not create GV2 groups</string>
<string name="preferences__internal_do_not_create_gv2_description" translatable="false">Do not attempt to create GV2 groups, i.e. will force creation of GV1 or MMS groups.</string>
<string name="preferences__internal_force_gv2_invites" translatable="false">Force Invites</string>
<string name="preferences__internal_force_gv2_invites_description" translatable="false">Members will not be added directly to a GV2 even if they could be.</string>
<string name="preferences__internal_ignore_gv2_server_changes" translatable="false">Ignore server changes</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences_internal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
android:key="internal_groupsV2"
android:title="@string/preferences__internal_preferences_groups_v2">

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:defaultValue="false"
android:key="internal.gv2.do_not_create_gv2"
android:summary="@string/preferences__internal_do_not_create_gv2_description"
android:title="@string/preferences__internal_do_not_create_gv2" />

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:defaultValue="false"
android:key="internal.gv2.force_invites"
Expand Down

0 comments on commit 833ca8c

Please sign in to comment.