contact-item.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.addrs = (props.addrs || []).map(addrString => contact_address_1.ContactAddress.fromPrefixedString(addrString));
  10. this.groups = props.groups || [];
  11. this.alternateNames = props.alternateNames || [];
  12. this.name = props.name || '';
  13. this.me = props.me;
  14. this.lastSent = props.lastSent ? new Date(props.lastSent) : undefined;
  15. this.lastReceived = props.lastReceived ? new Date(props.lastReceived) : undefined;
  16. this.lastChanged = props.lastChanged ? new Date(props.lastChanged) : undefined;
  17. this.notes = props.notes || '';
  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 first = this.addrs.filter(addr => addr.type === 'email')[0];
  27. if (first == null) {
  28. return undefined;
  29. }
  30. return first.address;
  31. }
  32. getFirstPhone() {
  33. const first = this.addrs.filter(addr => addr.type === 'phone')[0];
  34. if (first == null) {
  35. return undefined;
  36. }
  37. return first.address;
  38. }
  39. getFirstUh() {
  40. const first = this.addrs.filter(addr => addr.type === 'uh')[0];
  41. if (first == null) {
  42. return undefined;
  43. }
  44. return first.address;
  45. }
  46. search(search) {
  47. if (this.name.toLowerCase().indexOf(search.toLowerCase().trim()) >= 0) {
  48. return true;
  49. }
  50. if (this.alternateNames.find(i => i.toLowerCase().trim().indexOf(search.toLowerCase().trim()) >= 0)) {
  51. return true;
  52. }
  53. if (this.addrs.find(addr => addr.matches(search))) {
  54. return true;
  55. }
  56. return false;
  57. }
  58. getMatchingAddresses(search) {
  59. return this.addrs.filter(addr => addr.matches(search));
  60. }
  61. matchesAddressExactly(addressType, addressValue) {
  62. if (this.addrs.find(addr => addr.matchesExactly(addressType, addressValue))) {
  63. return true;
  64. }
  65. return false;
  66. }
  67. ensureAlternateNameExists(altName) {
  68. if (!this.alternateNames.includes(altName)) {
  69. this.alternateNames.push(altName);
  70. }
  71. }
  72. // public generateName() {
  73. // const firstEmail = this.getFirstEmail();
  74. // if (firstEmail != null) {
  75. // return firstEmail;
  76. // }
  77. // const firstPhone = this.getFirstPhone();
  78. // if (firstPhone != null) {
  79. // return firstPhone;
  80. // }
  81. // return 'New contact ' + this.id.substring(0,8);
  82. // }
  83. getData() {
  84. return {
  85. addrs: this.addrs.map(addr => addr.toPrefixedString()),
  86. alternateNames: this.alternateNames.map(x => x),
  87. groups: this.groups,
  88. hash: this.hash,
  89. id: this.id,
  90. lastChanged: this.lastChanged ? this.lastChanged.toISOString() : undefined,
  91. lastReceived: this.lastReceived ? this.lastReceived.toISOString() : undefined,
  92. lastSent: this.lastSent ? this.lastSent.toISOString() : undefined,
  93. me: this.me,
  94. name: this.name,
  95. notes: this.notes
  96. };
  97. }
  98. }
  99. exports.ContactItem = ContactItem;
  100. //# sourceMappingURL=contact-item.js.map