Welcome to mirror list, hosted at ThFree Co, Russian Federation.

newGroupConversationStore.js « store « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7029939bf019a66da6448df09b09f4e758af80b0 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
 * @copyright Copyright (c) 2019 Marco Ambrosini <marcoambrosini@pm.me>
 *
 * @author Marco Ambrosini <marcoambrosini@pm.me>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
import isEqual from 'lodash/isEqual'

const state = {
	selectedParticipants: [],
}

const getDefaultState = () => {
	return {
		selectedParticipants: [],
	}
}

const getters = {
	/**
	 * Gets the selected participants array
	 *
	 * @param {object} state the state object.
	 * @return {Array} the selected participants array
	 */
	selectedParticipants: (state) => {
		if (state.selectedParticipants) {
			return state.selectedParticipants
		}
		return []
	},
}

const mutations = {
	/**
	 * Adds a the selected participants to the store.
	 *
	 * @param {object} state current store state;
	 * @param {object} participant the selected participant;
	 */
	addSelectedParticipant(state, participant) {
		state.selectedParticipants = [...state.selectedParticipants, participant]
	},

	/**
	 * Adds a the selected participants to the store.
	 *
	 * @param {object} state current store state;
	 * @param {object} participant the selected participants
	 */
	removeSelectedParticipant(state, participant) {
		state.selectedParticipants = state.selectedParticipants.filter((selectedParticipant) => {
			return selectedParticipant.id !== participant.id
		})
	},

	/**
	 * Purges the store
	 *
	 * @param {object} state current store state;
	 */
	purgeNewGroupConversationStore(state) {
		Object.assign(state, getDefaultState())
	},
}

const actions = {

	/**
	 * Adds or removes the participant to the selected participants array
	 *
	 * @param {object} context default store context;
	 * @param context.commit
	 * @param context.state
	 * @param {object} participant the clicked participant;
	 */
	updateSelectedParticipants({ commit, state }, participant) {
		let isAlreadySelected = false
		state.selectedParticipants.forEach(selectedParticipant => {
			if (isEqual(selectedParticipant, participant)) {
				isAlreadySelected = true
			}
		})
		if (isAlreadySelected) {
			/**
			 * Remove the clicked participant from the selected participants list
			 */
			commit('removeSelectedParticipant', participant)
		} else {
			/**
			 * Add the clicked participant from the selected participants list
			 */
			commit('addSelectedParticipant', participant)
		}
	},

	/**
	 * Purge the store
	 *
	 * @param {object} context default store context;
	 */
	purgeNewGroupConversationStore(context) {
		context.commit('purgeNewGroupConversationStore')
	},
}

export default { state, mutations, getters, actions }