fix chats
This commit is contained in:
parent
283b91826f
commit
f030328cd1
2 changed files with 15 additions and 6 deletions
|
|
@ -89,14 +89,15 @@ const Chat = {
|
||||||
fetcher: null,
|
fetcher: null,
|
||||||
socket: null,
|
socket: null,
|
||||||
streaming: false,
|
streaming: false,
|
||||||
|
fetching: true,
|
||||||
errorLoadingChat: false,
|
errorLoadingChat: false,
|
||||||
messageRetriers: {},
|
messageRetriers: {},
|
||||||
idempotencyKeyIndex: {},
|
idempotencyKeyIndex: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
async created() {
|
||||||
if (this.testMode) return
|
if (this.testMode) return
|
||||||
this.activate()
|
await this.activate()
|
||||||
this.attachSocket()
|
this.attachSocket()
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|
@ -243,8 +244,8 @@ const Chat = {
|
||||||
accountId: this.chatUserId,
|
accountId: this.chatUserId,
|
||||||
credentials: useOAuthStore().token,
|
credentials: useOAuthStore().token,
|
||||||
})
|
})
|
||||||
useUsersStore().addNewUsers(result)
|
|
||||||
const { data } = result
|
const { data } = result
|
||||||
|
useUsersStore().addNewUsers({ ...result, data: data.account })
|
||||||
data.account = useUsersStore().findUser(data.account.id)
|
data.account = useUsersStore().findUser(data.account.id)
|
||||||
this.chat = data
|
this.chat = data
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -262,8 +263,8 @@ const Chat = {
|
||||||
},
|
},
|
||||||
deactivate() {
|
deactivate() {
|
||||||
this.clear()
|
this.clear()
|
||||||
if (!this.streaming) {
|
if (this.fetching) {
|
||||||
this.stopFetching()
|
this.stopFetching('Chat deactivated')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachSocket() {
|
attachSocket() {
|
||||||
|
|
@ -274,6 +275,7 @@ const Chat = {
|
||||||
}
|
}
|
||||||
|
|
||||||
et.addEventListener('update', this.onStreamMessage)
|
et.addEventListener('update', this.onStreamMessage)
|
||||||
|
et.addEventListener('pleroma:chat_update', this.onChatUpdate)
|
||||||
et.addEventListener('open', this.onStreamConnect)
|
et.addEventListener('open', this.onStreamConnect)
|
||||||
et.addEventListener('close', this.onStreamDisconnect)
|
et.addEventListener('close', this.onStreamDisconnect)
|
||||||
|
|
||||||
|
|
@ -284,6 +286,7 @@ const Chat = {
|
||||||
const { et } = this.socket
|
const { et } = this.socket
|
||||||
|
|
||||||
et.removeEventListener('update', this.onStreamMessage)
|
et.removeEventListener('update', this.onStreamMessage)
|
||||||
|
et.removeEventListener('pleroma:chat_update', this.onChatUpdate)
|
||||||
et.removeEventListener('open', this.onStreamConnect)
|
et.removeEventListener('open', this.onStreamConnect)
|
||||||
et.removeEventListener('close', this.onStreamDisconnect)
|
et.removeEventListener('close', this.onStreamDisconnect)
|
||||||
|
|
||||||
|
|
@ -306,11 +309,13 @@ const Chat = {
|
||||||
5000,
|
5000,
|
||||||
)
|
)
|
||||||
this.fetchChat({ isFirstFetch })
|
this.fetchChat({ isFirstFetch })
|
||||||
|
this.fetching = true
|
||||||
},
|
},
|
||||||
stopFetching(reason) {
|
stopFetching(reason) {
|
||||||
console.debug('[Chat View] Stopped fetching', 'Reason:', reason)
|
console.debug('[Chat View] Stopped fetching', 'Reason:', reason)
|
||||||
this.fetcher.stop()
|
this.fetcher.stop()
|
||||||
this.fetcher = null
|
this.fetcher = null
|
||||||
|
this.fetching = false
|
||||||
},
|
},
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
@ -440,6 +445,10 @@ const Chat = {
|
||||||
)
|
)
|
||||||
this.addMessages({ messages })
|
this.addMessages({ messages })
|
||||||
},
|
},
|
||||||
|
onChatUpdate({ data: { chatUpdate } }) {
|
||||||
|
const messages = [chatUpdate.lastMessage]
|
||||||
|
this.addMessages({ messages })
|
||||||
|
},
|
||||||
addMessages({ messages: newMessages }) {
|
addMessages({ messages: newMessages }) {
|
||||||
for (let i = 0; i < newMessages.length; i++) {
|
for (let i = 0; i < newMessages.length; i++) {
|
||||||
const message = newMessages[i]
|
const message = newMessages[i]
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ export const useChatsStore = defineStore('chats', {
|
||||||
chat.unread = 0
|
chat.unread = 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateChat({ chat: updatedChat }) {
|
updateChat({ data: { chatUpdate: updatedChat } }) {
|
||||||
const chat = getChatById(this, updatedChat.id)
|
const chat = getChatById(this, updatedChat.id)
|
||||||
if (chat) {
|
if (chat) {
|
||||||
chat.lastMessage = updatedChat.lastMessage
|
chat.lastMessage = updatedChat.lastMessage
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue