Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/client/src/store/chat.ts

51 lines
1.0 KiB
TypeScript
Raw Normal View History

2020-01-21 03:36:18 +13:00
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
2020-01-23 06:16:40 +13:00
import { EVENT } from '~/client/events'
import { accessor } from '~/store'
2020-01-21 03:36:18 +13:00
export const namespaced = true
interface Message {
id: string
content: string
created: Date
2020-01-23 06:16:40 +13:00
type: 'text' | 'event'
2020-01-21 03:36:18 +13:00
}
export const state = () => ({
2020-01-23 06:16:40 +13:00
history: [] as Message[],
2020-01-21 03:36:18 +13:00
})
export const getters = getterTree(state, {
//
})
export const mutations = mutationTree(state, {
addMessage(state, message: Message) {
2020-01-23 06:16:40 +13:00
state.history = state.history.concat([message])
},
clear(state) {
state.history = []
2020-01-21 03:36:18 +13:00
},
})
export const actions = actionTree(
{ state, getters, mutations },
{
2020-01-23 06:16:40 +13:00
sendMessage(store, content: string) {
if (!accessor.connected || accessor.user.muted) {
return
}
$client.sendMessage(EVENT.CHAT.MESSAGE, { content })
},
sendEmoji(store, emoji: string) {
if (!accessor.connected || !accessor.user.muted) {
return
}
$client.sendMessage(EVENT.CHAT.EMOJI, { emoji })
},
2020-01-21 03:36:18 +13:00
},
)