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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/**
* @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/>.
*
*/
/**
* This store helps to identify a the current actor in all cases.
* In Talk not every user is a local nextcloud user, so identifying
* solely by userId is not enough.
* If an as no userId, they are a guest and identified by actorType + sessionId.
*/
import { PARTICIPANT } from '../constants'
const state = {
userId: null,
sessionId: null,
actorId: null,
actorType: null,
displayName: '',
}
const getters = {
getUserId: (state) => () => {
return state.userId
},
getSessionId: (state) => () => {
return state.sessionId
},
getActorId: (state) => () => {
return state.actorId
},
getActorType: (state) => () => {
return state.actorType
},
getDisplayName: (state) => () => {
return state.displayName
},
getParticipantIdentifier: (state) => () => {
return {
actorType: state.actorType,
actorId: state.actorId,
sessionId: state.sessionId,
}
},
}
const mutations = {
/**
* Set the userId
*
* @param {object} state current store state;
* @param {string} userId The user id
*/
setUserId(state, userId) {
state.userId = userId
state.actorId = userId
},
/**
* Set the sessionId
*
* @param {object} state current store state;
* @param {string} sessionId The actors session id
*/
setSessionId(state, sessionId) {
state.sessionId = sessionId
},
/**
* Set the actorId
*
* @param {object} state current store state;
* @param {string} actorId The actor id
*/
setActorId(state, actorId) {
state.actorId = actorId
},
/**
* Set the userId
*
* @param {object} state current store state;
* @param {string} displayName The name
*/
setDisplayName(state, displayName) {
state.displayName = displayName
},
/**
* Set the userId
*
* @param {object} state current store state;
* @param {actorType} actorType The actor type of the user
*/
setActorType(state, actorType) {
state.actorType = actorType
},
}
const actions = {
/**
* Set the actor from the current user
*
* @param {object} context default store context;
* @param {object} user A NextcloudUser object as returned by @nextcloud/auth
* @param {string} user.uid The user id of the user
* @param {string|null} user.displayName The display name of the user
*/
setCurrentUser(context, user) {
context.commit('setUserId', user.uid)
context.commit('setDisplayName', user.displayName || user.uid)
context.commit('setActorType', 'users')
context.commit('setActorId', user.uid)
},
/**
* Set the actor from the current participant
*
* @param {object} context default store context;
* @param {object} participant The participant data
* @param {int} participant.participantType The type of the participant
* @param {string} participant.sessionId The session id of the participant
* @param {string} participant.actorId The actor id of the participant
*/
setCurrentParticipant(context, participant) {
context.commit('setSessionId', participant.sessionId)
if (participant.participantType === PARTICIPANT.TYPE.GUEST
|| participant.participantType === PARTICIPANT.TYPE.GUEST_MODERATOR) {
context.commit('setUserId', null)
context.commit('setActorType', 'guests')
context.commit('setActorId', participant.actorId)
// FIXME context.commit('setDisplayName', '')
}
},
/**
* Sets displayName only, we currently use this for guests user names.
*
* @param {object} context default store context;
* @param {string} displayName the display name to be set;
*/
setDisplayName(context, displayName) {
context.commit('setDisplayName', displayName)
},
}
export default { state, mutations, getters, actions }
|