forked from AkkomaGang/akkoma-fe
WIP keep last_message updated
This commit is contained in:
parent
09da927def
commit
c9870a9d43
2 changed files with 29 additions and 5 deletions
|
@ -64,7 +64,7 @@ const chats = {
|
|||
dispatch('addNewUsers', [chat.account])
|
||||
},
|
||||
addChatMessages ({ commit }, value) {
|
||||
commit('addChatMessages', value)
|
||||
commit('addChatMessages', { commit, ...value })
|
||||
},
|
||||
setChatFocused ({ commit }, value) {
|
||||
commit('setChatFocused', value)
|
||||
|
@ -90,7 +90,7 @@ const chats = {
|
|||
},
|
||||
deleteChatMessage ({ rootState, commit, dispatch }, value) {
|
||||
rootState.api.backendInteractor.deleteChatMessage(value)
|
||||
commit('deleteChatMessage', value)
|
||||
commit('deleteChatMessage', { commit, ...value })
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
|
@ -152,16 +152,27 @@ const chats = {
|
|||
setChatsLoading (state, { value }) {
|
||||
state.chats.loading = value
|
||||
},
|
||||
addChatMessages (state, { chatId, messages }) {
|
||||
addChatMessages (state, { commit, chatId, messages }) {
|
||||
const chatMessageService = state.openedChatMessageServices[chatId]
|
||||
if (chatMessageService) {
|
||||
chatService.add(chatMessageService, { messages: messages.map(parseChatMessage) })
|
||||
commit('refreshLastMessage', { commit, chatId })
|
||||
}
|
||||
},
|
||||
deleteChatMessage (state, { chatId, messageId }) {
|
||||
refreshLastMessage (state, { chatId }) {
|
||||
const chatMessageService = state.openedChatMessageServices[chatId]
|
||||
if (chatMessageService) {
|
||||
const chat = state.chatList.data.find(c => c.id === chatId)
|
||||
if (chat) {
|
||||
chat.lastMessage = chatMessageService.lastMessage
|
||||
}
|
||||
}
|
||||
},
|
||||
deleteChatMessage (state, { commit, chatId, messageId }) {
|
||||
const chatMessageService = state.openedChatMessageServices[chatId]
|
||||
if (chatMessageService) {
|
||||
chatService.deleteMessage(chatMessageService, messageId)
|
||||
commit('refreshLastMessage', { commit, chatId })
|
||||
}
|
||||
},
|
||||
resetChatNewMessageCount (state, _value) {
|
||||
|
|
|
@ -7,7 +7,8 @@ const empty = (chatId) => {
|
|||
newMessageCount: 0,
|
||||
lastSeenTimestamp: 0,
|
||||
chatId: chatId,
|
||||
minId: undefined
|
||||
minId: undefined,
|
||||
lastMessage: undefined
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +16,14 @@ const deleteMessage = (storage, messageId) => {
|
|||
if (!storage) { return }
|
||||
storage.messages = storage.messages.filter(m => m.id !== messageId)
|
||||
delete storage.idIndex[messageId]
|
||||
|
||||
if (storage.lastMessage && (storage.lastMessage.id === messageId)) {
|
||||
storage.lastMessage = _.maxBy(storage.messages, 'id')
|
||||
}
|
||||
|
||||
if (storage.minId === messageId) {
|
||||
storage.minId = _.minBy(storage.messages, 'id')
|
||||
}
|
||||
}
|
||||
|
||||
const add = (storage, { messages: newMessages }) => {
|
||||
|
@ -29,6 +38,10 @@ const add = (storage, { messages: newMessages }) => {
|
|||
storage.minId = message.id
|
||||
}
|
||||
|
||||
if (!storage.lastMessage || message.id > storage.lastMessage.id) {
|
||||
storage.lastMessage = message
|
||||
}
|
||||
|
||||
if (!storage.idIndex[message.id]) {
|
||||
if (storage.lastSeenTimestamp < message.created_at) {
|
||||
storage.newMessageCount++
|
||||
|
|
Loading…
Reference in a new issue