Skip to content

Commit

Permalink
feat(conversations): add user toggle for compact list
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Dec 13, 2024
1 parent 20840eb commit 54c7c21
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/__mocks__/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const mockedCapabilities: Capabilities = {
conversations: {
'can-create': true,
'force-passwords': false,
'compact-list': 0,
},
federation: {
enabled: false,
Expand Down Expand Up @@ -167,6 +168,7 @@ export const mockedCapabilities: Capabilities = {
],
conversations: [
'can-create',
'compact-list',
],
federation: [],
previews: [
Expand Down
36 changes: 35 additions & 1 deletion src/components/SettingsDialog/SettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@
@close="showFilePicker = false" />
</div>
</NcAppSettingsSection>
<NcAppSettingsSection v-if="!isGuest && supportConversationsListStyle"
id="talk_appearance"
:name="t('spreed', 'Appearance')"
class="app-settings-section">
<NcCheckboxRadioSwitch id="conversations_compact_list"
:model-value="conversationsListStyle"
:disabled="appearanceLoading"
type="switch"
class="checkbox"
@update:modelValue="toggleConversationsListStyle">
{{ t('spreed', 'Show my conversations list in compact mode') }}
</NcCheckboxRadioSwitch>
</NcAppSettingsSection>
<NcAppSettingsSection v-if="!isGuest"
id="privacy"
:name="t('spreed', 'Privacy')"
Expand Down Expand Up @@ -212,7 +225,7 @@ import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadi

import MediaDevicesPreview from './MediaDevicesPreview.vue'

import { PRIVACY } from '../../constants.js'
import { CONVERSATION, PRIVACY } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
import { useCustomSettings } from '../../services/SettingsAPI.ts'
Expand All @@ -230,6 +243,8 @@ const isBackgroundBlurredState = serverSupportsBackgroundBlurred
: BrowserStorage.getItem('background-blurred') // 'true', 'false', null
const supportTypingStatus = getTalkConfig('local', 'chat', 'typing-privacy') !== undefined
const supportStartWithoutMedia = getTalkConfig('local', 'call', 'start-without-media') !== undefined
const supportConversationsListStyle = getTalkConfig('local', 'conversations', 'compact-list') !== undefined

export default {
name: 'SettingsDialog',

Expand Down Expand Up @@ -258,6 +273,7 @@ export default {
serverSupportsBackgroundBlurred,
customSettingsSections,
supportStartWithoutMedia,
supportConversationsListStyle,
}
},

Expand All @@ -266,6 +282,7 @@ export default {
showSettings: false,
showFilePicker: false,
attachmentFolderLoading: true,
appearanceLoading: false,
privacyLoading: false,
playSoundsLoading: false,
mediaLoading: false,
Expand Down Expand Up @@ -301,6 +318,10 @@ export default {
return this.settingsStore.startWithoutMedia
},

conversationsListStyle() {
return this.settingsStore.conversationsListStyle !== CONVERSATION.APPEARANCE.DEFAULT
},

settingsUrl() {
return generateUrl('/settings/user/notifications')
},
Expand Down Expand Up @@ -390,6 +411,19 @@ export default {
this.privacyLoading = false
},

async toggleConversationsListStyle(value) {
this.appearanceLoading = true
try {
await this.settingsStore.setConversationsListStyle(
value ? CONVERSATION.APPEARANCE.COMPACT : CONVERSATION.APPEARANCE.DEFAULT
)
showSuccess(t('spreed', 'Your personal setting has been saved'))
} catch (exception) {
showError(t('spreed', 'Error while setting personal setting'))
}
this.appearanceLoading = false
},

/**
* Fallback method for versions before v29.0.4
* @param {boolean} value whether background should be blurred
Expand Down
5 changes: 5 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ export const CONVERSATION = {
DEFAULT: '',
},

APPEARANCE: {
DEFAULT: 0,
COMPACT: 1,
},

MAX_NAME_LENGTH: 255,
MAX_DESCRIPTION_LENGTH: 500,
}
Expand Down
5 changes: 5 additions & 0 deletions src/services/settingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ const setBlurVirtualBackground = async function(value: boolean) {
return setUserConfig('spreed', 'blur_virtual_background', value ? 'yes' : 'no')
}

const setConversationsListStyle = async function(value: number) {
return setUserConfig('spreed', 'conversations_compact_list', value.toString())
}

/**
* Set user config using provisioning API
*
Expand All @@ -102,6 +106,7 @@ const setUserConfig = async function(appId: string, configKey: string, configVal
export {
setAttachmentFolder,
setBlurVirtualBackground,
setConversationsListStyle,
setReadStatusPrivacy,
setTypingStatusPrivacy,
setSIPSettings,
Expand Down
19 changes: 8 additions & 11 deletions src/stores/__tests__/settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ describe('settingsStore', () => {
})

describe('media settings dialog', () => {
// FIXME: BrowserStorage.getItem('cachedConversations') is always called whenever capabilitiesManager.ts is imported
const EXTRA_CALLS = 3
it('shows correct stored values for conversations', () => {
// Arrange
settingsStore.showMediaSettings['token-1'] = true
Expand All @@ -70,10 +72,7 @@ describe('settingsStore', () => {

// Assert
expect(results).toEqual([true, false])
// It's always called at least once : BrowserStorage.getItem('cachedConversations')
// Whenever capabilitiesManager.ts is imported
// +2
expect(BrowserStorage.getItem).toHaveBeenCalledTimes(2)
expect(BrowserStorage.getItem).toHaveBeenCalledTimes(EXTRA_CALLS)
})

it('shows correct values received from BrowserStorage', () => {
Expand All @@ -90,11 +89,10 @@ describe('settingsStore', () => {

// Assert
expect(results).toEqual([true, true, false])
// It's always called at least once : BrowserStorage.getItem('cachedConversations') (+2)
expect(BrowserStorage.getItem).toHaveBeenCalledTimes(5) // 2 + 3
expect(BrowserStorage.getItem).toHaveBeenNthCalledWith(3, 'showMediaSettings_token-1')
expect(BrowserStorage.getItem).toHaveBeenNthCalledWith(4, 'showMediaSettings_token-2')
expect(BrowserStorage.getItem).toHaveBeenNthCalledWith(5, 'showMediaSettings_token-3')
expect(BrowserStorage.getItem).toHaveBeenCalledTimes(EXTRA_CALLS + 3)
expect(BrowserStorage.getItem).toHaveBeenNthCalledWith(EXTRA_CALLS + 1, 'showMediaSettings_token-1')
expect(BrowserStorage.getItem).toHaveBeenNthCalledWith(EXTRA_CALLS + 2, 'showMediaSettings_token-2')
expect(BrowserStorage.getItem).toHaveBeenNthCalledWith(EXTRA_CALLS + 3, 'showMediaSettings_token-3')
})

it('updates values correctly', async () => {
Expand All @@ -110,8 +108,7 @@ describe('settingsStore', () => {

// Assert
expect(results).toEqual([false, true])
// It's always called at least once : BrowserStorage.getItem('cachedConversations') (+2)
expect(BrowserStorage.getItem).toHaveBeenCalledTimes(2)
expect(BrowserStorage.getItem).toHaveBeenCalledTimes(EXTRA_CALLS)
expect(BrowserStorage.setItem).toHaveBeenCalledTimes(2)
expect(BrowserStorage.setItem).toHaveBeenNthCalledWith(1, 'showMediaSettings_token-1', 'false')
expect(BrowserStorage.setItem).toHaveBeenNthCalledWith(2, 'showMediaSettings_token-2', 'true')
Expand Down
7 changes: 7 additions & 0 deletions src/stores/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
setTypingStatusPrivacy,
setStartWithoutMedia,
setBlurVirtualBackground,
setConversationsListStyle,
} from '../services/settingsService.ts'

/**
Expand All @@ -42,6 +43,7 @@ export const useSettingsStore = defineStore('settings', {
showMediaSettings: {},
startWithoutMedia: getTalkConfig('local', 'call', 'start-without-media'),
blurVirtualBackgroundEnabled: getTalkConfig('local', 'call', 'blur-virtual-background'),
conversationsListStyle: getTalkConfig('local', 'conversations', 'compact-list'),
}),

getters: {
Expand Down Expand Up @@ -114,5 +116,10 @@ export const useSettingsStore = defineStore('settings', {
await setStartWithoutMedia(value)
this.startWithoutMedia = value
},

async setConversationsListStyle(value) {
await setConversationsListStyle(value)
this.conversationsListStyle = value
},
},
})

0 comments on commit 54c7c21

Please sign in to comment.