| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- const contact_address_1 = require("./contact-address");
- class ContactItem {
- constructor(props) {
- this.data = props;
- this.hash = props.hash;
- this.id = props.id;
- this.addrs = (props.addrs || []).map(addrString => contact_address_1.ContactAddress.fromPrefixedString(addrString));
- this.groups = props.groups || [];
- this.alternateNames = props.alternateNames || [];
- this.name = props.name || '';
- this.me = props.me;
- this.lastSent = props.lastSent ? new Date(props.lastSent) : undefined;
- this.lastReceived = props.lastReceived ? new Date(props.lastReceived) : undefined;
- this.lastChanged = props.lastChanged ? new Date(props.lastChanged) : undefined;
- this.notes = props.notes || '';
- }
- matchesGroup(group) {
- if (this.groups.filter(x => x === group.trim())[0].length > 0) {
- return true;
- }
- return false;
- }
- getFirstEmail() {
- const first = this.addrs.filter(addr => addr.type === 'email')[0];
- if (first == null) {
- return undefined;
- }
- return first.address;
- }
- getFirstPhone() {
- const first = this.addrs.filter(addr => addr.type === 'phone')[0];
- if (first == null) {
- return undefined;
- }
- return first.address;
- }
- search(search) {
- if (this.name.toLowerCase().indexOf(search.toLowerCase().trim()) >= 0) {
- return true;
- }
- if (this.alternateNames.find(i => i.toLowerCase().trim().indexOf(search.toLowerCase().trim()) >= 0)) {
- return true;
- }
- if (this.addrs.find(addr => addr.matches(search))) {
- return true;
- }
- return false;
- }
- getMatchingAddresses(search) {
- return this.addrs.filter(addr => addr.matches(search));
- }
- matchesAddressExactly(addressType, addressValue) {
- if (this.addrs.find(addr => addr.matchesExactly(addressType, addressValue))) {
- return true;
- }
- return false;
- }
- ensureAlternateNameExists(altName) {
- if (!this.alternateNames.includes(altName)) {
- this.alternateNames.push(altName);
- }
- }
- // public generateName() {
- // const firstEmail = this.getFirstEmail();
- // if (firstEmail != null) {
- // return firstEmail;
- // }
- // const firstPhone = this.getFirstPhone();
- // if (firstPhone != null) {
- // return firstPhone;
- // }
- // return 'New contact ' + this.id.substring(0,8);
- // }
- getData() {
- return {
- addrs: this.addrs.map(addr => addr.toPrefixedString()),
- alternateNames: this.alternateNames.map(x => x),
- groups: this.groups,
- hash: this.hash,
- id: this.id,
- lastChanged: this.lastChanged ? this.lastChanged.toISOString() : undefined,
- lastReceived: this.lastReceived ? this.lastReceived.toISOString() : undefined,
- lastSent: this.lastSent ? this.lastSent.toISOString() : undefined,
- me: this.me,
- name: this.name,
- notes: this.notes
- };
- }
- }
- exports.ContactItem = ContactItem;
- //# sourceMappingURL=contact-item.js.map
|