diff options
author | Marvin Borner | 2019-01-30 21:18:52 +0100 |
---|---|---|
committer | Marvin Borner | 2019-01-30 21:18:52 +0100 |
commit | 70425d5662e0f6592ca73f4fa48c705a130ebe5c (patch) | |
tree | f627a11cedd41e558c3eecde62076b68d41e6af8 /public/scripts/chat.js | |
parent | d1b2addcf3d33bb5a261c54f88b4d6130aa8952f (diff) |
Fixed message storing
Diffstat (limited to 'public/scripts/chat.js')
-rw-r--r-- | public/scripts/chat.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/public/scripts/chat.js b/public/scripts/chat.js index cc224c2..13c7839 100644 --- a/public/scripts/chat.js +++ b/public/scripts/chat.js @@ -93,7 +93,8 @@ function chat() { connectedPeer = conn; console.log('[LOG] Connected with', connectedPeer.peer); encryption.getMsgs(connectedPeer.peer, await encryption.get(connectedPeer.peer), await encryption.getPrivate(), passphrase).then(messages => - messages.forEach(data => receivedMessage(`${data.message} - ${data.time}`, true))); + messages.forEach(async data => await receivedMessage(`${data.message} - ${data.time}`, true)) + ); connectedPeer.on('open', async () => transferKey(await encryption.getPublic())); connectedPeer.on('data', async message => { console.log('[LOG] Received new message!'); @@ -113,7 +114,8 @@ function chat() { connectedPeer = peer.connect(id, {label: connectionId, reliable: true}); console.log('[LOG] Connected with', connectedPeer.peer); encryption.getMsgs(connectedPeer.peer, await encryption.get(connectedPeer.peer), await encryption.getPrivate(), passphrase).then(messages => - messages.forEach(data => receivedMessage(`${data.message} - ${data.time}`, true))); + messages.forEach(async data => await receivedMessage(`${data.message} - ${data.time}`, true)) + ); connectedPeer.on('open', async () => transferKey(await encryption.getPublic())); connectedPeer.on('data', async message => { console.log('[LOG] Received new message!'); @@ -154,7 +156,7 @@ function chat() { $('#messages').append(`<span style="color: green">${message}</span><br>`); } else { if (message.type === 'text') { - await encryption.storeMsg(peerId, message.data); + await encryption.storeMsg(connectedPeer.peer, message.data); await encryption.decrypt(message.data, await encryption.get(connectedPeer.peer), await encryption.getPrivate(), passphrase) .then(plaintext => $('#messages').append(`${plaintext}<br>`)); } else if (message.type === 'key') { |