diff --git a/chatto/src/main/resources/static/js/chat.js b/chatto/src/main/resources/static/js/chat.js index 07b06ae..5120b1b 100644 --- a/chatto/src/main/resources/static/js/chat.js +++ b/chatto/src/main/resources/static/js/chat.js @@ -235,7 +235,7 @@ function populateMessages(userName, passphrase) { $(chatAreaNew).append(DOMPurify.sanitize(msgContainer)); }) - + scrollChatAreaAnimated(2400); }); @@ -301,6 +301,7 @@ document.getElementById('chatMessageForm').addEventListener('submit', function(e let context = { fromUser: username, message: md.render(messageContent), time: new Date().toLocaleString() }; let msgContainer = msgContainerSendTemplate(context); $(chatAreaNew).append(DOMPurify.sanitize(msgContainer)); + scrollChatAreaAnimated(2400); let messageCipher = sjcl.encrypt(passphraseInput.value, messageContent, { mode: "gcm", ts: 128, adata: "", iter: iterations }); let messageCipherJson = JSON.parse(messageCipher); let chatMessageDTO = { @@ -326,7 +327,11 @@ function messageSend(chatMessageDTO) { headers: headers, body: chatMessageDTO }) - .then(response => console.log(response)); + .then(response => { + console.log(response); + return response; + }) + .then(response => fetchErrorHandler(response)); } @@ -411,4 +416,10 @@ function fetchErrorHandler(response) { return true; }); } +} + +function scrollChatAreaAnimated(delay) { + $(chatAreaNew).stop().animate({ + scrollTop: $(chatAreaNew)[0].scrollHeight + }, delay); } \ No newline at end of file