summaryrefslogtreecommitdiffstats
path: root/src/services/CommandsService.js
blob: 181d50e1d4685303c50268bda58e4f1447c48b8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import AuthService from "./AuthService"
import ChatService from "./ChatService"
import store from "@/store/index.js"
import router from '@/router/index.js'

function set_groups(searcher, data) {
    function group_command(group) {
        searcher.$emit("group_set", group)
    }

    let groups = {}

    data.forEach((group) => {
        groups[group.name] = () => group_command(group)
    })

    return groups
}


export default {
    groups() {
        return {
            async send(searcher) {
                const {data, status} = await ChatService.get_all_user_groups()
                if (status!==200)
                    return {}
                const groups = set_groups(searcher, data)
                return groups
            },

            make(searcher) {
                searcher.$emit('toogle_group_maker')
            },
        }
    },

    logout() {
        AuthService.logout()
        store.dispatch('logout')
        router.push('/login')
    },
}