contact-item.js 2.4 KB

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