2019-02-26 20:23:41 +00:00
|
|
|
import Vue from "vue";
|
|
|
|
import Vuex from "vuex";
|
2019-11-03 18:05:19 +00:00
|
|
|
import settings from "./store-settings";
|
|
|
|
|
2019-04-13 20:44:04 +00:00
|
|
|
const storage = require("./localStorage");
|
2019-02-26 20:23:41 +00:00
|
|
|
|
|
|
|
Vue.use(Vuex);
|
|
|
|
|
2019-11-02 19:40:59 +00:00
|
|
|
const store = new Vuex.Store({
|
2019-11-03 18:05:19 +00:00
|
|
|
modules: {
|
|
|
|
settings,
|
|
|
|
},
|
2019-02-27 14:15:34 +00:00
|
|
|
state: {
|
2019-11-02 19:40:59 +00:00
|
|
|
activeChannel: null,
|
|
|
|
currentUserVisibleError: null,
|
|
|
|
desktopNotificationState: "unsupported",
|
|
|
|
isAutoCompleting: false,
|
2019-02-27 14:15:34 +00:00
|
|
|
isConnected: false,
|
2019-11-02 19:40:59 +00:00
|
|
|
isFileUploadEnabled: false,
|
2019-02-27 14:15:34 +00:00
|
|
|
isNotified: false,
|
2019-02-27 18:15:58 +00:00
|
|
|
activeWindow: null,
|
2019-11-02 19:40:59 +00:00
|
|
|
networks: [],
|
|
|
|
pushNotificationState: "unsupported",
|
|
|
|
serverConfiguration: {},
|
2019-03-03 17:47:49 +00:00
|
|
|
sessions: [],
|
2019-04-13 20:44:04 +00:00
|
|
|
sidebarOpen: false,
|
2019-08-05 12:24:44 +00:00
|
|
|
sidebarDragging: false,
|
2019-04-13 20:44:04 +00:00
|
|
|
userlistOpen: storage.get("thelounge.state.userlist") !== "false",
|
2019-08-05 14:29:35 +00:00
|
|
|
versionData: null,
|
|
|
|
versionStatus: "loading",
|
|
|
|
versionDataExpired: false,
|
2019-02-27 14:15:34 +00:00
|
|
|
},
|
|
|
|
mutations: {
|
2019-11-02 19:40:59 +00:00
|
|
|
activeChannel(state, channel) {
|
|
|
|
state.activeChannel = channel;
|
|
|
|
},
|
|
|
|
currentUserVisibleError(state, error) {
|
|
|
|
state.currentUserVisibleError = error;
|
|
|
|
},
|
|
|
|
desktopNotificationState(state, desktopNotificationState) {
|
|
|
|
state.desktopNotificationState = desktopNotificationState;
|
|
|
|
},
|
|
|
|
isAutoCompleting(state, isAutoCompleting) {
|
|
|
|
state.isAutoCompleting = isAutoCompleting;
|
|
|
|
},
|
2019-02-27 14:15:34 +00:00
|
|
|
isConnected(state, payload) {
|
|
|
|
state.isConnected = payload;
|
|
|
|
},
|
2019-11-02 19:40:59 +00:00
|
|
|
isFileUploadEnabled(state, isFileUploadEnabled) {
|
|
|
|
state.isFileUploadEnabled = isFileUploadEnabled;
|
|
|
|
},
|
2019-02-27 14:15:34 +00:00
|
|
|
isNotified(state, payload) {
|
|
|
|
state.isNotified = payload;
|
|
|
|
},
|
2019-02-27 18:15:58 +00:00
|
|
|
activeWindow(state, payload) {
|
|
|
|
state.activeWindow = payload;
|
|
|
|
},
|
2019-11-02 19:40:59 +00:00
|
|
|
networks(state, networks) {
|
|
|
|
state.networks = networks;
|
|
|
|
},
|
|
|
|
removeNetwork(state, networkId) {
|
2019-11-03 18:05:19 +00:00
|
|
|
state.networks.splice(
|
|
|
|
store.state.networks.findIndex((n) => n.uuid === networkId),
|
|
|
|
1
|
|
|
|
);
|
2019-11-02 19:40:59 +00:00
|
|
|
},
|
|
|
|
sortNetworks(state, sortFn) {
|
|
|
|
state.networks.sort(sortFn);
|
|
|
|
},
|
|
|
|
pushNotificationState(state, pushNotificationState) {
|
|
|
|
state.pushNotificationState = pushNotificationState;
|
|
|
|
},
|
|
|
|
serverConfiguration(state, serverConfiguration) {
|
|
|
|
state.serverConfiguration = serverConfiguration;
|
2019-03-01 13:29:00 +00:00
|
|
|
},
|
2019-03-03 17:47:49 +00:00
|
|
|
sessions(state, payload) {
|
|
|
|
state.sessions = payload;
|
|
|
|
},
|
2019-04-13 20:44:04 +00:00
|
|
|
sidebarOpen(state, payload) {
|
|
|
|
state.sidebarOpen = payload;
|
|
|
|
},
|
2019-08-05 12:24:44 +00:00
|
|
|
sidebarDragging(state, payload) {
|
|
|
|
state.sidebarDragging = payload;
|
|
|
|
},
|
2019-04-13 20:44:04 +00:00
|
|
|
userlistOpen(state, payload) {
|
|
|
|
state.userlistOpen = payload;
|
|
|
|
},
|
2019-08-05 14:29:35 +00:00
|
|
|
versionData(state, payload) {
|
|
|
|
state.versionData = payload;
|
|
|
|
},
|
|
|
|
versionStatus(state, payload) {
|
|
|
|
state.versionStatus = payload;
|
|
|
|
},
|
|
|
|
versionDataExpired(state, payload) {
|
|
|
|
state.versionDataExpired = payload;
|
|
|
|
},
|
2019-03-03 17:47:49 +00:00
|
|
|
},
|
|
|
|
getters: {
|
|
|
|
currentSession: (state) => state.sessions.find((item) => item.current),
|
|
|
|
otherSessions: (state) => state.sessions.filter((item) => !item.current),
|
2019-11-03 11:23:03 +00:00
|
|
|
findChannelOnCurrentNetwork: (state) => (name) => {
|
|
|
|
name = name.toLowerCase();
|
|
|
|
return state.activeChannel.network.channels.find((c) => c.name.toLowerCase() === name);
|
|
|
|
},
|
2019-11-03 14:59:43 +00:00
|
|
|
findChannel: (state) => (id) => {
|
|
|
|
for (const network of state.networks) {
|
|
|
|
for (const channel of network.channels) {
|
|
|
|
if (channel.id === id) {
|
|
|
|
return {network, channel};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
findNetwork: (state) => (uuid) => {
|
|
|
|
for (const network of state.networks) {
|
|
|
|
if (network.uuid === uuid) {
|
|
|
|
return network;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2019-03-01 13:29:00 +00:00
|
|
|
},
|
2019-02-26 20:23:41 +00:00
|
|
|
});
|
2019-11-02 19:40:59 +00:00
|
|
|
|
|
|
|
export default store;
|