user 6 jaren geleden
bovenliggende
commit
7148032246
9 gewijzigde bestanden met toevoegingen van 103 en 76 verwijderingen
  1. 10 6
      lib/contact-book.js
  2. 1 1
      lib/contact-book.js.map
  3. 7 4
      lib/contact-item.d.ts
  4. 27 25
      lib/contact-item.js
  5. 1 1
      lib/contact-item.js.map
  6. 6 2
      lib/contact-params.d.ts
  7. 10 6
      src/contact-book.ts
  8. 35 29
      src/contact-item.ts
  9. 6 2
      src/contact-params.ts

+ 10 - 6
lib/contact-book.js

@@ -14,9 +14,11 @@ class ContactBook {
     getFromPhoneNumbers() {
         const result = [];
         for (const item of this.items) {
-            for (const address of item.canSendFromAddrs) {
-                if (address.type === 'phone') {
-                    result.push(contact_address_1.ContactAddress.formatPhoneNumber(address.address));
+            if (item.me) {
+                for (const address of item.addrs) {
+                    if (address.type === 'phone') {
+                        result.push(contact_address_1.ContactAddress.formatPhoneNumber(address.address));
+                    }
                 }
             }
         }
@@ -25,9 +27,11 @@ class ContactBook {
     getFromEmailAddresses() {
         const result = [];
         for (const item of this.items) {
-            for (const address of item.canSendFromAddrs) {
-                if (address.type === 'email') {
-                    result.push(address.address);
+            if (item.me) {
+                for (const address of item.addrs) {
+                    if (address.type === 'email') {
+                        result.push(address.address);
+                    }
                 }
             }
         }

File diff suppressed because it is too large
+ 1 - 1
lib/contact-book.js.map


+ 7 - 4
lib/contact-item.d.ts

@@ -4,11 +4,15 @@ export declare class ContactItem {
     readonly data: ContactParams;
     readonly id: string;
     readonly hash: string;
+    name: string;
     addrs: ContactAddress[];
+    me: boolean;
     groups: string[];
-    names: string[];
+    alternateNames: string[];
     notes: string;
-    canSendFromAddrs: ContactAddress[];
+    lastSent?: Date;
+    lastReceived?: Date;
+    lastChanged?: Date;
     constructor(props: ContactParams);
     matchesGroup(group: string): boolean;
     getFirstEmail(): string | undefined;
@@ -16,7 +20,6 @@ export declare class ContactItem {
     search(search: string): boolean;
     getMatchingAddresses(search: string): ContactAddress[];
     matchesAddressExactly(addressType: string, addressValue: string): boolean;
-    generateName(): string;
-    getName(): string;
+    ensureAlternateNameExists(altName: string): void;
     getData(): ContactParams;
 }

+ 27 - 25
lib/contact-item.js

@@ -6,13 +6,14 @@ class ContactItem {
         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.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) {
@@ -36,7 +37,10 @@ class ContactItem {
         return first.address;
     }
     search(search) {
-        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))) {
@@ -53,33 +57,31 @@ class ContactItem {
         }
         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 '';
+    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()),
-            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
         };
     }

File diff suppressed because it is too large
+ 1 - 1
lib/contact-item.js.map


+ 6 - 2
lib/contact-params.d.ts

@@ -1,9 +1,13 @@
 export interface ContactParams {
     id: string;
     hash: string;
-    names: string[];
+    name: string;
     addrs: string[];
+    me: boolean;
     groups: string[];
+    alternateNames: string[];
     notes: string;
-    canSendFromAddrs: string[];
+    lastSent?: Date;
+    lastReceived?: Date;
+    lastChanged?: Date;
 }

+ 10 - 6
src/contact-book.ts

@@ -20,9 +20,11 @@ export class ContactBook {
   public getFromPhoneNumbers(): string[] {
     const result: string[] = [];
     for (const item of this.items) {
-      for (const address of item.canSendFromAddrs) {
-        if (address.type === 'phone') {
-          result.push(ContactAddress.formatPhoneNumber(address.address));
+      if (item.me) {
+        for (const address of item.addrs) {
+          if (address.type === 'phone') {
+            result.push(ContactAddress.formatPhoneNumber(address.address));
+          }
         }
       }
     }
@@ -32,9 +34,11 @@ export class ContactBook {
   public getFromEmailAddresses(): string[] {
     const result: string[] = [];
     for (const item of this.items) {
-      for (const address of item.canSendFromAddrs) {
-        if (address.type === 'email') {
-          result.push(address.address);
+      if (item.me) {
+        for (const address of item.addrs) {
+          if (address.type === 'email') {
+            result.push(address.address);
+          }
         }
       }
     }

+ 35 - 29
src/contact-item.ts

@@ -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
     };
   }

+ 6 - 2
src/contact-params.ts

@@ -1,9 +1,13 @@
 export interface ContactParams {
     id: string;
     hash: string;
-    names: string[];
+    name: string;
     addrs: string[];
+    me: boolean;
     groups: string[];
+    alternateNames: string[];
     notes: string;
-    canSendFromAddrs: string[];
+    lastSent?: Date;
+    lastReceived?: Date;
+    lastChanged?: Date;
 }