Skip to content

Commit

Permalink
Add checkbox for locking conversation
Browse files Browse the repository at this point in the history
Added logic for setting a conversation to read-only.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
  • Loading branch information
PVince81 committed Oct 8, 2020
1 parent 39e77a5 commit 8f049ee
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/TopBar/TopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
@click="handleRenameConversation">
{{ t('spreed', 'Rename conversation') }}
</ActionButton>
<ActionCheckbox
:checked="isReadOnly"
:disabled="readOnlyStateLoading"
@change="toggleReadOnly">
{{ t('spreed', 'Lock conversation') }}
</ActionCheckbox>
<ActionSeparator
v-if="canFullModerate" />
<ActionCheckbox
Expand Down Expand Up @@ -203,6 +209,7 @@ export default {
// Switch for the password-editing operation
isEditingPassword: false,
lobbyTimerLoading: false,
readOnlyStateLoading: false,
}
},
Expand Down Expand Up @@ -316,6 +323,9 @@ export default {
hasLobbyEnabled() {
return this.conversation.lobbyState === WEBINAR.LOBBY.NON_MODERATORS
},
isReadOnly() {
return this.conversation.readOnly === CONVERSATION.STATE.READ_ONLY
},
isPasswordProtected() {
return this.conversation.hasPassword
},
Expand Down Expand Up @@ -456,6 +466,16 @@ export default {
this.lobbyTimerLoading = false
},
async toggleReadOnly() {
this.readOnlyStateLoading = true
await this.$store.dispatch('setReadOnlyState', {
token: this.token,
readOnly: this.isReadOnly ? CONVERSATION.STATE.READ_WRITE : CONVERSATION.STATE.READ_ONLY,
})
this.readOnlyStateLoading = false
},
async handlePasswordDisable() {
// disable the password protection for the current conversation
if (this.conversation.hasPassword) {
Expand Down
17 changes: 17 additions & 0 deletions src/services/conversationsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,22 @@ const changeLobbyState = async function(token, newState, timestamp) {
}
}

/**
* Change the read-only state
* @param {string} token The token of the conversation to be modified
* @param {int} readOnly The new read-only state to set
*/
const changeReadOnlyState = async function(token, readOnly) {
try {
const response = await axios.put(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/read-only`, {
state: readOnly,
})
return response
} catch (error) {
console.debug('Error while updating read-only state: ', error)
}
}

export {
fetchConversations,
fetchConversation,
Expand All @@ -312,6 +328,7 @@ export {
makePublic,
makePrivate,
changeLobbyState,
changeReadOnlyState,
setConversationPassword,
setConversationName,
}
13 changes: 13 additions & 0 deletions src/store/conversationsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
makePublic,
makePrivate,
changeLobbyState,
changeReadOnlyState,
addToFavorites,
removeFromFavorites,
} from '../services/conversationsService'
Expand Down Expand Up @@ -193,6 +194,18 @@ const actions = {
commit('addConversation', conversation)
},

async setReadOnlyState({ commit, getters }, { token, readOnly }) {
const conversation = Object.assign({}, getters.conversations[token])
if (!conversation) {
return
}

await changeReadOnlyState(token, readOnly)
conversation.readOnly = readOnly

commit('addConversation', conversation)
},

async setLobbyTimer({ commit, getters }, { token, timestamp }) {
const conversation = Object.assign({}, getters.conversations[token])
if (!conversation) {
Expand Down

0 comments on commit 8f049ee

Please sign in to comment.