|
|
@@ -10,17 +10,20 @@ export class ContactItem {
|
|
|
public groups: string[];
|
|
|
public names: string[];
|
|
|
public notes: string;
|
|
|
- public canSendFromAddrs: string[];
|
|
|
+ public canSendFromAddrs: ContactAddress[];
|
|
|
|
|
|
|
|
|
constructor(props: ContactParams) {
|
|
|
this.data = props;
|
|
|
this.hash = props.hash;
|
|
|
this.id = props.id;
|
|
|
- this.canSendFromAddrs = props.canSendFromAddrs || [];
|
|
|
+ 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.notes = props.notes || '';
|
|
|
}
|
|
|
|
|
|
@@ -64,10 +67,7 @@ export class ContactItem {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public getName(): string {
|
|
|
- if (this.names.length > 0) {
|
|
|
- return this.names[0];
|
|
|
- }
|
|
|
+ public generateName() {
|
|
|
const firstEmail = this.getFirstEmail();
|
|
|
if (firstEmail != null) {
|
|
|
return firstEmail;
|
|
|
@@ -79,10 +79,19 @@ export class ContactItem {
|
|
|
return 'New contact ' + this.id.substring(0,8);
|
|
|
}
|
|
|
|
|
|
+ public getName(): string {
|
|
|
+ if (this.names.length > 0) {
|
|
|
+ return this.names[0];
|
|
|
+ } else {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public getData(): ContactParams {
|
|
|
return {
|
|
|
addrs: this.addrs.map(addr => addr.toPrefixedString()),
|
|
|
- canSendFromAddrs: this.canSendFromAddrs,
|
|
|
+ canSendFromAddrs: this.canSendFromAddrs.map(addr => addr.toPrefixedString()),
|
|
|
groups: this.groups,
|
|
|
hash: this.hash,
|
|
|
id: this.id,
|