mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 08:09:12 +01:00
Add initial username link screen + QR code generation.
This commit is contained in:
committed by
Alex Hart
parent
e0c06615fb
commit
855e194baa
@@ -32,6 +32,10 @@ public class UsernameUtil {
|
||||
private static final Pattern FULL_PATTERN = Pattern.compile(String.format(Locale.US, "^[a-zA-Z_][a-zA-Z0-9_]{%d,%d}$", MIN_LENGTH - 1, MAX_LENGTH - 1), Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern DIGIT_START_PATTERN = Pattern.compile("^[0-9].*$");
|
||||
|
||||
|
||||
private static final String BASE_URL_SCHEMELESS = "signal.me/#u/";
|
||||
private static final String BASE_URL = "https://" + BASE_URL_SCHEMELESS;
|
||||
|
||||
public static boolean isValidUsernameForSearch(@Nullable String value) {
|
||||
return !TextUtils.isEmpty(value) && !DIGIT_START_PATTERN.matcher(value).matches();
|
||||
}
|
||||
@@ -87,6 +91,13 @@ public class UsernameUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateLink(String username) throws BaseUsernameException {
|
||||
byte[] hash = Username.hash(username);
|
||||
String base64 = Base64UrlSafe.encodeBytesWithoutPadding(hash);
|
||||
|
||||
return BASE_URL + base64;
|
||||
}
|
||||
|
||||
public enum InvalidReason {
|
||||
TOO_SHORT, TOO_LONG, INVALID_CHARACTERS, STARTS_WITH_NUMBER
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user