diff options
author | Marvin Borner | 2019-01-30 18:47:55 +0100 |
---|---|---|
committer | Marvin Borner | 2019-01-30 18:47:55 +0100 |
commit | d1b2addcf3d33bb5a261c54f88b4d6130aa8952f (patch) | |
tree | ec8adb35cc232b4b523935d453bd34b770864579 /public | |
parent | f4bc9e771b5f79ff95ed2069b9c1402679241ddb (diff) |
Added enter listener
Diffstat (limited to 'public')
-rw-r--r-- | public/scripts/chat.js | 13 | ||||
-rw-r--r-- | public/scripts/encryption.js | 10 |
2 files changed, 19 insertions, 4 deletions
diff --git a/public/scripts/chat.js b/public/scripts/chat.js index 056dc09..cc224c2 100644 --- a/public/scripts/chat.js +++ b/public/scripts/chat.js @@ -164,10 +164,21 @@ function chat() { } /** + * Sends a message of the text input field + * @returns {Promise<void>} + */ + async function sendMessageFromInput() { + return await sendMessage($('#message').val()) & $('#message').val('') + } + + /** * Click events */ $(document).ready(() => { - $('#send_message').on('click', async () => await sendMessage($('#message').val()) & $('#message').val('')); + $('#send_message').on('click', async () => await sendMessageFromInput()); + $('#message').on('keydown', async e => { + if (e.key === 'Enter') await sendMessageFromInput() + }); // FABs $('#add_peer_id').on('click', async () => await connect($('#peer_id').val())); diff --git a/public/scripts/encryption.js b/public/scripts/encryption.js index 669f9d4..b514f55 100644 --- a/public/scripts/encryption.js +++ b/public/scripts/encryption.js @@ -33,6 +33,8 @@ function setupDatabase() { console.error("Database failed: " + e.stack); }); + window.db = db; + return true; } @@ -164,12 +166,14 @@ async function storeMessage(peerId, message) { async function getMessages(peerId, publicKey, privateKey, passphrase) { console.log('[LOG] Getting messages'); try { - return await db.messages.where('peer_id').equals(peerId).sortBy('id').toArray().then(messages => { + return await db.messages.where('peer_id').equals(peerId).sortBy('id').then(messages => { + console.log(messages); let messageArray = []; - messages.forEach(async messageObj => messageArray.push({ - message: await decrypt(messages['message'], publicKey, privateKey, passphrase), + messages.forEach(async messageObj => console.log(messageObj) & messageArray.push({ + message: await decrypt(messageObj['message'], publicKey, privateKey, passphrase), time: moment(messageObj['time']).fromNow() })); + console.log(messageArray); return messageArray; }) } catch (e) { |