Skip to content

Commit dc7c185

Browse files
committed
Introduce participant mixin
To remove duplication of the "get current participant" logic all over the place and also for future use. Signed-off-by: Vincent Petry <[email protected]>
1 parent 59288cd commit dc7c185

File tree

8 files changed

+65
-82
lines changed

8 files changed

+65
-82
lines changed

src/App.vue

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { emit } from '@nextcloud/event-bus'
6161
import browserCheck from './mixins/browserCheck'
6262
import duplicateSessionHandler from './mixins/duplicateSessionHandler'
6363
import isInCall from './mixins/isInCall'
64+
import participant from './mixins/participant'
6465
import talkHashCheck from './mixins/talkHashCheck'
6566
import { generateUrl } from '@nextcloud/router'
6667
import UploadEditor from './components/UploadEditor'
@@ -84,6 +85,7 @@ export default {
8485
talkHashCheck,
8586
duplicateSessionHandler,
8687
isInCall,
88+
participant,
8789
],
8890
8991
data() {
@@ -107,23 +109,6 @@ export default {
107109
return this.$store.getters.getUserId()
108110
},
109111
110-
participant() {
111-
if (typeof this.token === 'undefined') {
112-
return {
113-
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
114-
}
115-
}
116-
117-
const participantIndex = this.$store.getters.getParticipantIndex(this.token, this.$store.getters.getParticipantIdentifier())
118-
if (participantIndex !== -1) {
119-
return this.$store.getters.getParticipant(this.token, participantIndex)
120-
}
121-
122-
return {
123-
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
124-
}
125-
},
126-
127112
warnLeaving() {
128113
return !this.isLeavingAfterSessionConflict && this.isInCall
129114
},

src/FilesSidebarCallViewApp.vue

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
</template>
3232

3333
<script>
34-
import { PARTICIPANT } from './constants'
3534
import CallView from './components/CallView/CallView'
3635
import PreventUnload from 'vue-prevent-unload'
3736
import duplicateSessionHandler from './mixins/duplicateSessionHandler'
3837
import isInCall from './mixins/isInCall'
38+
import participant from './mixins/participant'
3939
import talkHashCheck from './mixins/talkHashCheck'
4040
import '@nextcloud/dialogs/styles/toast.scss'
4141
@@ -51,6 +51,7 @@ export default {
5151
mixins: [
5252
duplicateSessionHandler,
5353
isInCall,
54+
participant,
5455
talkHashCheck,
5556
],
5657
@@ -106,17 +107,6 @@ export default {
106107
return this.isInCall
107108
},
108109
109-
participant() {
110-
const participantIndex = this.$store.getters.getParticipantIndex(this.token, this.$store.getters.getParticipantIdentifier())
111-
if (participantIndex === -1) {
112-
return {
113-
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
114-
}
115-
}
116-
117-
return this.$store.getters.getParticipant(this.token, participantIndex)
118-
},
119-
120110
warnLeaving() {
121111
return !this.isLeavingAfterSessionConflict && this.showCallView
122112
},

src/PublicShareSidebar.vue

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import { loadState } from '@nextcloud/initial-state'
4949
import CallView from './components/CallView/CallView'
5050
import ChatView from './components/ChatView'
5151
import CallButton from './components/TopBar/CallButton'
52-
import { PARTICIPANT } from './constants'
5352
import { EventBus } from './services/EventBus'
5453
import { fetchConversation } from './services/conversationsService'
5554
import { getPublicShareConversationData } from './services/filesIntegrationServices'
@@ -61,6 +60,7 @@ import { signalingKill } from './utils/webrtc/index'
6160
import browserCheck from './mixins/browserCheck'
6261
import duplicateSessionHandler from './mixins/duplicateSessionHandler'
6362
import isInCall from './mixins/isInCall'
63+
import participant from './mixins/participant'
6464
import talkHashCheck from './mixins/talkHashCheck'
6565
import '@nextcloud/dialogs/styles/toast.scss'
6666
@@ -79,6 +79,7 @@ export default {
7979
browserCheck,
8080
duplicateSessionHandler,
8181
isInCall,
82+
participant,
8283
talkHashCheck,
8384
],
8485
@@ -114,17 +115,6 @@ export default {
114115
return this.state.isOpen
115116
},
116117
117-
participant() {
118-
const participantIndex = this.$store.getters.getParticipantIndex(this.token, this.$store.getters.getParticipantIdentifier())
119-
if (participantIndex === -1) {
120-
return {
121-
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
122-
}
123-
}
124-
125-
return this.$store.getters.getParticipant(this.token, participantIndex)
126-
},
127-
128118
warnLeaving() {
129119
return !this.isLeavingAfterSessionConflict && this.isInCall
130120
},

src/components/LeftSidebar/NewGroupConversation/NewGroupConversation.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export default {
189189
},
190190
191191
participant() {
192+
// TODO: use participant mixin ??
192193
if (this.$store.getters.getToken()) {
193194
return {
194195
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,

src/components/MessagesList/MessagesGroup/Message/Message.vue

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import FilePreview from './MessagePart/FilePreview'
8585
import Mention from './MessagePart/Mention'
8686
import RichText from '@juliushaertl/vue-richtext'
8787
import Quote from '../../../Quote'
88+
import participant from '../../../../mixins/participant'
8889
import { EventBus } from '../../../../services/EventBus'
8990
import emojiRegex from 'emoji-regex'
9091
import { PARTICIPANT, CONVERSATION } from '../../../../constants'
@@ -97,6 +98,10 @@ export default {
9798
tooltip: Tooltip,
9899
},
99100
101+
mixins: [
102+
participant,
103+
],
104+
100105
components: {
101106
Actions,
102107
ActionButton,
@@ -246,17 +251,6 @@ export default {
246251
return this.$store.getters.conversation(this.token)
247252
},
248253
249-
participant() {
250-
const participantIndex = this.$store.getters.getParticipantIndex(this.token, this.$store.getters.getParticipantIdentifier())
251-
if (participantIndex !== -1) {
252-
return this.$store.getters.getParticipant(this.token, participantIndex)
253-
}
254-
255-
return {
256-
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
257-
}
258-
},
259-
260254
messagesList() {
261255
return this.$store.getters.messagesList(this.token)
262256
},

src/components/TopBar/CallButton.vue

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import { CONVERSATION, PARTICIPANT, WEBINAR } from '../../constants'
5353
import browserCheck from '../../mixins/browserCheck'
5454
import isInCall from '../../mixins/isInCall'
55+
import participant from '../../mixins/participant'
5556
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
5657
import { emit } from '@nextcloud/event-bus'
5758
@@ -65,6 +66,7 @@ export default {
6566
mixins: [
6667
browserCheck,
6768
isInCall,
69+
participant,
6870
],
6971
7072
data() {
@@ -95,19 +97,6 @@ export default {
9597
}
9698
},
9799
98-
participant() {
99-
const participantIndex = this.$store.getters.getParticipantIndex(this.token, this.$store.getters.getParticipantIdentifier())
100-
if (participantIndex !== -1) {
101-
console.debug('Current participant found')
102-
return this.$store.getters.getParticipant(this.token, participantIndex)
103-
}
104-
105-
console.debug('Current participant not found')
106-
return {
107-
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
108-
}
109-
},
110-
111100
isBlockedByLobby() {
112101
return this.conversation.lobbyState === WEBINAR.LOBBY.NON_MODERATORS
113102
&& !this.isParticipantTypeModerator(this.conversation.participantType)

src/mixins/participant.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
*
3+
* @copyright Copyright (c) 2020 Vincent Petry <[email protected]>
4+
*
5+
* @license GNU AGPL version 3 or any later version
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
import { PARTICIPANT } from '../constants'
23+
24+
/**
25+
* A mixin to check retrieve the current participant object
26+
*
27+
* Components using this mixin require a "token" property.
28+
*/
29+
export default {
30+
31+
computed: {
32+
participant() {
33+
if (typeof this.token === 'undefined') {
34+
return {
35+
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
36+
}
37+
}
38+
39+
const participantIndex = this.$store.getters.getParticipantIndex(this.token, this.$store.getters.getParticipantIdentifier())
40+
if (participantIndex === -1) {
41+
return {
42+
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
43+
}
44+
}
45+
46+
return this.$store.getters.getParticipant(this.token, participantIndex)
47+
},
48+
},
49+
}

src/views/MainView.vue

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import TopBar from '../components/TopBar/TopBar'
2323
import { PARTICIPANT } from '../constants'
2424
import isInLobby from '../mixins/isInLobby'
2525
import isInCall from '../mixins/isInCall'
26+
import participant from '../mixins/participant'
2627
2728
export default {
2829
name: 'MainView',
@@ -36,6 +37,7 @@ export default {
3637
mixins: [
3738
isInLobby,
3839
isInCall,
40+
participant,
3941
],
4042
4143
props: {
@@ -50,23 +52,6 @@ export default {
5052
return this.$store.getters.conversation(this.token)
5153
},
5254
53-
participant() {
54-
if (typeof this.token === 'undefined') {
55-
return {
56-
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
57-
}
58-
}
59-
60-
const participantIndex = this.$store.getters.getParticipantIndex(this.token, this.$store.getters.getParticipantIdentifier())
61-
if (participantIndex !== -1) {
62-
return this.$store.getters.getParticipant(this.token, participantIndex)
63-
}
64-
65-
return {
66-
inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
67-
}
68-
},
69-
7055
showChatInSidebar() {
7156
return this.isInCall
7257
},

0 commit comments

Comments
 (0)