Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85827950
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/stores/chats.js b/src/stores/chats.js
index 86ea310ce2..1cf4f4a3d1 100644
--- a/src/stores/chats.js
+++ b/src/stores/chats.js
@@ -1,94 +1,94 @@
import { orderBy, sumBy } from 'lodash'
import { defineStore } from 'pinia'
import { maybeShowChatNotification } from '../services/chat_utils/chat_utils.js'
import { promiseInterval } from '../services/promise_interval/promise_interval.js'
import { useOAuthStore } from 'src/stores/oauth.js'
import { useStreamingStore } from 'src/stores/streaming.js'
import { useUsersStore } from 'src/stores/users.js'
import { chats } from 'src/api/chats.js'
const defaultState = {
data: new Map(),
fetcher: null,
}
export const useChatsStore = defineStore('chats', {
state: () => ({ ...defaultState }),
getters: {
sortedChatList(state) {
return orderBy([...state.data.values()], ['updated_at'], ['desc'])
},
unreadChatsCount(state) {
return sumBy([...state.data.values()], 'unread')
},
},
actions: {
attachSocket() {
const et = new EventTarget()
const socket = {
name: 'chats',
et,
}
et.addEventListener('pleroma:chat_update', ({ data: { chatUpdate } }) => {
this.updateChat(chatUpdate)
})
useStreamingStore().addSubscriber(socket)
},
startFetching() {
- this.fetcher = () => promiseInterval(() => this.fetchChats(), 5000)
- this.fetcher()
+ this.fetcher = promiseInterval(() => this.fetchChats(), 5000)
+ this.fetchChats()
},
stopFetching() {
this.fetcher?.stop()
this.fetcher = null
},
async fetchChats() {
this.addNewChats(
await chats({
credentials: useOAuthStore().token,
}),
)
},
resetChats() {
this.data = new Map()
this.stopFetching()
this.startFetching()
},
addNewChats(result) {
useUsersStore().addNewUsers({
...result,
data: result.data.map((k) => k.account).filter(Boolean),
})
// We do unshift in update so we reverse the chat list here
result.data.forEach((chat) => this.updateChat(chat))
},
readChat(id) {
const chat = this.data.get(id)
if (chat) {
chat.unread = 0
} else {
console.error(`Chat ${id} not found!`)
}
},
updateChat(updatedChat) {
const chat = this.data.get(updatedChat.id)
if (chat) {
chat.lastMessage = updatedChat.lastMessage
chat.unread = updatedChat.unread
chat.updated_at = updatedChat.updated_at
} else {
this.data.set(updatedChat.id, updatedChat)
}
maybeShowChatNotification(chat ?? updatedChat)
},
deleteChat(id) {
this.data.delete(id)
},
},
})
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Oct 31, 12:43 AM (19 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1800823
Default Alt Text
(2 KB)
Attached To
Mode
rPUFE pleroma-fe-upstream
Attached
Detach File
Event Timeline