diff --git a/src/components/CallView/CallView.vue b/src/components/CallView/CallView.vue index d0bae872366..0da9fc9f86e 100644 --- a/src/components/CallView/CallView.vue +++ b/src/components/CallView/CallView.vue @@ -156,11 +156,12 @@ 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 { satisfyVersion } from '../../utils/satisfyVersion.ts' import { localMediaModel, localCallParticipantModel, callParticipantCollection } from '../../utils/webrtc/index.js' import RemoteVideoBlocker from '../../utils/webrtc/RemoteVideoBlocker.js' -const serverVersion = loadState('core', 'config', {}).versionstring ?? '29.0.0' -const serverSupportsBackgroundBlurred = '29.0.4'.localeCompare(serverVersion) < 1 +const serverVersion = loadState('core', 'config', {}).version ?? '29.0.0.0' +const serverSupportsBackgroundBlurred = satisfyVersion(serverVersion, '29.0.4.0') export default { name: 'CallView', @@ -201,9 +202,8 @@ export default { const screenshotMode = ref(false) provide('CallView:screenshotModeEnabled', screenshotMode) - const isBackgroundBlurred = ref(serverSupportsBackgroundBlurred - ? null - : BrowserStorage.getItem('background-blurred') !== 'false') + // Fallback ref for versions before v29.0.4 + const isBackgroundBlurred = ref(BrowserStorage.getItem('background-blurred') !== 'false') return { localMediaModel, diff --git a/src/components/SettingsDialog/SettingsDialog.vue b/src/components/SettingsDialog/SettingsDialog.vue index 980d71f98af..016ff70e92c 100644 --- a/src/components/SettingsDialog/SettingsDialog.vue +++ b/src/components/SettingsDialog/SettingsDialog.vue @@ -210,9 +210,10 @@ import { getTalkConfig } from '../../services/CapabilitiesManager.ts' import { useCustomSettings } from '../../services/SettingsAPI.ts' import { useSettingsStore } from '../../stores/settings.js' import { useSoundsStore } from '../../stores/sounds.js' +import { satisfyVersion } from '../../utils/satisfyVersion.ts' -const serverVersion = loadState('core', 'config', {}).versionstring ?? '29.0.0' -const serverSupportsBackgroundBlurred = '29.0.4'.localeCompare(serverVersion) < 1 +const serverVersion = loadState('core', 'config', {}).version ?? '29.0.0.0' +const serverSupportsBackgroundBlurred = satisfyVersion(serverVersion, '29.0.4.0') const isBackgroundBlurredState = serverSupportsBackgroundBlurred ? loadState('spreed', 'force_enable_blur_filter', '') // 'yes', 'no', '' @@ -313,11 +314,9 @@ export default { { configValue: 'no' }) } BrowserStorage.removeItem('background-blurred') - } else { + } else if (blurred === null) { // Fallback to BrowserStorage - if (blurred === null) { - BrowserStorage.setItem('background-blurred', 'true') - } + BrowserStorage.setItem('background-blurred', 'true') } }, @@ -374,12 +373,13 @@ export default { this.privacyLoading = false }, + /** + * Fallback method for versions before v29.0.4 + * @param {boolean} value whether background should be blurred + */ toggleBackgroundBlurred(value) { - if (serverSupportsBackgroundBlurred) { - return - } - this.isBackgroundBlurred = value ? 'true' : 'false' - BrowserStorage.setItem('background-blurred', value) + this.isBackgroundBlurred = value.toString() + BrowserStorage.setItem('background-blurred', this.isBackgroundBlurred) emit('set-background-blurred', value) }, diff --git a/src/utils/__tests__/satisfyVersion.spec.js b/src/utils/__tests__/satisfyVersion.spec.js new file mode 100644 index 00000000000..d32fb5e1951 --- /dev/null +++ b/src/utils/__tests__/satisfyVersion.spec.js @@ -0,0 +1,26 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { satisfyVersion } from '../satisfyVersion.ts' + +describe('satisfyVersion', () => { + const testCases = [ + // Older + ['29.1.4.3', '28.2.5.4', true], + ['29.1.4.3', '29.0.15.3', true], + ['29.1.4.3', '29.1.1.3', true], + ['29.1.4.3', '29.1.4.0', true], + // Exact + ['29.1.4.3', '29.1.4.3', true], + // Newer + ['29.1.4.3', '29.1.4.4', false], + ['29.1.4.3', '29.1.5.0', false], + ['29.1.4.3', '29.2.0.0', false], + ['29.1.4.3', '30.0.0.0', false], + ] + + it.each(testCases)('check if %s should satisfy requirement %s returns %s', (a, b, c) => { + expect(satisfyVersion(a, b)).toBe(c) + }) +}) diff --git a/src/utils/satisfyVersion.ts b/src/utils/satisfyVersion.ts new file mode 100644 index 00000000000..b3535d78bf6 --- /dev/null +++ b/src/utils/satisfyVersion.ts @@ -0,0 +1,26 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/** + * Checks if given version satisfy requirements (newer than) + * Versions are expected to have format like '29.1.4.3' + * @param version given version + * @param requirement version to compare against + */ +function satisfyVersion(version: string, requirement: string): boolean { + const versionMap = version.split('.').map(Number) + const requirementMap = requirement.split('.').map(Number) + + for (let i = 0; i < requirementMap.length; i++) { + if (versionMap[i] !== requirementMap[i]) { + return versionMap[i] > requirementMap[i] + } + } + return true +} + +export { + satisfyVersion, +}