1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

Enable search for sends (#249)

This commit is contained in:
Matt Gibson 2021-01-22 19:54:22 -06:00 committed by GitHub
parent 68bd93e45b
commit e1f1d7e702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import { CipherView } from '../models/view/cipherView';
import { SendView } from '../models/view/sendView';
export abstract class SearchService {
clearIndex: () => void;
@ -8,4 +9,5 @@ export abstract class SearchService {
filter?: ((cipher: CipherView) => boolean) | (((cipher: CipherView) => boolean)[]),
ciphers?: CipherView[]) => Promise<CipherView[]>;
searchCiphersBasic: (ciphers: CipherView[], query: string, deleted?: boolean) => CipherView[];
searchSends: (sends: SendView[], query: string) => SendView[];
}

View File

@ -9,6 +9,7 @@ import { SearchService as SearchServiceAbstraction } from '../abstractions/searc
import { CipherType } from '../enums/cipherType';
import { FieldType } from '../enums/fieldType';
import { UriMatchType } from '../enums/uriMatchType';
import { SendView } from '../models/view/sendView';
export class SearchService implements SearchServiceAbstraction {
private indexing = false;
@ -161,6 +162,28 @@ export class SearchService implements SearchServiceAbstraction {
});
}
searchSends(sends: SendView[], query: string) {
query = query.trim().toLocaleLowerCase();
return sends.filter(s => {
if (s.name != null && s.name.toLowerCase().indexOf(query) > -1) {
return true;
}
if (query.length >= 8 && (s.id.startsWith(query) || (s.file?.id != null && s.file.id.startsWith(query)))) {
return true;
}
if (s.notes != null && s.notes.toLowerCase().indexOf(query) > -1) {
return true;
}
if (s.text?.text != null && s.text.text.toLowerCase().indexOf(query) > -1) {
return true;
}
if (s.file?.fileName != null && s.file.fileName.toLowerCase().indexOf(query) > -1) {
return true;
}
});
}
getIndexForSearch(): lunr.Index {
return this.index;
}