Search for username in compose mode

This commit is contained in:
Scott Nonnenberg 2021-11-11 17:17:29 -08:00 committed by GitHub
parent 6731cc6629
commit cbae7f8ee9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 997 additions and 72 deletions

20
ts/types/Username.ts Normal file
View file

@ -0,0 +1,20 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export function isValidUsername(searchTerm: string): boolean {
return /^[a-z][0-9a-z_]{2,24}$/.test(searchTerm);
}
export function getUsernameFromSearch(searchTerm: string): string | undefined {
if (/^[+0-9]+$/.test(searchTerm)) {
return undefined;
}
const match = /^@?(.*?)@?$/.exec(searchTerm);
if (match && match[1]) {
return match[1];
}
return undefined;
}