user 6 tahun lalu
induk
melakukan
d54bbf1b8e
4 mengubah file dengan 20 tambahan dan 6 penghapusan
  1. 1 0
      lib/index.d.ts
  2. 9 3
      lib/index.js
  3. 1 1
      lib/index.js.map
  4. 9 2
      src/index.ts

+ 1 - 0
lib/index.d.ts

@@ -30,6 +30,7 @@ export declare class BankClient {
     retrievePrivate(peerAddr: string, topic: string): Promise<string>;
     subscribePrivate(peerAddr: string, topic: string, connectCallback: () => void, messageCallback: (data: any) => void): Promise<void>;
     getOrCreateContact(peerId: string, addressType: string, addressValue: string): Promise<ContactItem>;
+    createContact(peerId: string, addressType?: string, addressValue?: string): Promise<ContactItem>;
     getAllContacts(peerId: string): Promise<ContactItem[]>;
     getContactBook(peerId: string): Promise<ContactBook>;
     updateContact(peerId: string, contactId: string, newProperties: any): Promise<ContactItem>;

+ 9 - 3
lib/index.js

@@ -240,13 +240,19 @@ class BankClient {
             if (existing != null) {
                 return existing;
             }
+            return yield this.createContact(peerId, addressType, addressValue);
+        });
+    }
+    createContact(peerId, addressType, addressValue) {
+        return __awaiter(this, void 0, void 0, function* () {
             const contactId = util_1.uuid();
             const newItem = {
-                addrs: [
-                    new contact_address_1.ContactAddress(addressType, addressValue).toPrefixedString()
-                ],
+                addrs: [],
                 id: contactId
             };
+            if (addressType != null && addressValue != null) {
+                newItem.addrs.push(new contact_address_1.ContactAddress(addressType, addressValue).toPrefixedString());
+            }
             const newItemHash = yield this.uploadSlimJSON(newItem);
             yield this.appendPrivate(peerId, '📇', newItemHash);
             const contactBook2 = yield this.getContactBook(peerId);

File diff ditekan karena terlalu besar
+ 1 - 1
lib/index.js.map


+ 9 - 2
src/index.ts

@@ -233,13 +233,20 @@ export class BankClient {
       if (existing != null) {
         return existing;
       }
+      return await this.createContact(peerId, addressType, addressValue);
+    }
+
+    public async createContact(peerId: string, addressType?: string, addressValue?: string): Promise<ContactItem> {
       const contactId = uuid();
-      const newItem = {
+      const newItem:any = {
         addrs: [
-          new ContactAddress(addressType, addressValue).toPrefixedString()
+          
         ],
         id: contactId
       };
+      if (addressType != null && addressValue != null) {
+        newItem.addrs.push(new ContactAddress(addressType, addressValue).toPrefixedString());
+      }
       const newItemHash = await this.uploadSlimJSON(newItem);
       await this.appendPrivate(peerId, '📇', newItemHash);
       const contactBook2 = await this.getContactBook(peerId);