-
Notifications
You must be signed in to change notification settings - Fork 450
/
Copy pathFlowPostToConversation.vue
96 lines (91 loc) · 2.18 KB
/
FlowPostToConversation.vue
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
<template>
<div>
<Multiselect :value="currentRoom"
:options="roomOptions"
track-by="token"
label="displayName"
@input="(newValue) => newValue !== null && $emit('input', JSON.stringify({'m': currentMode.id, 't': newValue.token }))" />
<Multiselect :value="currentMode"
:options="modeOptions"
track-by="id"
label="text"
@input="(newValue) => newValue !== null && $emit('input', JSON.stringify({'m': newValue.id, 't': currentRoom.token }))" />
</div>
</template>
<script>
import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
import axios from '@nextcloud/axios'
import { FLOW, CONVERSATION } from '../constants'
export default {
name: 'FlowPostToConversation',
components: { Multiselect },
props: {
value: {
default: JSON.stringify({ 'm': '0', 't': '' }),
type: String,
},
},
data() {
return {
modeOptions: [
{
id: FLOW.MESSAGE_MODES.NO_MENTION,
text: t('spreed', 'Message without mention'),
},
{
id: FLOW.MESSAGE_MODES.SELF_MENTION,
text: t('spreed', 'Mention myself'),
},
{
id: FLOW.MESSAGE_MODES.ROOM_MENTION,
text: t('spreed', 'Mention room'),
},
],
roomOptions: [],
}
},
computed: {
currentRoom() {
if (this.value === '') {
return ''
}
const selectedRoom = JSON.parse(this.value).t
const newValue = this.roomOptions.find(option => option.token === selectedRoom)
if (typeof newValue === 'undefined') {
return ''
}
return newValue
},
currentMode() {
if (this.value === '') {
return this.modeOptions[0]
}
const selectedMode = JSON.parse(this.value).m
const newValue = this.modeOptions.find(option => option.id === selectedMode)
if (typeof newValue === 'undefined') {
return this.modeOptions[0]
}
return newValue
},
},
beforeMount() {
this.fetchRooms()
},
methods: {
fetchRooms() {
axios.get(OC.linkToOCS('/apps/spreed/api/v1', 2) + 'room').then((response) => {
this.roomOptions = response.data.ocs.data.filter(function(room) {
return room.readOnly === CONVERSATION.STATE.READ_WRITE
})
})
},
},
}
</script>
<style scoped>
.multiselect {
width: 100%;
margin: auto;
text-align: center;
}
</style>