contact-item.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { ContactParams } from "./contact-params";
  2. export class ContactItem {
  3. public readonly data: ContactParams;
  4. public readonly id: string;
  5. public readonly hash: string;
  6. public readonly addrs: string[];
  7. public readonly groups: string[];
  8. constructor(props: ContactParams) {
  9. this.data = props;
  10. this.hash = props.hash;
  11. this.id = props.id;
  12. this.addrs = props.addrs || [];
  13. this.groups = props.groups || [];
  14. }
  15. public matchesAddressOrName(search: string): boolean {
  16. if (this.addrs.filter(x => x.indexOf(search.trim()) >= 0).length > 0) {
  17. return true;
  18. }
  19. return false;
  20. }
  21. public matchesGroup(group: string): boolean {
  22. if (this.groups.filter(x => x === group.trim())[0].length > 0) {
  23. return true;
  24. }
  25. return false;
  26. }
  27. public getFirstEmail(): string | undefined {
  28. const prefixed = this.addrs.filter(x => x.startsWith('email:'))[0];
  29. if (prefixed == null) {
  30. return undefined;
  31. }
  32. return prefixed.substring(6);
  33. }
  34. public getMatchingAddresses(search: string): string[] {
  35. return this.addrs.filter(x => x.indexOf(search) >= 0);
  36. }
  37. }