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
|
|
|
|
|
|
|
|
interface Members {
|
|
|
|
[id: string]: Member
|
|
|
|
}
|
|
|
|
|
|
|
|
export const state = () => ({
|
|
|
|
id: '',
|
|
|
|
members: {} as Members,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const getters = getterTree(state, {
|
2020-04-05 15:17:06 +12:00
|
|
|
member: (state) => state.members[state.id] || null,
|
|
|
|
admin: (state) => (state.members[state.id] ? state.members[state.id].admin : false),
|
|
|
|
muted: (state) => (state.members[state.id] ? state.members[state.id].muted : false),
|
2020-01-21 03:36:18 +13:00
|
|
|
})
|
|
|
|
|
|
|
|
export const mutations = mutationTree(state, {
|
2020-01-24 04:23:26 +13:00
|
|
|
setIgnored(state, { id, ignored }: { id: string; ignored: boolean }) {
|
|
|
|
state.members[id] = {
|
|
|
|
...state.members[id],
|
|
|
|
ignored,
|
|
|
|
}
|
|
|
|
},
|
2020-01-23 06:16:40 +13:00
|
|
|
setMuted(state, { id, muted }: { id: string; muted: boolean }) {
|
|
|
|
state.members[id] = {
|
|
|
|
...state.members[id],
|
|
|
|
muted,
|
|
|
|
}
|
|
|
|
},
|
2020-01-21 03:36:18 +13:00
|
|
|
setMembers(state, members: Member[]) {
|
|
|
|
const data: Members = {}
|
|
|
|
for (const member of members) {
|
2020-01-23 06:16:40 +13:00
|
|
|
data[member.id] = {
|
|
|
|
connected: true,
|
|
|
|
...member,
|
|
|
|
}
|
2020-01-21 03:36:18 +13:00
|
|
|
}
|
|
|
|
state.members = data
|
|
|
|
},
|
|
|
|
setMember(state, id: string) {
|
|
|
|
state.id = id
|
|
|
|
},
|
|
|
|
addMember(state, member: Member) {
|
2021-02-14 00:19:39 +13:00
|
|
|
// remove html tags
|
|
|
|
let tmp = document.createElement("div");
|
|
|
|
tmp.innerHTML = member.displayname;
|
|
|
|
member.displayname = tmp.textContent || tmp.innerText || "";
|
|
|
|
|
2020-01-21 03:36:18 +13:00
|
|
|
state.members = {
|
|
|
|
...state.members,
|
2020-01-23 06:16:40 +13:00
|
|
|
[member.id]: {
|
|
|
|
connected: true,
|
|
|
|
...member,
|
|
|
|
},
|
2020-01-21 03:36:18 +13:00
|
|
|
}
|
|
|
|
},
|
|
|
|
delMember(state, id: string) {
|
2020-01-23 06:16:40 +13:00
|
|
|
state.members[id] = {
|
|
|
|
...state.members[id],
|
|
|
|
connected: false,
|
|
|
|
}
|
2020-01-21 03:36:18 +13:00
|
|
|
},
|
2020-02-05 04:37:56 +13:00
|
|
|
reset(state) {
|
2020-01-21 03:36:18 +13:00
|
|
|
state.members = {}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
export const actions = actionTree(
|
|
|
|
{ state, getters, mutations },
|
|
|
|
{
|
2020-01-23 06:16:40 +13:00
|
|
|
ban({ state }, member: string | Member) {
|
|
|
|
if (!accessor.connected || !accessor.user.admin) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof member === 'string') {
|
|
|
|
member = state.members[member]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!member) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.ADMIN.BAN, { id: member.id })
|
|
|
|
},
|
|
|
|
|
|
|
|
kick({ state }, member: string | Member) {
|
|
|
|
if (!accessor.connected || !accessor.user.admin) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof member === 'string') {
|
|
|
|
member = state.members[member]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!member) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.ADMIN.KICK, { id: member.id })
|
|
|
|
},
|
|
|
|
|
|
|
|
mute({ state }, member: string | Member) {
|
|
|
|
if (!accessor.connected || !accessor.user.admin) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof member === 'string') {
|
|
|
|
member = state.members[member]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!member) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.ADMIN.MUTE, { id: member.id })
|
|
|
|
},
|
|
|
|
|
|
|
|
unmute({ state }, member: string | Member) {
|
|
|
|
if (!accessor.connected || !accessor.user.admin) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof member === 'string') {
|
|
|
|
member = state.members[member]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!member) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$client.sendMessage(EVENT.ADMIN.UNMUTE, { id: member.id })
|
|
|
|
},
|
2020-01-21 03:36:18 +13:00
|
|
|
},
|
|
|
|
)
|