Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migrate settingsService to TS #13971

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/AdminSettings/SIPBridge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
import NcTextArea from '@nextcloud/vue/dist/Components/NcTextArea.js'

import { EventBus } from '../../services/EventBus.ts'
import { setSIPSettings } from '../../services/settingsService.js'
import { setSIPSettings } from '../../services/settingsService.ts'
import { getWelcomeMessage } from '../../services/signalingService.js'

export default {
Expand Down Expand Up @@ -194,11 +194,15 @@ export default {
this.loading = true
this.saveLabel = t('spreed', 'Saving …')

const groups = this.sipGroups.map(group => {
const sipGroups = this.sipGroups.map(group => {
return group.id
})

await setSIPSettings(groups, this.sharedSecret, this.dialInInfo)
await setSIPSettings({
sipGroups,
sharedSecret: this.sharedSecret,
dialInInfo: this.dialInInfo,
})
if (this.currentSetup.dialOutEnabled !== this.dialOutEnabled) {
await OCP.AppConfig.setValue('spreed', 'sip_dialout', this.dialOutEnabled ? 'yes' : 'no')
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/SettingsDialog/SettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ import { PRIVACY } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
import { useCustomSettings } from '../../services/SettingsAPI.ts'
import { setUserConfig } from '../../services/settingsService.js'
import { setUserConfig } from '../../services/settingsService.ts'
import { useSettingsStore } from '../../stores/settings.js'
import { useSoundsStore } from '../../stores/sounds.js'
import { isMac } from '../../utils/browserCheck.ts'
Expand Down
107 changes: 0 additions & 107 deletions src/services/settingsService.js

This file was deleted.

111 changes: 111 additions & 0 deletions src/services/settingsService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'

import BrowserStorage from './BrowserStorage.js'
import type {
setSipSettingsParams,
setSipSettingsResponse,
setUserSettingsParams,
setUserSettingsResponse,
UserPreferencesResponse,
} from '../types/index.ts'

/**
* Sets the attachment folder setting for the user
*
* @param path The name of the folder
*/
const setAttachmentFolder = async function(path: string): setUserSettingsResponse {
return axios.post(generateOcsUrl('apps/spreed/api/v1/settings/user'), {
key: 'attachment_folder',
value: path,
} as setUserSettingsParams)
}

/**
* Sets the read status privacy setting for the user
*
* @param privacy The selected value, either 0 or 1
*/
const setReadStatusPrivacy = async function(privacy: number): setUserSettingsResponse {
return axios.post(generateOcsUrl('apps/spreed/api/v1/settings/user'), {
key: 'read_status_privacy',
value: privacy,
} as setUserSettingsParams)
}

/**
* Sets the typing status privacy setting for the user
*
* @param privacy The selected value, either 0 or 1
*/
const setTypingStatusPrivacy = async function(privacy: number): setUserSettingsResponse {
return axios.post(generateOcsUrl('apps/spreed/api/v1/settings/user'), {
key: 'typing_privacy',
value: privacy,
} as setUserSettingsParams)
}

/**
* Save the SIP settings
*
* @param payload payload
* @param payload.sipGroups The groups allowed to enable SIP on a conversation
* @param payload.sharedSecret The shared secret which is used by the SIP server to authenticate
* @param payload.dialInInfo The dial-in Information displayed in the email and sidebar
*/
const setSIPSettings = async function({ sipGroups, sharedSecret, dialInInfo }: setSipSettingsParams): setSipSettingsResponse {
return axios.post(generateOcsUrl('apps/spreed/api/v1/settings/sip'), {
sipGroups,
sharedSecret,
dialInInfo,
} as setSipSettingsParams)
}

const setPlaySounds = async function(hasUserAccount: boolean, value: 'yes'|'no') {
if (hasUserAccount) {
return axios.post(generateOcsUrl('apps/spreed/api/v1/settings/user'), {
key: 'play_sounds',
value,
})
} else {
BrowserStorage.setItem('play_sounds', value)
}
}

const setStartWithoutMedia = async function(value: boolean) {
return setUserConfig('spreed', 'calls_start_without_media', value ? 'yes' : 'no')
}

const setBlurVirtualBackground = async function(value: boolean) {
return setUserConfig('spreed', 'blur_virtual_background', value ? 'yes' : 'no')
}

/**
* Set user config using provisioning API
*
* @param appId - app id
* @param configKey - key of the config to set
* @param configValue - value to set
*/
const setUserConfig = async function(appId: string, configKey: string, configValue: string): UserPreferencesResponse {
return axios.post(generateOcsUrl('apps/provisioning_api/api/v1/config/users/{appId}/{configKey}', { appId, configKey }), {
configValue,
})
}

export {
setAttachmentFolder,
setBlurVirtualBackground,
setReadStatusPrivacy,
setTypingStatusPrivacy,
setSIPSettings,
setPlaySounds,
setStartWithoutMedia,
setUserConfig,
}
2 changes: 1 addition & 1 deletion src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
getFileTemplates,
shareFile,
} from '../services/filesSharingServices.js'
import { setAttachmentFolder } from '../services/settingsService.js'
import { setAttachmentFolder } from '../services/settingsService.ts'
import { useChatExtrasStore } from '../stores/chatExtras.js'
import {
hasDuplicateUploadNames,
Expand Down
2 changes: 1 addition & 1 deletion src/store/fileUploadStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import storeConfig from './storeConfig.js'
import fileUploadStore from './fileUploadStore.js'
import { getDavClient } from '../services/DavClient.js'
import { shareFile } from '../services/filesSharingServices.js'
import { setAttachmentFolder } from '../services/settingsService.js'
import { setAttachmentFolder } from '../services/settingsService.ts'
import { findUniquePath } from '../utils/fileUpload.js'

jest.mock('../services/DavClient', () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/stores/__tests__/settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { loadState } from '@nextcloud/initial-state'

import { PRIVACY } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { setReadStatusPrivacy, setTypingStatusPrivacy } from '../../services/settingsService.js'
import { setReadStatusPrivacy, setTypingStatusPrivacy } from '../../services/settingsService.ts'
import { generateOCSResponse } from '../../test-helpers.js'
import { useSettingsStore } from '../settings.js'

Expand Down
2 changes: 1 addition & 1 deletion src/stores/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
setTypingStatusPrivacy,
setStartWithoutMedia,
setBlurVirtualBackground,
} from '../services/settingsService.js'
} from '../services/settingsService.ts'

/**
* @typedef {string} Token
Expand Down
2 changes: 1 addition & 1 deletion src/stores/sounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { loadState } from '@nextcloud/initial-state'
import { generateFilePath } from '@nextcloud/router'

import BrowserStorage from '../services/BrowserStorage.js'
import { setPlaySounds } from '../services/settingsService.js'
import { setPlaySounds } from '../services/settingsService.ts'

const hasUserAccount = Boolean(getCurrentUser()?.uid)
/**
Expand Down
10 changes: 10 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,13 @@ export type OutOfOfficeResponse = ApiResponseUnwrapped<{
replacementUserDisplayName?: string|null,
}
}>

// User preferences response
// from https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-user-preferences-api.html
export type UserPreferencesResponse = ApiResponseUnwrapped<unknown>

// Settings
export type setSipSettingsParams = Required<operations['settings-setsip-settings']>['requestBody']['content']['application/json']
export type setSipSettingsResponse = ApiResponse<operations['settings-setsip-settings']['responses'][200]['content']['application/json']>
export type setUserSettingsParams = Required<operations['settings-set-user-setting']>['requestBody']['content']['application/json']
export type setUserSettingsResponse = ApiResponse<operations['settings-set-user-setting']['responses'][200]['content']['application/json']>
Loading