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

ModerationSettings.vue « ConversationSettings « components « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 85a93f160529d6b3c95db02194aee69d6f6c984c (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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!--
  - @copyright Copyright (c) 2020 Vincent Petry <vincent@nextcloud.com>
  -
  - @author Vincent Petry <vincent@nextcloud.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>
		<div class="app-settings-subsection">
			<div id="moderation_settings_listable_conversation_hint" class="app-settings-section__hint">
				{{ t('spreed', 'Defines who can find this conversation') }}
			</div>
			<div>
				<label for="moderation_settings_listable_conversation_input">{{ t('spreed', 'Listable for') }}</label>
				<Multiselect id="moderation_settings_listable_conversation_input"
					v-model="listable"
					:options="listableOptions"
					:placeholder="t('spreed', 'Listable for')"
					label="label"
					track-by="value"
					:disabled="isListableLoading"
					aria-describedby="moderation_settings_listable_conversation_hint"
					@input="saveListable" />
			</div>
		</div>
		<div class="app-settings-subsection">
			<div id="moderation_settings_lock_conversation_hint" class="app-settings-section__hint">
				{{ t('spreed', 'Locking the conversation prevents anyone to post messages or start calls.') }}
			</div>
			<div>
				<input id="moderation_settings_lock_conversation_checkbox"
					aria-describedby="moderation_settings_lock_conversation_hint"
					type="checkbox"
					class="checkbox"
					name="moderation_settings_lock_conversation_checkbox"
					:checked="isReadOnly"
					:disabled="isReadOnlyStateLoading"
					@change="toggleReadOnly">
				<label for="moderation_settings_lock_conversation_checkbox">{{ t('spreed', 'Lock conversation') }}</label>
			</div>
		</div>
		<div class="app-settings-subsection">
			<div id="moderation_settings_enable_lobby_hint" class="app-settings-section__hint">
				{{ t('spreed', 'Enabling the lobby only allows moderators to post messages.') }}
			</div>
			<div>
				<input id="moderation_settings_enable_lobby_checkbox"
					aria-describedby="moderation_settings_enable_lobby_hint"
					type="checkbox"
					class="checkbox"
					name="moderation_settings_enable_lobby_checkbox"
					:checked="hasLobbyEnabled"
					:disabled="isLobbyStateLoading"
					@change="toggleLobby">
				<label for="moderation_settings_enable_lobby_checkbox">{{ t('spreed', 'Enable lobby') }}</label>
			</div>
		</div>
		<div class="app-settings-subsection">
			<div v-if="hasLobbyEnabled" id="moderation_settings_lobby_timer_hint" class="app-settings-section__hint">
				{{ t('spreed', 'After the time limit the lobby will be automatically disabled.') }}
			</div>
			<div v-if="hasLobbyEnabled">
				<form
					:disabled="lobbyTimerFieldDisabled"
					@submit.prevent="saveLobbyTimer">
					<span class="icon-calendar-dark" />
					<div>
						<label for="moderation_settings_lobby_timer_field">{{ t('spreed', 'Meeting start time') }}</label>
					</div>
					<div>
						<DatetimePicker
							id="moderation_settings_lobby_timer_field"
							aria-describedby="moderation_settings_lobby_timer_hint"
							:value="lobbyTimer"
							:placeholder="t('spreed', 'Start time (optional)')"
							:disabled="lobbyTimerFieldDisabled"
							type="datetime"
							:input-class="['mx-input', { focusable: !lobbyTimerFieldDisabled }]"
							v-bind="dateTimePickerAttrs"
							@change="setNewLobbyTimer" />
						<button
							id="moderation_settings_lobby_timer_submit"
							:aria-label="t('spreed', 'Save meeting start time')"
							:disabled="lobbyTimerFieldDisabled"
							type="submit"
							class="icon icon-confirm-fade" />
					</div>
				</form>
			</div>
		</div>
		<SipSettings v-if="canUserEnableSIP" />
	</div>
</template>

<script>
import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { CONVERSATION, WEBINAR } from '../../constants'
import DatetimePicker from '@nextcloud/vue/dist/Components/DatetimePicker'
import SipSettings from './SipSettings'

const listableOptions = [
	{ value: CONVERSATION.LISTABLE.NONE, label: t('spreed', 'None') },
	{ value: CONVERSATION.LISTABLE.USERS, label: t('spreed', 'Registered users') },
	{ value: CONVERSATION.LISTABLE.ALL, label: t('spreed', 'Everyone') },
]

export default {
	name: 'ModerationSettings',

	components: {
		Multiselect,
		DatetimePicker,
		SipSettings,
	},

	data() {
		return {
			isReadOnlyStateLoading: false,
			isListableLoading: false,
			isLobbyStateLoading: false,
			isLobbyTimerLoading: false,
			newLobbyTimer: null,
			listableOptions,
			listable: null,
		}
	},

	computed: {
		canUserEnableSIP() {
			return this.conversation.canEnableSIP
		},

		token() {
			return this.$store.getters.getToken()
		},

		conversation() {
			return this.$store.getters.conversation(this.token) || this.$store.getters.dummyConversation
		},

		isReadOnly() {
			return this.conversation.readOnly === CONVERSATION.STATE.READ_ONLY
		},

		hasLobbyEnabled() {
			return this.conversation.lobbyState === WEBINAR.LOBBY.NON_MODERATORS
		},

		lobbyTimerFieldDisabled() {
			return this.isLobbyStateLoading || this.isLobbyTimerLoading
		},

		lobbyTimer() {
			// A timestamp of 0 means that there is no lobby, but it would be
			// interpreted as the Unix epoch by the DateTimePicker.
			if (this.conversation.lobbyTimer === 0) {
				return undefined
			}

			// PHP timestamp is second-based; JavaScript timestamp is
			// millisecond based.
			return new Date(this.conversation.lobbyTimer * 1000)
		},

		dateTimePickerAttrs() {
			return {
				format: 'YYYY-MM-DD HH:mm',
				firstDayOfWeek: window.firstDay + 1, // Provided by server
				lang: {
					days: window.dayNamesShort, // Provided by server
					months: window.monthNamesShort, // Provided by server
				},
				// Do not update the value until the confirm button has been
				// pressed. Otherwise it would not be possible to set a lobby
				// for today, because as soon as the day is selected the lobby
				// timer would be set, but as no time was set at that point the
				// lobby timer would be set to today at 00:00, which would
				// disable the lobby due to being in the past.
				confirm: true,
			}
		},
	},

	mounted() {
		this.listable = this.conversation.listable
	},

	methods: {
		async toggleReadOnly() {
			const newReadOnly = this.isReadOnly ? CONVERSATION.STATE.READ_WRITE : CONVERSATION.STATE.READ_ONLY
			this.isReadOnlyStateLoading = true
			try {
				await this.$store.dispatch('setReadOnlyState', {
					token: this.token,
					readOnly: newReadOnly,
				})
				if (newReadOnly) {
					showSuccess(t('spreed', 'You locked the conversation'))
				} else {
					showSuccess(t('spreed', 'You unlocked the conversation'))
				}
			} catch (e) {
				if (newReadOnly) {
					console.error('Error occurred when locking the conversation', e)
					showError(t('spreed', 'Error occurred when locking the conversation'))
				} else {
					console.error('Error updating read-only state', e)
					showError(t('spreed', 'Error occurred when unlocking the conversation'))
				}
			}
			this.isReadOnlyStateLoading = false
		},

		async saveListable(listable) {
			this.isListableLoading = true
			try {
				await this.$store.dispatch('setListable', {
					token: this.token,
					listable: listable.value,
				})
				showSuccess(t('spreed', 'You updated the listable scope'))
			} catch (e) {
				console.error('Error occurred when updating the listable scope', e)
				showError(t('spreed', 'Error occurred when updating the listable scope'))
				this.listable = this.conversation.listable
			}
			this.isListableLoading = false
		},

		async toggleLobby() {
			const newLobbyState = this.conversation.lobbyState !== WEBINAR.LOBBY.NON_MODERATORS
			this.isLobbyStateLoading = true
			try {
				await this.$store.dispatch('toggleLobby', {
					token: this.token,
					enableLobby: newLobbyState,
				})
				if (newLobbyState) {
					showSuccess(t('spreed', 'You restricted the conversation to moderators'))
				} else {
					showSuccess(t('spreed', 'You opened the conversation to everyone'))
				}
			} catch (e) {
				if (newLobbyState) {
					console.error('Error occurred when restricting the conversation to moderator', e)
					showError(t('spreed', 'Error occurred when restricting the conversation to moderator'))
				} else {
					console.error('Error occurred when opening the conversation to everyone', e)
					showError(t('spreed', 'Error occurred when opening the conversation to everyone'))
				}
			}
			this.isLobbyStateLoading = false
		},

		setNewLobbyTimer(date) {
			let timestamp = 0
			if (date) {
				// PHP timestamp is second-based; JavaScript timestamp is
				// millisecond based.
				timestamp = date.getTime() / 1000
			}

			this.newLobbyTimer = timestamp
		},

		async saveLobbyTimer() {
			this.isLobbyTimerLoading = true

			try {
				await this.$store.dispatch('setLobbyTimer', {
					token: this.token,
					timestamp: this.newLobbyTimer,
				})
				showSuccess(t('spreed', 'Start time has been updated'))
			} catch (e) {
				console.error('Error occurred while updating start time', e)
				showError(t('spreed', 'Error occurred while updating start time'))
			}

			this.isLobbyTimerLoading = false
		},
	},
}
</script>

<style lang="scss" scoped>
::v-deep .mx-input {
	margin: 0;
}

input[type=password] {
	width: 200px;
}
</style>