mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-25 15:37:32 +00:00
Restrict group names to 32 graphemes.
Uses some code from #10132 hence co-author: Co-authored-by: Fumiaki Yoshimatsu <fumiakiy@gmail.com>
This commit is contained in:

committed by
Greyson Parrelli

parent
0ccc7e3c06
commit
2d39e43677
@@ -27,6 +27,7 @@ import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.dd.CircularProgressButton;
|
||||
|
||||
import org.signal.core.util.EditTextUtil;
|
||||
import org.thoughtcrime.securesms.LoggingFragment;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.groups.ui.GroupMemberListView;
|
||||
@@ -104,6 +105,7 @@ public class AddGroupDetailsFragment extends LoggingFragment {
|
||||
|
||||
avatar.setOnClickListener(v -> showAvatarSelectionBottomSheet());
|
||||
members.setRecipientClickListener(this::handleRecipientClick);
|
||||
EditTextUtil.addGraphemeClusterLimitFilter(name, FeatureFlags.getMaxGroupNameGraphemeLength());
|
||||
name.addTextChangedListener(new AfterTextChanged(editable -> viewModel.setName(editable.toString())));
|
||||
toolbar.setNavigationOnClickListener(unused -> callback.onNavigationButtonPressed());
|
||||
create.setOnClickListener(v -> handleCreateClicked());
|
||||
|
@@ -27,6 +27,7 @@ import androidx.navigation.Navigation;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.dd.CircularProgressButton;
|
||||
|
||||
import org.signal.core.util.EditTextUtil;
|
||||
import org.signal.core.util.StreamUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.LoggingFragment;
|
||||
@@ -63,7 +64,6 @@ public class EditProfileFragment extends LoggingFragment {
|
||||
|
||||
private static final String TAG = Log.tag(EditProfileFragment.class);
|
||||
private static final short REQUEST_CODE_SELECT_AVATAR = 31726;
|
||||
private static final int MAX_GROUP_NAME_LENGTH = 32;
|
||||
|
||||
private Toolbar toolbar;
|
||||
private View title;
|
||||
@@ -213,15 +213,12 @@ public class EditProfileFragment extends LoggingFragment {
|
||||
|
||||
this.avatar.setOnClickListener(v -> startAvatarSelection());
|
||||
|
||||
this.givenName.addTextChangedListener(new AfterTextChanged(s -> {
|
||||
trimInPlace(s, isEditingGroup);
|
||||
viewModel.setGivenName(s.toString());
|
||||
}));
|
||||
|
||||
view.findViewById(R.id.mms_group_hint)
|
||||
.setVisibility(isEditingGroup && groupId.isMms() ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (isEditingGroup) {
|
||||
EditTextUtil.addGraphemeClusterLimitFilter(givenName, FeatureFlags.getMaxGroupNameGraphemeLength());
|
||||
givenName.addTextChangedListener(new AfterTextChanged(s -> viewModel.setGivenName(s.toString())));
|
||||
givenName.setHint(R.string.EditProfileFragment__group_name);
|
||||
givenName.requestFocus();
|
||||
toolbar.setTitle(R.string.EditProfileFragment__edit_group_name_and_photo);
|
||||
@@ -231,8 +228,12 @@ public class EditProfileFragment extends LoggingFragment {
|
||||
view.findViewById(R.id.description_text).setVisibility(View.GONE);
|
||||
view.<ImageView>findViewById(R.id.avatar_placeholder).setImageResource(R.drawable.ic_group_outline_40);
|
||||
} else {
|
||||
this.givenName.addTextChangedListener(new AfterTextChanged(s -> {
|
||||
trimInPlace(s);
|
||||
viewModel.setGivenName(s.toString());
|
||||
}));
|
||||
this.familyName.addTextChangedListener(new AfterTextChanged(s -> {
|
||||
trimInPlace(s, false);
|
||||
trimInPlace(s);
|
||||
viewModel.setFamilyName(s.toString());
|
||||
}));
|
||||
LearnMoreTextView descriptionText = view.findViewById(R.id.description_text);
|
||||
@@ -335,7 +336,7 @@ public class EditProfileFragment extends LoggingFragment {
|
||||
controller.onProfileNameUploadCompleted();
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@RequiresApi(api = 21)
|
||||
private void handleFinishedLollipop() {
|
||||
int[] finishButtonLocation = new int[2];
|
||||
int[] revealLocation = new int[2];
|
||||
@@ -374,9 +375,8 @@ public class EditProfileFragment extends LoggingFragment {
|
||||
animation.start();
|
||||
}
|
||||
|
||||
private static void trimInPlace(Editable s, boolean isGroup) {
|
||||
int trimmedLength = isGroup ? StringUtil.trimToFit(s.toString(), MAX_GROUP_NAME_LENGTH).length()
|
||||
: StringUtil.trimToFit(s.toString(), ProfileName.MAX_PART_LENGTH).length();
|
||||
private static void trimInPlace(Editable s) {
|
||||
int trimmedLength = StringUtil.trimToFit(s.toString(), ProfileName.MAX_PART_LENGTH).length();
|
||||
|
||||
if (s.length() > trimmedLength) {
|
||||
s.delete(trimmedLength, s.length());
|
||||
|
@@ -14,7 +14,6 @@ import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.groups.SelectionLimits;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
||||
import org.thoughtcrime.securesms.jobs.RemoteConfigRefreshJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
|
||||
@@ -53,6 +52,7 @@ public final class FeatureFlags {
|
||||
private static final String USERNAMES = "android.usernames";
|
||||
private static final String GROUPS_V2_RECOMMENDED_LIMIT = "global.groupsv2.maxGroupSize";
|
||||
private static final String GROUPS_V2_HARD_LIMIT = "global.groupsv2.groupSizeHardLimit";
|
||||
private static final String GROUP_NAME_MAX_LENGTH = "global.groupsv2.maxNameLength";
|
||||
private static final String INTERNAL_USER = "android.internalUser";
|
||||
private static final String VERIFY_V2 = "android.verifyV2";
|
||||
private static final String PHONE_NUMBER_PRIVACY_VERSION = "android.phoneNumberPrivacyVersion";
|
||||
@@ -89,7 +89,8 @@ public final class FeatureFlags {
|
||||
GROUP_CALLING,
|
||||
SEND_VIEWED_RECEIPTS,
|
||||
CUSTOM_VIDEO_MUXER,
|
||||
CDS_REFRESH_INTERVAL
|
||||
CDS_REFRESH_INTERVAL,
|
||||
GROUP_NAME_MAX_LENGTH
|
||||
);
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -122,7 +123,8 @@ public final class FeatureFlags {
|
||||
GROUP_CALLING,
|
||||
GV1_MIGRATION_JOB,
|
||||
CUSTOM_VIDEO_MUXER,
|
||||
CDS_REFRESH_INTERVAL
|
||||
CDS_REFRESH_INTERVAL,
|
||||
GROUP_NAME_MAX_LENGTH
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -278,6 +280,11 @@ public final class FeatureFlags {
|
||||
return getInteger(CDS_REFRESH_INTERVAL, (int) TimeUnit.HOURS.toSeconds(48));
|
||||
}
|
||||
|
||||
/** The maximum number of grapheme */
|
||||
public static int getMaxGroupNameGraphemeLength() {
|
||||
return Math.max(32, getInteger(GROUP_NAME_MAX_LENGTH, -1));
|
||||
}
|
||||
|
||||
/** Only for rendering debug info. */
|
||||
public static synchronized @NonNull Map<String, Object> getMemoryValues() {
|
||||
return new TreeMap<>(REMOTE_VALUES);
|
||||
|
@@ -33,7 +33,6 @@
|
||||
android:background="@null"
|
||||
android:hint="@string/AddGroupDetailsFragment__group_name_required"
|
||||
android:inputType="text"
|
||||
android:maxLength="34"
|
||||
android:maxLines="1"
|
||||
app:layout_constraintBottom_toBottomOf="@id/group_avatar"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
Reference in New Issue
Block a user