user 6 anos atrás
pai
commit
469aa8048e
4 arquivos alterados com 17 adições e 9 exclusões
  1. 1 0
      lib/index.d.ts
  2. 8 4
      lib/index.js
  3. 1 1
      lib/index.js.map
  4. 7 4
      src/index.ts

+ 1 - 0
lib/index.d.ts

@@ -28,6 +28,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, contactAddr: string): Promise<any>;
+    getAllContacts(peerId: string): Promise<any[]>;
     getContactById(peerId: string, contactId: string): Promise<any>;
     updateContact(peerId: string, contactId: string, newProperties: any): Promise<any>;
     getContentItemByHash(hash: string): Promise<ContentItem>;

+ 8 - 4
lib/index.js

@@ -235,8 +235,7 @@ class BankClient {
     }
     getOrCreateContact(peerId, contactAddr) {
         return __awaiter(this, void 0, void 0, function* () {
-            const contactList = yield this.retrievePrivate(peerId, '📇');
-            const itemList = yield this.getItemsForCommaList(contactList);
+            const itemList = yield this.getAllContacts(peerId);
             // console.log('contact hash for', contact, type, 'is', contactHash);
             const existing = itemList.filter(item => item.addrs && item.addrs.includes(contactAddr))[0];
             if (existing != null) {
@@ -253,10 +252,15 @@ class BankClient {
             return newItem;
         });
     }
-    getContactById(peerId, contactId) {
+    getAllContacts(peerId) {
         return __awaiter(this, void 0, void 0, function* () {
             const contactList = yield this.retrievePrivate(peerId, '📇');
-            const itemList = yield this.getItemsForCommaList(contactList);
+            return yield this.getItemsForCommaList(contactList);
+        });
+    }
+    getContactById(peerId, contactId) {
+        return __awaiter(this, void 0, void 0, function* () {
+            const itemList = yield this.getAllContacts(peerId);
             const existing = itemList.filter(item => item.id === contactId)[0];
             if (!existing) {
                 throw new Error('Cannot find contact with id ' + contactId);

Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 1
lib/index.js.map


+ 7 - 4
src/index.ts

@@ -228,8 +228,7 @@ export class BankClient {
     }
 
     public async getOrCreateContact(peerId: string, contactAddr: string) {
-      const contactList = await this.retrievePrivate(peerId, '📇');
-      const itemList = await this.getItemsForCommaList(contactList);
+      const itemList = await this.getAllContacts(peerId);
       // console.log('contact hash for', contact, type, 'is', contactHash);
       const existing = itemList.filter(item => item.addrs && item.addrs.includes(contactAddr))[0];
       if (existing != null) {
@@ -246,9 +245,13 @@ export class BankClient {
       return newItem;
     }
 
-    public async getContactById(peerId: string, contactId: string) {
+    public async getAllContacts(peerId: string) {
       const contactList = await this.retrievePrivate(peerId, '📇');
-      const itemList = await this.getItemsForCommaList(contactList);
+      return await this.getItemsForCommaList(contactList);
+    }
+
+    public async getContactById(peerId: string, contactId: string) {
+      const itemList = await this.getAllContacts(peerId);
       const existing = itemList.filter(item => item.id === contactId)[0];
       if (!existing) {
         throw new Error('Cannot find contact with id ' + contactId);