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

guestNameStore.js « store « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 759568649ad5191471777bc5a46c3f7ee4fe786a (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
/**
 * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com>
 *
 * @author Joas Schilling <coding@schilljs.com>
 *
 * @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 Vue from 'vue'

const state = {
	guestNames: {
	},
}

const getters = {
	/**
	 * Gets the participants array
	 *
	 * @param {object} state the state object.
	 * @return {Array} the participants array (if there are participants in the store)
	 */
	getGuestName: (state) => (token, actorId) => {
		if (state.guestNames[token] && state.guestNames[token][actorId]) {
			return state.guestNames[token][actorId]
		}
		return t('spreed', 'Guest')
	},
}

const mutations = {
	/**
	 * Adds a guest name to the store
	 *
	 * @param {object} state current store state
	 * @param {boolean} noUpdate Only set the guest name if it was not set before
	 * @param {string} token the token of the conversation
	 * @param {string} actorId the guest
	 * @param {string} actorDisplayName the display name to set
	 */
	addGuestName(state, { noUpdate, token, actorId, actorDisplayName }) {
		if (!state.guestNames[token]) {
			Vue.set(state.guestNames, token, [])
		}
		if (!state.guestNames[token][actorId]) {
			Vue.set(state.guestNames[token], actorId, t('spreed', 'Guest'))
		} else if (noUpdate) {
			return
		}
		state.guestNames[token][actorId] = actorDisplayName
	},
}

const actions = {

	/**
	 * Add guest name of a chat message to the store
	 *
	 * @param {object} context default store context
	 * @param {string} token the token of the conversation
	 * @param {string} actorId the guest
	 * @param {string} actorDisplayName the display name to set
	 */
	setGuestNameIfEmpty(context, { token, actorId, actorDisplayName }) {
		context.commit('addGuestName', { noUpdate: true, token, actorId, actorDisplayName })
	},
	/**
	 * Add guest name of a chat message to the store
	 *
	 * @param {object} context default store context
	 * @param {string} token the token of the conversation
	 * @param {string} actorId the guest
	 * @param {string} actorDisplayName the display name to set
	 */
	forceGuestName(context, { token, actorId, actorDisplayName }) {
		context.commit('addGuestName', { noUpdate: false, token, actorId, actorDisplayName })
	},
}

export default { state, mutations, getters, actions }