"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; this.lastReceived = props.lastReceived; this.lastChanged = props.lastChanged; 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, me: this.me, name: this.name, notes: this.notes }; } } exports.ContactItem = ContactItem; //# sourceMappingURL=contact-item.js.map