| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { ContactParams } from "./contact-params";
- export class ContactItem {
- public readonly data: ContactParams;
- public readonly id: string;
- public readonly hash: string;
- public readonly addrs: string[];
- public readonly groups: string[];
-
- constructor(props: ContactParams) {
- this.data = props;
- this.hash = props.hash;
- this.id = props.id;
- this.addrs = props.addrs || [];
- this.groups = props.groups || [];
- }
- public matchesAddressOrName(search: string): boolean {
- if (this.addrs.filter(x => x.indexOf(search.trim()) >= 0).length > 0) {
- return true;
- }
- return false;
- }
- public matchesGroup(group: string): boolean {
- if (this.groups.filter(x => x === group.trim())[0].length > 0) {
- return true;
- }
- return false;
- }
- public getFirstEmail(): string | undefined {
- const prefixed = this.addrs.filter(x => x.startsWith('email:'))[0];
- if (prefixed == null) {
- return undefined;
- }
- return prefixed.substring(6);
- }
- public getMatchingAddresses(search: string): string[] {
- return this.addrs.filter(x => x.indexOf(search) >= 0);
- }
- }
|