From e3a5bea4871b73be0257557d20048bf30976f83c Mon Sep 17 00:00:00 2001 From: WhiteNervosa Date: Thu, 18 Jun 2020 08:33:23 -0500 Subject: [PATCH] Unsent messages persist through a refresh or logging in --- assets/chat/js/chat.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 9b44e967..a2234d35 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -480,7 +480,10 @@ class Chat { this.loadingscrn.fadeOut(250, () => this.loadingscrn.remove()) this.mainwindow.updateAndPin() + window.addEventListener('beforeunload', (event) => ChatStore.write('chat.unsentMessage', this.input.val())) + this.input.focus().attr('placeholder', `Write something ...`) + this.input.val(ChatStore.read('chat.unsentMessage') ? ChatStore.read('chat.unsentMessage') : null) MessageBuilder.status(`Welcome to DGG chat`).into(this) return Promise.resolve(this) } @@ -1128,6 +1131,7 @@ class Chat { this.source.send('MSG', {data: raw}) this.inputhistory.add(raw) this.input.val('') + if(ChatStore.read('chat.unsentMessage') !== null) ChatStore.write('chat.unsentMessage', null) } } }