aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/scripts/chat.js
diff options
context:
space:
mode:
authorMarvin Borner2019-02-23 15:57:42 +0100
committerMarvin Borner2019-02-23 15:57:42 +0100
commitc50bbafc8d41b86def89dc10df4fc830a9432314 (patch)
tree5d5d2afb1f6da42c2dd2a81eb655c3ab8bf70db7 /public/scripts/chat.js
parentf817a64349fdf822718d47f155b00e9017f90bbf (diff)
Added storing of own messages
Diffstat (limited to 'public/scripts/chat.js')
-rw-r--r--public/scripts/chat.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/public/scripts/chat.js b/public/scripts/chat.js
index ef3eaef..8176102 100644
--- a/public/scripts/chat.js
+++ b/public/scripts/chat.js
@@ -165,7 +165,9 @@ function chat() {
connectedPeer.peer,
await encryption.getPeerPublicKey(connectedPeer.peer),
)
- .then(messages => messages.forEach(async messageData => receivedMessage(`${messageData.message} - ${messageData.time}`, true)));
+ .then(messages => messages.forEach(async (messageData) => {
+ await receivedMessage(messageData);
+ }));
transferKey(await encryption.getPublicKey());
} else if (data.type !== 'state') {
console.log('[LOG] Received new message!');
@@ -207,7 +209,9 @@ function chat() {
connectedPeer.peer,
await encryption.getPeerPublicKey(connectedPeer.peer),
)
- .then(messages => messages.forEach(async messageData => receivedMessage(`${messageData.message} - ${messageData.time}`, true)));
+ .then(messages => messages.forEach(async (messageData) => {
+ await receivedMessage(messageData);
+ }));
connectedPeer.on('close', () => {
swal('Disconnected!', `The connection to "${connectedPeer.peer}" has been closed!`, 'error');
});
@@ -264,6 +268,7 @@ function chat() {
if (self) {
$('#messages')
.append(`<span style="color: green">${message}</span><br>`);
+ await encryption.storeMessage(connectedPeer.peer, message, true);
} else if (message.type === 'text') {
await encryption.storeMessage(connectedPeer.peer, message.data);
await encryption.decrypt(
@@ -272,10 +277,20 @@ function chat() {
)
.then(plaintext => $('#messages')
.append(`<span>${plaintext}</span><br>`));
+ } else if (message.type === 'decrypted') {
+ if (message.self) {
+ $('#messages')
+ .append(`<span style="color: green">${message.message} - ${message.time}</span><br>`);
+ } else {
+ $('#messages')
+ .append(`<span>${message.message} - ${message.time}</span><br>`);
+ }
} else if (message.type === 'file') {
processFile(message);
} else if (message.type === 'key') {
await encryption.storePeerPublicKey(connectedPeer.peer, message.data);
+ } else {
+ console.error('Received unsupported message!');
}
}