forked from AkkomaGang/akkoma-fe
get rid of older messages when scrolling down in chat to keep it from bloating dom
This commit is contained in:
parent
aa240f935f
commit
47770ed715
3 changed files with 24 additions and 0 deletions
|
@ -241,6 +241,7 @@ const Chat = {
|
||||||
this.fetchChat({ maxId: this.currentChatMessageService.minId })
|
this.fetchChat({ maxId: this.currentChatMessageService.minId })
|
||||||
} else if (this.bottomedOut(JUMP_TO_BOTTOM_BUTTON_VISIBILITY_OFFSET)) {
|
} else if (this.bottomedOut(JUMP_TO_BOTTOM_BUTTON_VISIBILITY_OFFSET)) {
|
||||||
this.jumpToBottomButtonVisible = false
|
this.jumpToBottomButtonVisible = false
|
||||||
|
this.$store.dispatch('cullOlderMessages', this.currentChatMessageService.chatId)
|
||||||
if (this.newMessageCount > 0) {
|
if (this.newMessageCount > 0) {
|
||||||
// Use a delay before marking as read to prevent situation where new messages
|
// Use a delay before marking as read to prevent situation where new messages
|
||||||
// arrive just as you're leaving the view and messages that you didn't actually
|
// arrive just as you're leaving the view and messages that you didn't actually
|
||||||
|
|
|
@ -115,6 +115,9 @@ const chats = {
|
||||||
},
|
},
|
||||||
handleMessageError ({ commit }, value) {
|
handleMessageError ({ commit }, value) {
|
||||||
commit('handleMessageError', { commit, ...value })
|
commit('handleMessageError', { commit, ...value })
|
||||||
|
},
|
||||||
|
cullOlderMessages ({ commit }, chatId) {
|
||||||
|
commit('cullOlderMessages', chatId)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
@ -227,6 +230,9 @@ const chats = {
|
||||||
handleMessageError (state, { chatId, fakeId, isRetry }) {
|
handleMessageError (state, { chatId, fakeId, isRetry }) {
|
||||||
const chatMessageService = state.openedChatMessageServices[chatId]
|
const chatMessageService = state.openedChatMessageServices[chatId]
|
||||||
chatService.handleMessageError(chatMessageService, fakeId, isRetry)
|
chatService.handleMessageError(chatMessageService, fakeId, isRetry)
|
||||||
|
},
|
||||||
|
cullOlderMessages (state, chatId) {
|
||||||
|
chatService.cullOlderMessages(state.openedChatMessageServices[chatId])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,22 @@ const deleteMessage = (storage, messageId) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cullOlderMessages = (storage) => {
|
||||||
|
const maxIndex = storage.messages.length
|
||||||
|
const minIndex = maxIndex - 50
|
||||||
|
if (maxIndex <= 50) return
|
||||||
|
|
||||||
|
storage.messages = _.sortBy(storage.messages, ['id'])
|
||||||
|
storage.minId = storage.messages[minIndex].id
|
||||||
|
for (const message of storage.messages) {
|
||||||
|
if (message.id < storage.minId) {
|
||||||
|
delete storage.idIndex[message.id]
|
||||||
|
delete storage.idempotencyKeyIndex[message.idempotency_key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storage.messages = storage.messages.slice(minIndex, maxIndex)
|
||||||
|
}
|
||||||
|
|
||||||
const handleMessageError = (storage, fakeId, isRetry) => {
|
const handleMessageError = (storage, fakeId, isRetry) => {
|
||||||
if (!storage) { return }
|
if (!storage) { return }
|
||||||
const fakeMessage = storage.idIndex[fakeId]
|
const fakeMessage = storage.idIndex[fakeId]
|
||||||
|
@ -201,6 +217,7 @@ const ChatService = {
|
||||||
empty,
|
empty,
|
||||||
getView,
|
getView,
|
||||||
deleteMessage,
|
deleteMessage,
|
||||||
|
cullOlderMessages,
|
||||||
resetNewMessageCount,
|
resetNewMessageCount,
|
||||||
clear,
|
clear,
|
||||||
handleMessageError
|
handleMessageError
|
||||||
|
|
Loading…
Reference in a new issue