fix chats

This commit is contained in:
Henry Jameson 2026-08-25 21:09:05 +03:00
commit f030328cd1
2 changed files with 15 additions and 6 deletions

View file

@ -89,14 +89,15 @@ const Chat = {
fetcher: null,
socket: null,
streaming: false,
fetching: true,
errorLoadingChat: false,
messageRetriers: {},
idempotencyKeyIndex: {},
}
},
created() {
async created() {
if (this.testMode) return
this.activate()
await this.activate()
this.attachSocket()
},
mounted() {
@ -243,8 +244,8 @@ const Chat = {
accountId: this.chatUserId,
credentials: useOAuthStore().token,
})
useUsersStore().addNewUsers(result)
const { data } = result
useUsersStore().addNewUsers({ ...result, data: data.account })
data.account = useUsersStore().findUser(data.account.id)
this.chat = data
} catch (e) {
@ -262,8 +263,8 @@ const Chat = {
},
deactivate() {
this.clear()
if (!this.streaming) {
this.stopFetching()
if (this.fetching) {
this.stopFetching('Chat deactivated')
}
},
attachSocket() {
@ -274,6 +275,7 @@ const Chat = {
}
et.addEventListener('update', this.onStreamMessage)
et.addEventListener('pleroma:chat_update', this.onChatUpdate)
et.addEventListener('open', this.onStreamConnect)
et.addEventListener('close', this.onStreamDisconnect)
@ -284,6 +286,7 @@ const Chat = {
const { et } = this.socket
et.removeEventListener('update', this.onStreamMessage)
et.removeEventListener('pleroma:chat_update', this.onChatUpdate)
et.removeEventListener('open', this.onStreamConnect)
et.removeEventListener('close', this.onStreamDisconnect)
@ -306,11 +309,13 @@ const Chat = {
5000,
)
this.fetchChat({ isFirstFetch })
this.fetching = true
},
stopFetching(reason) {
console.debug('[Chat View] Stopped fetching', 'Reason:', reason)
this.fetcher.stop()
this.fetcher = null
this.fetching = false
},
// Actions
@ -440,6 +445,10 @@ const Chat = {
)
this.addMessages({ messages })
},
onChatUpdate({ data: { chatUpdate } }) {
const messages = [chatUpdate.lastMessage]
this.addMessages({ messages })
},
addMessages({ messages: newMessages }) {
for (let i = 0; i < newMessages.length; i++) {
const message = newMessages[i]

View file

@ -101,7 +101,7 @@ export const useChatsStore = defineStore('chats', {
chat.unread = 0
}
},
updateChat({ chat: updatedChat }) {
updateChat({ data: { chatUpdate: updatedChat } }) {
const chat = getChatById(this, updatedChat.id)
if (chat) {
chat.lastMessage = updatedChat.lastMessage