2020-01-21 03:36:18 +13:00
|
|
|
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
|
2020-01-24 04:23:26 +13:00
|
|
|
import { Member } from '~/neko/types'
|
|
|
|
import { EVENT } from '~/neko/events'
|
2020-01-23 06:16:40 +13:00
|
|
|
import { accessor } from '~/store'
|
2020-01-21 03:36:18 +13:00
|
|
|
|
|
|
|
export const namespaced = true
|
|
|
|
|
|
|
|
export const state = () => ({
|
|
|
|
id: '',
|
2020-01-26 03:29:52 +13:00
|
|
|
clipboard: '',
|
2020-01-21 03:36:18 +13:00
|
|
|
})
|
|
|
|
|
|
|
|
export const getters = getterTree(state, {
|
|
|
|
hosting: (state, getters, root) => {
|
|
|
|
return root.user.id === state.id
|
|
|
|
},
|
2020-01-23 06:16:40 +13:00
|
|
|
hosted: (state, getters, root) => {
|
|
|
|
return state.id !== ''
|
|
|
|
},
|
2020-01-21 03:36:18 +13:00
|
|
|
host: (state, getters, root) => {
|
|
|
|
return root.user.member[state.id] || null
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
export const mutations = mutationTree(state, {
|
|
|
|
setHost(state, host: string | Member) {
|
|
|
|
if (typeof host === 'string') {
|
|
|
|
state.id = host
|
|
|
|
} else {
|
|
|
|
state.id = host.id
|
|
|
|
}
|
|
|
|
},
|
2020-01-24 04:23:26 +13:00
|
|
|
|
2020-01-26 03:29:52 +13:00
|
|
|
setClipboard(state, clipboard: string) {
|
|
|
|
state.clipboard = clipboard
|
|
|
|
},
|
|
|
|
|
2020-02-05 04:37:56 +13:00
|
|
|
reset(state) {
|
2020-01-24 04:23:26 +13:00
|
|
|
state.id = ''
|
2020-01-26 03:29:52 +13:00
|
|
|
state.clipboard = ''
|
2020-01-24 04:23:26 +13:00
|
|
|
},
|
2020-01-21 03:36:18 +13:00
|
|
|
})
|
|
|
|
|
|
|
|
export const actions = actionTree(
|
|
|
|
{ state, getters, mutations },
|
|
|
|
{
|
2020-01-26 03:29:52 +13:00
|
|
|
sendClipboard({ getters }, clipboard: string) {
|
|
|
|
if (!accessor.connected || !getters.hosting) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.CONTROL.CLIPBOARD, { text: clipboard })
|
|
|
|
},
|
|
|
|
|
2020-01-23 06:16:40 +13:00
|
|
|
toggle({ getters }) {
|
|
|
|
if (!accessor.connected) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!getters.hosting) {
|
|
|
|
$client.sendMessage(EVENT.CONTROL.REQUEST)
|
|
|
|
} else {
|
|
|
|
$client.sendMessage(EVENT.CONTROL.RELEASE)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
request({ getters }) {
|
|
|
|
if (!accessor.connected || !getters.hosting) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.CONTROL.REQUEST)
|
|
|
|
},
|
|
|
|
|
|
|
|
release({ getters }) {
|
|
|
|
if (!accessor.connected || getters.hosting) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.CONTROL.RELEASE)
|
|
|
|
},
|
|
|
|
|
2020-01-24 04:23:26 +13:00
|
|
|
give({ getters }, member: string | Member) {
|
|
|
|
if (!accessor.connected || !getters.hosting) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof member === 'string') {
|
|
|
|
member = accessor.user.members[member]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!member) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.CONTROL.GIVE, { id: member.id })
|
|
|
|
},
|
|
|
|
|
2020-01-23 06:16:40 +13:00
|
|
|
adminControl() {
|
|
|
|
if (!accessor.connected || !accessor.user.admin) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.ADMIN.CONTROL)
|
|
|
|
},
|
|
|
|
|
|
|
|
adminRelease() {
|
|
|
|
if (!accessor.connected || !accessor.user.admin) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.ADMIN.RELEASE)
|
|
|
|
},
|
|
|
|
|
2020-01-24 04:23:26 +13:00
|
|
|
adminGive({ getters }, member: string | Member) {
|
|
|
|
if (!accessor.connected) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof member === 'string') {
|
|
|
|
member = accessor.user.members[member]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!member) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.ADMIN.GIVE, { id: member.id })
|
|
|
|
},
|
|
|
|
|
2020-01-23 06:16:40 +13:00
|
|
|
lock() {
|
|
|
|
if (!accessor.connected || !accessor.user.admin) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.ADMIN.LOCK)
|
|
|
|
},
|
|
|
|
|
|
|
|
unlock() {
|
|
|
|
if (!accessor.connected || !accessor.user.admin) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.ADMIN.UNLOCK)
|
|
|
|
},
|
2020-01-21 03:36:18 +13:00
|
|
|
},
|
|
|
|
)
|