pleroma-fe/src/stores/shout.js

32 lines
792 B
JavaScript
Raw Normal View History

2023-04-04 21:17:54 -06:00
import { defineStore } from 'pinia'
export const useShoutStore = defineStore('shout', {
state: () => ({
messages: [],
channel: { state: '' },
2026-01-06 16:22:52 +02:00
joined: false,
2023-04-04 21:17:54 -06:00
}),
actions: {
2026-01-06 16:22:52 +02:00
initializeShout(socket) {
2023-04-04 21:17:54 -06:00
const channel = socket.channel('chat:public')
channel.joinPush.receive('ok', () => {
this.joined = true
})
channel.onClose(() => {
this.joined = false
})
channel.onError(() => {
this.joined = false
})
channel.on('new_msg', (msg) => {
this.messages.push(msg)
this.messages = this.messages.slice(-19, 20)
})
channel.on('messages', ({ messages }) => {
this.messages = messages.slice(-19, 20)
})
channel.join()
this.channel = channel
2026-01-06 16:22:52 +02:00
},
},
2023-04-04 21:17:54 -06:00
})