Skip to content

Commit 533c8ff

Browse files
committed
feat(chat): maintain sent message history on navigate away
1 parent 01d09f8 commit 533c8ff

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/gui/app/controllers/chat-messages.controller.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,19 @@
158158
};
159159

160160
// This happens when a chat message is submitted.
161-
const chatHistory = [];
162-
let currrentHistoryIndex = -1;
163161
$scope.submitChat = function() {
164162
if (chatMessagesService.chatMessage == null || chatMessagesService.chatMessage.length < 1) {
165163
return;
166164
}
167165
chatMessagesService.submitChat(chatMessagesService.chatSender, chatMessagesService.chatMessage, chatMessagesService.threadDetails?.replyToMessageId);
168-
chatHistory.unshift(chatMessagesService.chatMessage);
169-
currrentHistoryIndex = -1;
166+
chatMessagesService.chatHistory.unshift(chatMessagesService.chatMessage);
167+
chatMessagesService.currrentHistoryIndex = -1;
170168
chatMessagesService.chatMessage = "";
171169
chatMessagesService.threadDetails = null;
172170
};
173171

174172
$scope.onMessageFieldUpdate = () => {
175-
currrentHistoryIndex = -1;
173+
chatMessagesService.currrentHistoryIndex = -1;
176174
};
177175

178176
$scope.onMessageFieldKeypress = ($event) => {
@@ -181,22 +179,27 @@
181179
//up arrow
182180
if (
183181
chatMessagesService.chatMessage.length < 1 ||
184-
chatMessagesService.chatMessage === chatHistory[currrentHistoryIndex]
182+
chatMessagesService.currrentHistoryIndex === -1 ||
183+
chatMessagesService.chatMessage === chatMessagesService.chatHistory[chatMessagesService.currrentHistoryIndex]
185184
) {
186-
if (currrentHistoryIndex + 1 < chatHistory.length) {
187-
currrentHistoryIndex++;
188-
chatMessagesService.chatMessage = chatHistory[currrentHistoryIndex];
185+
if (chatMessagesService.currrentHistoryIndex + 1 < chatMessagesService.chatHistory.length) {
186+
chatMessagesService.currrentHistoryIndex++;
187+
chatMessagesService.chatMessage = chatMessagesService.chatHistory[chatMessagesService.currrentHistoryIndex];
189188
}
190189
}
191190
} else if (keyCode === 40) {
192191
//down arrow
193192
if (
194193
chatMessagesService.chatMessage.length > 0 ||
195-
chatMessagesService.chatMessage === chatHistory[currrentHistoryIndex]
194+
chatMessagesService.chatMessage === chatMessagesService.chatHistory[chatMessagesService.currrentHistoryIndex]
196195
) {
197-
if (currrentHistoryIndex - 1 >= 0) {
198-
currrentHistoryIndex--;
199-
chatMessagesService.chatMessage = chatHistory[currrentHistoryIndex];
196+
if (chatMessagesService.currrentHistoryIndex >= 0) {
197+
chatMessagesService.currrentHistoryIndex--;
198+
if (chatMessagesService.currrentHistoryIndex >= 0) {
199+
chatMessagesService.chatMessage = chatMessagesService.chatHistory[chatMessagesService.currrentHistoryIndex];
200+
} else {
201+
chatMessagesService.chatMessage = "";
202+
}
200203
}
201204
}
202205
} else if (keyCode === 13) {

src/gui/app/services/chat-messages.service.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
// The message/thread currently being replied to
2929
service.threadDetails = null;
3030

31+
// History of chat messages sent via Dashboard
32+
service.chatHistory = [];
33+
service.currrentHistoryIndex = -1;
34+
3135
// Return the chat queue.
3236
service.getChatQueue = function() {
3337
return service.chatQueue;

0 commit comments

Comments
 (0)