contact-item.js 2.0 KB

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