Add filter commands for finding conversations
This commit is contained in:
parent
472df5821a
commit
de0450efe7
1 changed files with 33 additions and 0 deletions
|
@ -42,6 +42,29 @@ const cachedIndices = new WeakMap<
|
||||||
Fuse<ConversationType>
|
Fuse<ConversationType>
|
||||||
>();
|
>();
|
||||||
|
|
||||||
|
type CommandRunnerType = (
|
||||||
|
conversations: ReadonlyArray<ConversationType>,
|
||||||
|
query: string
|
||||||
|
) => Array<ConversationType>;
|
||||||
|
|
||||||
|
const COMMANDS = new Map<string, CommandRunnerType>();
|
||||||
|
|
||||||
|
COMMANDS.set('uuidEndsWith', (conversations, query) => {
|
||||||
|
return conversations.filter(convo => convo.uuid?.endsWith(query));
|
||||||
|
});
|
||||||
|
|
||||||
|
COMMANDS.set('idEndsWith', (conversations, query) => {
|
||||||
|
return conversations.filter(convo => convo.id?.endsWith(query));
|
||||||
|
});
|
||||||
|
|
||||||
|
COMMANDS.set('e164EndsWith', (conversations, query) => {
|
||||||
|
return conversations.filter(convo => convo.e164?.endsWith(query));
|
||||||
|
});
|
||||||
|
|
||||||
|
COMMANDS.set('groupIdEndsWith', (conversations, query) => {
|
||||||
|
return conversations.filter(convo => convo.groupId?.endsWith(query));
|
||||||
|
});
|
||||||
|
|
||||||
// See https://fusejs.io/examples.html#extended-search for
|
// See https://fusejs.io/examples.html#extended-search for
|
||||||
// extended search documentation.
|
// extended search documentation.
|
||||||
function searchConversations(
|
function searchConversations(
|
||||||
|
@ -49,6 +72,16 @@ function searchConversations(
|
||||||
searchTerm: string,
|
searchTerm: string,
|
||||||
regionCode: string | undefined
|
regionCode: string | undefined
|
||||||
): Array<ConversationType> {
|
): Array<ConversationType> {
|
||||||
|
const maybeCommand = searchTerm.match(/^!([^\s]+):(.*)$/);
|
||||||
|
if (maybeCommand) {
|
||||||
|
const [, commandName, query] = maybeCommand;
|
||||||
|
|
||||||
|
const command = COMMANDS.get(commandName);
|
||||||
|
if (command) {
|
||||||
|
return command(conversations, query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const phoneNumber = parseAndFormatPhoneNumber(searchTerm, regionCode);
|
const phoneNumber = parseAndFormatPhoneNumber(searchTerm, regionCode);
|
||||||
|
|
||||||
// Escape the search term
|
// Escape the search term
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue