Add filter commands for finding conversations
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
parent
f5b3785aa0
commit
050a1bf789
|
@ -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…
Reference in New Issue