contact-item.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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;
  15. this.lastReceived = props.lastReceived;
  16. this.lastChanged = props.lastChanged;
  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. search(search) {
  40. if (this.name.toLowerCase().indexOf(search.toLowerCase().trim()) >= 0) {
  41. return true;
  42. }
  43. if (this.alternateNames.find(i => i.toLowerCase().trim().indexOf(search.toLowerCase().trim()) >= 0)) {
  44. return true;
  45. }
  46. if (this.addrs.find(addr => addr.matches(search))) {
  47. return true;
  48. }
  49. return false;
  50. }
  51. getMatchingAddresses(search) {
  52. return this.addrs.filter(addr => addr.matches(search));
  53. }
  54. matchesAddressExactly(addressType, addressValue) {
  55. if (this.addrs.find(addr => addr.matchesExactly(addressType, addressValue))) {
  56. return true;
  57. }
  58. return false;
  59. }
  60. ensureAlternateNameExists(altName) {
  61. if (!this.alternateNames.includes(altName)) {
  62. this.alternateNames.push(altName);
  63. }
  64. }
  65. // public generateName() {
  66. // const firstEmail = this.getFirstEmail();
  67. // if (firstEmail != null) {
  68. // return firstEmail;
  69. // }
  70. // const firstPhone = this.getFirstPhone();
  71. // if (firstPhone != null) {
  72. // return firstPhone;
  73. // }
  74. // return 'New contact ' + this.id.substring(0,8);
  75. // }
  76. getData() {
  77. return {
  78. addrs: this.addrs.map(addr => addr.toPrefixedString()),
  79. alternateNames: this.alternateNames.map(x => x),
  80. groups: this.groups,
  81. hash: this.hash,
  82. id: this.id,
  83. me: this.me,
  84. name: this.name,
  85. notes: this.notes
  86. };
  87. }
  88. }
  89. exports.ContactItem = ContactItem;
  90. //# sourceMappingURL=contact-item.js.map