From 08160492e22dd8da1cbb4decbb3481f5e6968201 Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Sun, 24 Feb 2019 17:48:02 +0100
Subject: Improved contact list

---
 public/scripts/encryption.js | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

(limited to 'public/scripts/encryption.js')

diff --git a/public/scripts/encryption.js b/public/scripts/encryption.js
index 4c0ab22..0e76b43 100644
--- a/public/scripts/encryption.js
+++ b/public/scripts/encryption.js
@@ -249,7 +249,7 @@ const self = module.exports = {
    * @returns {Promise<void>}
    */
   storePeer: async (peerId) => {
-    db.contacts.put({
+    await db.contacts.put({
       peer_id: peerId,
       fingerprint: await self.getPublicKeyFingerprint(await self.getPeerPublicKey(peerId)),
     })
@@ -257,6 +257,12 @@ const self = module.exports = {
       .catch(err => console.error(err));
   },
 
+  /**
+   * Gets every stored peer
+   * @returns {Promise<Array>}
+   */
+  getStoredPeers: async () => db.contacts.toArray(),
+
   /**
    * Gets the public fingerprint of a peer
    * @param peerId
@@ -274,12 +280,12 @@ const self = module.exports = {
    * @param key
    */
   storePeerPublicKey: async (peerId, key) => {
-    db.peer_keys.put({
+    await db.peer_keys.put({
       peer_id: peerId,
       key_data: key,
     })
-      .then(() => {
-        self.storePeer(peerId);
+      .then(async () => {
+        await self.storePeer(peerId);
         console.log(`[LOG] Stored public key of ${peerId}`);
       })
       .catch(err => console.error(err));
-- 
cgit v1.2.3