|
|
@@ -6,24 +6,29 @@ export class ContactItem {
|
|
|
public readonly data: ContactParams;
|
|
|
public readonly id: string;
|
|
|
public readonly hash: string;
|
|
|
+ public name: string;
|
|
|
public addrs: ContactAddress[];
|
|
|
+ public me: boolean;
|
|
|
public groups: string[];
|
|
|
- public names: string[];
|
|
|
+ public alternateNames: string[];
|
|
|
public notes: string;
|
|
|
- public canSendFromAddrs: ContactAddress[];
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ public lastSent?: Date;
|
|
|
+ public lastReceived?: Date;
|
|
|
+ public lastChanged?: Date;
|
|
|
+
|
|
|
constructor(props: ContactParams) {
|
|
|
this.data = props;
|
|
|
this.hash = props.hash;
|
|
|
this.id = props.id;
|
|
|
- this.canSendFromAddrs = (props.canSendFromAddrs || []).map(addrString => ContactAddress.fromPrefixedString(addrString));
|
|
|
this.addrs = (props.addrs || []).map(addrString => ContactAddress.fromPrefixedString(addrString));
|
|
|
this.groups = props.groups || [];
|
|
|
- this.names = props.names || [];
|
|
|
- if (this.names.length === 0) {
|
|
|
- this.names.push(this.generateName());
|
|
|
- }
|
|
|
+ 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 || '';
|
|
|
}
|
|
|
|
|
|
@@ -51,7 +56,10 @@ export class ContactItem {
|
|
|
}
|
|
|
|
|
|
public search(search: string): boolean {
|
|
|
- if (this.names.find(i => i.toLowerCase().trim().indexOf(search.toLowerCase().trim()) >= 0)) {
|
|
|
+ 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))) {
|
|
|
@@ -71,35 +79,33 @@ export class ContactItem {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public generateName() {
|
|
|
- const firstEmail = this.getFirstEmail();
|
|
|
- if (firstEmail != null) {
|
|
|
- return firstEmail;
|
|
|
+ public ensureAlternateNameExists(altName: string) {
|
|
|
+ if (!this.alternateNames.includes(altName)) {
|
|
|
+ this.alternateNames.push(altName);
|
|
|
}
|
|
|
- const firstPhone = this.getFirstPhone();
|
|
|
- if (firstPhone != null) {
|
|
|
- return firstPhone;
|
|
|
- }
|
|
|
- return 'New contact ' + this.id.substring(0,8);
|
|
|
}
|
|
|
|
|
|
- public getName(): string {
|
|
|
- if (this.names.length > 0) {
|
|
|
- return this.names[0];
|
|
|
- } else {
|
|
|
- return '';
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ // 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);
|
|
|
+ // }
|
|
|
|
|
|
public getData(): ContactParams {
|
|
|
return {
|
|
|
addrs: this.addrs.map(addr => addr.toPrefixedString()),
|
|
|
- canSendFromAddrs: this.canSendFromAddrs.map(addr => addr.toPrefixedString()),
|
|
|
+ alternateNames: this.alternateNames.map(x => x),
|
|
|
groups: this.groups,
|
|
|
hash: this.hash,
|
|
|
id: this.id,
|
|
|
- names: this.names,
|
|
|
+ me: this.me,
|
|
|
+ name: this.name,
|
|
|
notes: this.notes
|
|
|
};
|
|
|
}
|