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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
<!--
- @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/>.
-->
<template>
<div>
<ParticipantsList
v-if="participantsList.length"
:items="participantsList"
:loading="!participantsInitialised" />
<Hint v-else :hint="t('spreed', 'No search results')" />
</div>
</template>
<script>
import ParticipantsList from '../ParticipantsList/ParticipantsList'
import { ATTENDEE, PARTICIPANT } from '../../../../constants'
import UserStatus from '../../../../mixins/userStatus'
import Hint from '../../../Hint'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
export default {
name: 'CurrentParticipants',
components: {
ParticipantsList,
Hint,
},
mixins: [
UserStatus,
],
props: {
searchText: {
type: String,
default: '',
},
participantsInitialised: {
type: Boolean,
default: true,
},
},
computed: {
token() {
return this.$store.getters.getToken()
},
/**
* Gets the participants array.
*
* @return {Array}
*/
participantsList() {
let participants = this.$store.getters.participantsList(this.token)
if (this.searchText !== '') {
const lowerSearchText = this.searchText.toLowerCase()
participants = participants.filter(participant => {
return participant.displayName.toLowerCase().indexOf(lowerSearchText) !== -1
|| (participant.actorType !== 'guests'
&& participant.actorId.toLowerCase().indexOf(lowerSearchText) !== -1)
})
}
return participants.slice().sort(this.sortParticipants)
},
},
mounted() {
subscribe('user_status:status.updated', this.userStatusUpdated)
},
beforeDestroyed() {
unsubscribe('user_status:status.updated', this.userStatusUpdated)
},
methods: {
userStatusUpdated(state) {
this.$store.dispatch('updateUser', {
token: this.token,
participantIdentifier: {
actorType: 'users',
actorId: state.userId,
},
updatedData: {
status: state.status,
statusIcon: state.icon,
statusMessage: state.message,
},
})
},
/**
* Sort two participants by:
* - participants before groups
* - online status
* - in call
* - who raised hand first
* - type (moderators before normal participants)
* - user status (dnd at the end)
* - display name
*
* @param {object} participant1 First participant
* @param {int} participant1.participantType First participant type
* @param {string} participant1.sessionId First participant session
* @param {string} participant1.displayName First participant display name
* @param {string} participant1.status First participant user status
* @param {string} participant1.actorType First participant actor type
* @param {int} participant1.inCall First participant in call flag
* @param {object} participant2 Second participant
* @param {int} participant2.participantType Second participant type
* @param {string} participant2.sessionId Second participant session
* @param {string} participant2.displayName Second participant display name
* @param {string} participant2.actorType Second participant actor type
* @param {string} participant2.status Second participant user status
* @param {int} participant2.inCall Second participant in call flag
* @return {number}
*/
sortParticipants(participant1, participant2) {
const p1IsGroup = participant1.actorType === ATTENDEE.ACTOR_TYPE.GROUPS
const p2IsGroup = participant2.actorType === ATTENDEE.ACTOR_TYPE.GROUPS
if (p1IsGroup !== p2IsGroup) {
// Groups below participants
return p2IsGroup ? -1 : 1
}
const hasSessions1 = !!participant1.sessionIds.length
const hasSessions2 = !!participant2.sessionIds.length
/**
* For now the user status is not overwriting the online-offline status anymore
* It felt too weird having users appear as offline but they are in the call or chat actively
if (participant1.status === 'offline') {
hasSessions1 = false
}
if (participant2.status === 'offline') {
hasSessions2 = false
}
*/
if (!hasSessions1) {
if (hasSessions2) {
return 1
}
} else if (!hasSessions2) {
return -1
}
const p1inCall = participant1.inCall !== PARTICIPANT.CALL_FLAG.DISCONNECTED
const p2inCall = participant2.inCall !== PARTICIPANT.CALL_FLAG.DISCONNECTED
if (p1inCall !== p2inCall) {
return p1inCall ? -1 : 1
}
const p1HandRaised = this.$store.getters.getParticipantRaisedHand(participant1.sessionIds)
const p2HandRaised = this.$store.getters.getParticipantRaisedHand(participant2.sessionIds)
if (p1HandRaised.state !== p2HandRaised.state) {
return p1HandRaised.state ? -1 : 1
}
// both had raised hands, then pick whoever raised hand first
if (p1HandRaised) {
// use MAX_VALUE if not defined to avoid zeroes making it look like
// one raised their hands at the birth of time...
const t1 = p1HandRaised.timestamp || Number.MAX_VALUE
const t2 = p2HandRaised.timestamp || Number.MAX_VALUE
if (t1 !== t2) {
return t1 - t2
}
}
const moderatorTypes = [PARTICIPANT.TYPE.OWNER, PARTICIPANT.TYPE.MODERATOR, PARTICIPANT.TYPE.GUEST_MODERATOR]
const moderator1 = moderatorTypes.indexOf(participant1.participantType) !== -1
const moderator2 = moderatorTypes.indexOf(participant2.participantType) !== -1
if (moderator1 !== moderator2) {
return moderator1 ? -1 : 1
}
const participant1Away = this.isNotAvailable(participant1)
const participant2Away = this.isNotAvailable(participant2)
if (participant1Away !== participant2Away) {
return participant1Away ? 1 : -1
}
return participant1.displayName.localeCompare(participant2.displayName)
},
},
}
</script>
|