Skip to content

Commit

Permalink
feat(capabilities): apply manager for dynamic capabilities (conversat…
Browse files Browse the repository at this point in the history
…ion related)

Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed May 8, 2024
1 parent 3a85d39 commit 0bf4beb
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 125 deletions.
9 changes: 5 additions & 4 deletions src/components/CallView/CallView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
<script>
import debounce from 'debounce'

import { getCapabilities } from '@nextcloud/capabilities'
import { showMessage } from '@nextcloud/dialogs'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'

Expand All @@ -136,12 +135,11 @@ import ViewerOverlayCallView from './shared/ViewerOverlayCallView.vue'
import { SIMULCAST } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { fetchPeers } from '../../services/callsService.js'
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
import { EventBus } from '../../services/EventBus.js'
import { localMediaModel, localCallParticipantModel, callParticipantCollection } from '../../utils/webrtc/index.js'
import RemoteVideoBlocker from '../../utils/webrtc/RemoteVideoBlocker.js'

const supportedReactions = getCapabilities()?.spreed?.config?.call?.['supported-reactions']

export default {
name: 'CallView',

Expand Down Expand Up @@ -175,7 +173,6 @@ export default {

setup() {
return {
supportedReactions,
localMediaModel,
localCallParticipantModel,
callParticipantCollection,
Expand Down Expand Up @@ -329,6 +326,10 @@ export default {
presenterVideoBlockerEnabled() {
return this.sharedDatas[this.shownRemoteScreenPeerId]?.remoteVideoBlocker?.isVideoEnabled()
},

supportedReactions() {
return getTalkConfig(this.token, 'call', 'supported-reactions')
},
},

watch: {
Expand Down
10 changes: 3 additions & 7 deletions src/components/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@
<script>
import ChevronDoubleDown from 'vue-material-design-icons/ChevronDoubleDown.vue'

import { getCapabilities } from '@nextcloud/capabilities'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'

import GuestWelcomeWindow from './GuestWelcomeWindow.vue'
Expand All @@ -72,12 +70,10 @@ import NewMessageUploadEditor from './NewMessage/NewMessageUploadEditor.vue'
import TransitionWrapper from './UIShared/TransitionWrapper.vue'

import { CONVERSATION, PARTICIPANT } from '../constants.js'
import { getTalkConfig, hasTalkFeature } from '../services/CapabilitiesManager.ts'
import { EventBus } from '../services/EventBus.js'
import { useChatExtrasStore } from '../stores/chatExtras.js'

const attachmentsAllowed = getCapabilities()?.spreed?.config?.attachments?.allowed
const supportFederationV1 = getCapabilities()?.spreed?.features?.includes('federation-v1')

export default {

name: 'ChatView',
Expand Down Expand Up @@ -124,10 +120,10 @@ export default {
},

canUploadFiles() {
return attachmentsAllowed && this.$store.getters.getUserId()
return getTalkConfig(this.token, 'attachments', 'allowed') && this.$store.getters.getUserId()
&& this.$store.getters.getAttachmentFolderFreeSpace() !== 0
&& (this.conversation.permissions & PARTICIPANT.PERMISSIONS.CHAT)
&& (!supportFederationV1 || !this.conversation.remoteServer)
&& (!hasTalkFeature(this.token, 'federation-v1') || !this.conversation.remoteServer)
},

isDragAndDropBlocked() {
Expand Down
22 changes: 9 additions & 13 deletions src/components/ConversationSettings/ConversationSettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</NcAppSettingsSection>

<!-- Bots settings -->
<NcAppSettingsSection v-if="selfIsOwnerOrModerator && hasBotV1API"
<NcAppSettingsSection v-if="selfIsOwnerOrModerator && supportBotsV1"
id="bots"
:name="t('spreed', 'Bots')">
<BotsSettings :token="token" />
Expand All @@ -92,7 +92,6 @@
</template>

<script>
import { getCapabilities } from '@nextcloud/capabilities'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { loadState } from '@nextcloud/initial-state'

Expand All @@ -116,13 +115,9 @@ import RecordingConsentSettings from './RecordingConsentSettings.vue'
import SipSettings from './SipSettings.vue'

import { CALL, PARTICIPANT, CONVERSATION } from '../../constants.js'
import { getTalkConfig, hasTalkFeature } from '../../services/CapabilitiesManager.ts'
import { useSettingsStore } from '../../stores/settings.js'

const recordingEnabled = getCapabilities()?.spreed?.config?.call?.recording || false
const recordingConsentCapability = getCapabilities()?.spreed?.features?.includes('recording-consent')
const recordingConsent = getCapabilities()?.spreed?.config?.call?.['recording-consent'] !== CALL.RECORDING_CONSENT.OFF
const supportFederationV1 = getCapabilities()?.spreed?.features?.includes('federation-v1')

export default {
name: 'ConversationSettingsDialog',

Expand Down Expand Up @@ -181,7 +176,7 @@ export default {
},

showMediaSettingsToggle() {
return (!supportFederationV1 || !this.conversation.remoteServer)
return (!hasTalkFeature(this.token, 'federation-v1') || !this.conversation.remoteServer)
},

showMediaSettings() {
Expand Down Expand Up @@ -218,19 +213,20 @@ export default {
return this.conversation.objectType === CONVERSATION.OBJECT_TYPE.BREAKOUT_ROOM
},

hasBotV1API() {
return getCapabilities()?.spreed?.features?.includes('bots-v1')
supportBotsV1() {
return hasTalkFeature(this.token, 'bots-v1')
},

canConfigureBreakoutRooms() {
const breakoutRoomsEnabled = getCapabilities()?.spreed?.config?.call?.['breakout-rooms'] || false
return this.canFullModerate
&& breakoutRoomsEnabled
&& (getTalkConfig(this.token, 'call', 'breakout-rooms') || false)
&& this.conversation.type === CONVERSATION.TYPE.GROUP
},

recordingConsentAvailable() {
return recordingEnabled && recordingConsentCapability && recordingConsent
return (getTalkConfig(this.token, 'call', 'recording') || false)
&& hasTalkFeature(this.token, 'recording-consent')
&& getTalkConfig(this.token, 'call', 'recording-consent') !== CALL.RECORDING_CONSENT.OFF
},

recordingConsentRequired() {
Expand Down
7 changes: 2 additions & 5 deletions src/components/ConversationSettings/NotificationsSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ import Account from 'vue-material-design-icons/Account.vue'
import VolumeHigh from 'vue-material-design-icons/VolumeHigh.vue'
import VolumeOff from 'vue-material-design-icons/VolumeOff.vue'

import { getCapabilities } from '@nextcloud/capabilities'

import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'

import { PARTICIPANT } from '../../constants.js'

const supportFederationV1 = getCapabilities()?.spreed?.features?.includes('federation-v1')
import { hasTalkFeature } from '../../services/CapabilitiesManager.ts'

const notificationLevels = [
{ value: PARTICIPANT.NOTIFY.ALWAYS, label: t('spreed', 'All messages') },
Expand Down Expand Up @@ -80,7 +77,7 @@ export default {

computed: {
showCallNotificationSettings() {
return (!supportFederationV1 || !this.conversation.remoteServer)
return (!hasTalkFeature(this.conversation.token, 'federation-v1') || !this.conversation.remoteServer)
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
</template>

<script>
import { getCapabilities } from '@nextcloud/capabilities'
import { showError, showSuccess } from '@nextcloud/dialogs'

import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'

import { CALL, CONVERSATION } from '../../constants.js'

const recordingConsent = getCapabilities()?.spreed?.config?.call?.['recording-consent']
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'

export default {
name: 'RecordingConsentSettings',
Expand Down Expand Up @@ -69,7 +67,7 @@ export default {
},

isGlobalConsent() {
return recordingConsent === CALL.RECORDING_CONSENT.REQUIRED
return getTalkConfig(this.token, 'call', 'recording-consent') === CALL.RECORDING_CONSENT.REQUIRED
},

isBreakoutRoomStarted() {
Expand Down
15 changes: 8 additions & 7 deletions src/components/MediaSettings/MediaSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ import Creation from 'vue-material-design-icons/Creation.vue'
import VideoIcon from 'vue-material-design-icons/Video.vue'
import VideoOff from 'vue-material-design-icons/VideoOff.vue'

import { getCapabilities } from '@nextcloud/capabilities'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'

import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
Expand All @@ -215,13 +214,11 @@ import { useDevices } from '../../composables/useDevices.js'
import { useIsInCall } from '../../composables/useIsInCall.js'
import { AVATAR, CALL, PARTICIPANT, VIRTUAL_BACKGROUND } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
import { useGuestNameStore } from '../../stores/guestName.js'
import { useSettingsStore } from '../../stores/settings.js'
import { localMediaModel } from '../../utils/webrtc/index.js'

const recordingEnabled = getCapabilities()?.spreed?.config?.call?.recording || false
const recordingConsent = getCapabilities()?.spreed?.config?.call?.['recording-consent']

export default {
name: 'MediaSettings',

Expand Down Expand Up @@ -393,12 +390,16 @@ export default {
},

canModerateRecording() {
return this.canFullModerate && recordingEnabled
return this.canFullModerate && (getTalkConfig(this.token, 'call', 'recording') || false)
},

recordingConsent() {
return getTalkConfig(this.token, 'call', 'recording-consent')
},

isRecordingConsentRequired() {
return recordingConsent === CALL.RECORDING_CONSENT.REQUIRED
|| (recordingConsent === CALL.RECORDING_CONSENT.OPTIONAL && this.conversation.recordingConsent === CALL.RECORDING_CONSENT.REQUIRED)
return this.recordingConsent === CALL.RECORDING_CONSENT.REQUIRED
|| (this.recordingConsent === CALL.RECORDING_CONSENT.OPTIONAL && this.conversation.recordingConsent === CALL.RECORDING_CONSENT.REQUIRED)
},

showRecordingWarning() {
Expand Down
24 changes: 11 additions & 13 deletions src/components/MediaSettings/VideoBackgroundEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,16 @@ import CheckBold from 'vue-material-design-icons/CheckBold.vue'
import Folder from 'vue-material-design-icons/Folder.vue'
import Upload from 'vue-material-design-icons/Upload.vue'

import { getCapabilities } from '@nextcloud/capabilities'
import { showError } from '@nextcloud/dialogs'
import { FilePickerVue } from '@nextcloud/dialogs/filepicker.js'
import { imagePath, generateUrl } from '@nextcloud/router'

import { VIRTUAL_BACKGROUND } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
import { getDavClient } from '../../services/DavClient.js'
import { findUniquePath } from '../../utils/fileUpload.js'

const canUploadBackgrounds = getCapabilities()?.spreed?.config?.call?.['can-upload-background']
const predefinedBackgrounds = getCapabilities()?.spreed?.config?.call?.['predefined-backgrounds']
const predefinedBackgroundLabels = {
'1_office': t('spreed', 'Select virtual office background'),
'2_home': t('spreed', 'Select virtual home background'),
Expand Down Expand Up @@ -122,36 +120,36 @@ export default {

emits: ['update-background'],

setup() {
return {
canUploadBackgrounds,
predefinedBackgrounds,
}
},

data() {
return {
selectedBackground: undefined,
getCapabilities,
showFilePicker: false,
}
},

computed: {
canUploadBackgrounds() {
return getTalkConfig(this.token, 'call', 'can-upload-background')
},

predefinedBackgrounds() {
return getTalkConfig(this.token, 'call', 'predefined-backgrounds')
},

isCustomBackground() {
return this.selectedBackground !== 'none'
&& this.selectedBackground !== 'blur'
&& !this.predefinedBackgroundsURLs.includes(this.selectedBackground)
},

predefinedBackgroundsURLs() {
return predefinedBackgrounds.map(fileName => {
return this.predefinedBackgrounds.map(fileName => {
return imagePath('spreed', 'backgrounds/' + fileName)
})
},

hasBackgroundsCapability() {
return !!predefinedBackgrounds
return !!this.predefinedBackgrounds
},

relativeBackgroundsFolderPath() {
Expand Down
12 changes: 6 additions & 6 deletions src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
import UnfoldLess from 'vue-material-design-icons/UnfoldLessHorizontal.vue'
import UnfoldMore from 'vue-material-design-icons/UnfoldMoreHorizontal.vue'

import { getCapabilities } from '@nextcloud/capabilities'
import { showError, showSuccess, showWarning, TOAST_DEFAULT_TIMEOUT } from '@nextcloud/dialogs'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
Expand All @@ -105,14 +104,11 @@ import Poll from './MessagePart/Poll.vue'
import Reactions from './MessagePart/Reactions.vue'

import { CONVERSATION, PARTICIPANT } from '../../../../constants.js'
import { getTalkConfig } from '../../../../services/CapabilitiesManager.ts'
import { EventBus } from '../../../../services/EventBus.js'
import { useChatExtrasStore } from '../../../../stores/chatExtras.js'
import { getItemTypeFromMessage } from '../../../../utils/getItemTypeFromMessage.ts'

const isTranslationAvailable = getCapabilities()?.spreed?.config?.chat?.['has-translation-providers']
// Fallback for the desktop client when connecting to Talk 17
?? getCapabilities()?.spreed?.config?.chat?.translations?.length > 0

export default {
name: 'Message',

Expand Down Expand Up @@ -291,7 +287,11 @@ export default {

emits: ['toggle-combined-system-message'],

setup() {
setup(props) {
const isTranslationAvailable = getTalkConfig(props.token, 'chat', 'has-translation-providers')
// Fallback for the desktop client when connecting to Talk 17
?? getTalkConfig(props.token, 'chat', 'translations')?.length > 0

return {
isTranslationAvailable,
chatExtrasStore: useChatExtrasStore(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ import Reply from 'vue-material-design-icons/Reply.vue'
import Share from 'vue-material-design-icons/Share.vue'
import Translate from 'vue-material-design-icons/Translate.vue'

import { getCapabilities } from '@nextcloud/capabilities'
import { showError, showSuccess } from '@nextcloud/dialogs'
import moment from '@nextcloud/moment'

Expand All @@ -288,14 +287,13 @@ import { emojiSearch } from '@nextcloud/vue/dist/Functions/emoji.js'

import { useMessageInfo } from '../../../../../composables/useMessageInfo.js'
import { CONVERSATION, ATTENDEE } from '../../../../../constants.js'
import { hasTalkFeature } from '../../../../../services/CapabilitiesManager.ts'
import { getMessageReminder, removeMessageReminder, setMessageReminder } from '../../../../../services/remindersService.js'
import { useIntegrationsStore } from '../../../../../stores/integrations.js'
import { useReactionsStore } from '../../../../../stores/reactions.js'
import { copyConversationLinkToClipboard } from '../../../../../utils/handleUrl.ts'
import { parseMentions } from '../../../../../utils/textParse.ts'

const supportReminders = getCapabilities()?.spreed?.features?.includes('remind-me-later')

export default {
name: 'MessageButtonsBar',

Expand Down Expand Up @@ -473,6 +471,7 @@ export default {
isConversationReadOnly,
isConversationModifiable,
} = useMessageInfo(token, id)
const supportReminders = hasTalkFeature(token.value, 'remind-me-later')

return {
messageActions,
Expand Down
Loading

0 comments on commit 0bf4beb

Please sign in to comment.