contact-item.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. class ContactItem {
  4. constructor(props) {
  5. this.data = props;
  6. this.hash = props.hash;
  7. this.id = props.id;
  8. this.addrs = props.addrs || [];
  9. this.groups = props.groups || [];
  10. this.names = props.names || [];
  11. this.notes = props.notes || '';
  12. }
  13. matchesAddressOrName(search) {
  14. if (this.addrs.filter(x => x.indexOf(search.trim()) >= 0).length > 0) {
  15. return true;
  16. }
  17. return false;
  18. }
  19. matchesGroup(group) {
  20. if (this.groups.filter(x => x === group.trim())[0].length > 0) {
  21. return true;
  22. }
  23. return false;
  24. }
  25. getFirstEmail() {
  26. const prefixed = this.addrs.filter(x => x.startsWith('email:'))[0];
  27. if (prefixed == null) {
  28. return undefined;
  29. }
  30. return prefixed.substring(6);
  31. }
  32. getFirstPhone() {
  33. const prefixed = this.addrs.filter(x => x.startsWith('phone:'))[0];
  34. if (prefixed == null) {
  35. return undefined;
  36. }
  37. return prefixed.substring(6);
  38. }
  39. getMatchingAddresses(search) {
  40. return this.addrs.filter(x => x.indexOf(search) >= 0);
  41. }
  42. getName() {
  43. if (this.names.length > 0) {
  44. return this.names[0];
  45. }
  46. const firstEmail = this.getFirstEmail();
  47. if (firstEmail != null) {
  48. return firstEmail;
  49. }
  50. const firstPhone = this.getFirstPhone();
  51. if (firstPhone != null) {
  52. return firstPhone;
  53. }
  54. return 'New contact ' + this.id.substring(0, 8);
  55. }
  56. getData() {
  57. return {
  58. addrs: this.addrs,
  59. groups: this.groups,
  60. hash: this.hash,
  61. id: this.id,
  62. names: this.names,
  63. notes: this.notes
  64. };
  65. }
  66. }
  67. exports.ContactItem = ContactItem;
  68. //# sourceMappingURL=contact-item.js.map