| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- "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.canSendFromAddrs = (props.canSendFromAddrs || []).map(addrString => contact_address_1.ContactAddress.fromPrefixedString(addrString));
- this.addrs = (props.addrs || []).map(addrString => contact_address_1.ContactAddress.fromPrefixedString(addrString));
- this.groups = props.groups || [];
- this.names = props.names || [];
- if (this.names.length === 0) {
- this.names.push(this.generateName());
- }
- 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.names.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;
- }
- 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);
- }
- getName() {
- if (this.names.length > 0) {
- return this.names[0];
- }
- else {
- return '';
- }
- }
- getData() {
- return {
- addrs: this.addrs.map(addr => addr.toPrefixedString()),
- canSendFromAddrs: this.canSendFromAddrs.map(addr => addr.toPrefixedString()),
- groups: this.groups,
- hash: this.hash,
- id: this.id,
- names: this.names,
- notes: this.notes
- };
- }
- }
- exports.ContactItem = ContactItem;
- //# sourceMappingURL=contact-item.js.map
|