More permissive username search
This commit is contained in:
parent
89525d3e16
commit
4a41e87173
17 changed files with 121 additions and 31 deletions
|
@ -1,7 +1,10 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { usernames } from '@signalapp/libsignal-client';
|
||||
|
||||
import * as RemoteConfig from '../RemoteConfig';
|
||||
import { getNickname } from '../types/Username';
|
||||
import { parseIntWithFallback } from './parseIntWithFallback';
|
||||
|
||||
export function getMaxNickname(): number {
|
||||
|
@ -13,3 +16,26 @@ export function getMaxNickname(): number {
|
|||
export function getMinNickname(): number {
|
||||
return parseIntWithFallback(RemoteConfig.getValue('global.nicknames.min'), 3);
|
||||
}
|
||||
|
||||
export function getUsernameFromSearch(searchTerm: string): string | undefined {
|
||||
const nickname = getNickname(searchTerm);
|
||||
if (nickname == null || nickname.length < getMinNickname()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let modifiedTerm = searchTerm;
|
||||
if (searchTerm.endsWith('.')) {
|
||||
// Allow nicknames without full discriminator
|
||||
modifiedTerm = `${searchTerm}01`;
|
||||
} else if (!/\.\d*$/.test(searchTerm)) {
|
||||
// Allow nicknames without discriminator
|
||||
modifiedTerm = `${searchTerm}.01`;
|
||||
}
|
||||
|
||||
try {
|
||||
usernames.hash(modifiedTerm);
|
||||
return searchTerm;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue