user 6 years ago
parent
commit
08c6690aa8
4 changed files with 47 additions and 1 deletions
  1. 2 0
      lib/contact-item.d.ts
  2. 21 0
      lib/contact-item.js
  3. 1 1
      lib/contact-item.js.map
  4. 23 0
      src/contact-item.ts

+ 2 - 0
lib/contact-item.d.ts

@@ -11,6 +11,8 @@ export declare class ContactItem {
     matchesAddressOrName(search: string): boolean;
     matchesGroup(group: string): boolean;
     getFirstEmail(): string | undefined;
+    getFirstPhone(): string | undefined;
     getMatchingAddresses(search: string): string[];
+    getName(): string;
     getData(): ContactParams;
 }

+ 21 - 0
lib/contact-item.js

@@ -29,9 +29,30 @@ class ContactItem {
         }
         return prefixed.substring(6);
     }
+    getFirstPhone() {
+        const prefixed = this.addrs.filter(x => x.startsWith('phone:'))[0];
+        if (prefixed == null) {
+            return undefined;
+        }
+        return prefixed.substring(6);
+    }
     getMatchingAddresses(search) {
         return this.addrs.filter(x => x.indexOf(search) >= 0);
     }
+    getName() {
+        if (this.names.length > 0) {
+            return this.names[0];
+        }
+        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,

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


+ 23 - 0
src/contact-item.ts

@@ -42,10 +42,33 @@ export class ContactItem {
       return prefixed.substring(6);
   }
 
+  public getFirstPhone(): string | undefined {
+    const prefixed = this.addrs.filter(x => x.startsWith('phone:'))[0];
+    if (prefixed == null) {
+        return undefined;
+    }
+    return prefixed.substring(6);
+}
+
   public getMatchingAddresses(search: string): string[] {
       return this.addrs.filter(x => x.indexOf(search) >= 0);
   }
 
+  public getName(): string {
+    if (this.names.length > 0) {
+      return this.names[0];
+    }
+    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,