Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
replace Vuex settingsStore.js to Pinia settings.js
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Jul 17, 2023
commit ec5dd4240268b7cc361b1311240b1880ce5641c2
6 changes: 5 additions & 1 deletion src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ import { CONVERSATION, PARTICIPANT, PRIVACY } from '../../constants.js'
import { EventBus } from '../../services/EventBus.js'
import { shareFile } from '../../services/filesSharingServices.js'
import { searchPossibleMentions } from '../../services/mentionsService.js'
import { useSettingsStore } from '../../stores/settings.js'
import { fetchClipboardContent } from '../../utils/clipboard.js'
import { isDarkTheme } from '../../utils/isDarkTheme.js'

Expand Down Expand Up @@ -261,8 +262,11 @@ export default {

setup() {
const { openViewer } = useViewer()
const settingsStore = useSettingsStore()

return {
openViewer,
settingsStore,
supportTypingStatus,
}
},
Expand Down Expand Up @@ -371,7 +375,7 @@ export default {
},
showTypingStatus() {
return this.hasTypingIndicator && this.supportTypingStatus
&& this.$store.getters.getTypingStatusPrivacy() === PRIVACY.PUBLIC
&& this.settingsStore.typingStatusPrivacy === PRIVACY.PUBLIC
},
},

Expand Down
24 changes: 9 additions & 15 deletions src/components/SettingsDialog/SettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
import MediaDevicesPreview from '../MediaDevicesPreview.vue'

import { PRIVACY } from '../../constants.js'
import { useSettingsStore } from '../../stores/settings.js'

const supportTypingStatus = getCapabilities()?.spreed?.config?.chat?.['typing-privacy'] !== undefined

Expand All @@ -184,7 +185,10 @@ export default {
},

setup() {
const settingsStore = useSettingsStore()

return {
settingsStore,
supportTypingStatus,
}
},
Expand Down Expand Up @@ -220,19 +224,11 @@ export default {
},

readStatusPrivacyIsPublic() {
return this.readStatusPrivacy === PRIVACY.PUBLIC
},

readStatusPrivacy() {
return this.$store.getters.getReadStatusPrivacy()
return this.settingsStore.readStatusPrivacy === PRIVACY.PUBLIC
},

typingStatusPrivacyIsPublic() {
return this.typingStatusPrivacy === PRIVACY.PUBLIC
},

typingStatusPrivacy() {
return this.$store.getters.getTypingStatusPrivacy()
return this.settingsStore.typingStatusPrivacy === PRIVACY.PUBLIC
},

settingsUrl() {
Expand Down Expand Up @@ -280,9 +276,8 @@ export default {
async toggleReadStatusPrivacy() {
this.privacyLoading = true
try {
await this.$store.dispatch(
'updateReadStatusPrivacy',
this.readStatusPrivacyIsPublic ? PRIVACY.PRIVATE : PRIVACY.PUBLIC,
await this.settingsStore.updateReadStatusPrivacy(
this.readStatusPrivacyIsPublic ? PRIVACY.PRIVATE : PRIVACY.PUBLIC
)
showSuccess(t('spreed', 'Your privacy setting has been saved'))
} catch (exception) {
Expand All @@ -294,8 +289,7 @@ export default {
async toggleTypingStatusPrivacy() {
this.privacyLoading = true
try {
await this.$store.dispatch(
'updateTypingStatusPrivacy',
await this.settingsStore.updateTypingStatusPrivacy(
this.typingStatusPrivacyIsPublic ? PRIVACY.PRIVATE : PRIVACY.PUBLIC
)
showSuccess(t('spreed', 'Your privacy setting has been saved'))
Expand Down
80 changes: 0 additions & 80 deletions src/store/settingsStore.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/store/storeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import participantsStore from './participantsStore.js'
import pollStore from './pollStore.js'
import quoteReplyStore from './quoteReplyStore.js'
import reactionsStore from './reactionsStore.js'
import settingsStore from './settingsStore.js'
import sharedItemStore from './sharedItemsStore.js'
import sidebarStore from './sidebarStore.js'
import soundsStore from './soundsStore.js'
Expand All @@ -55,7 +54,6 @@ export default {
newGroupConversationStore,
participantsStore,
quoteReplyStore,
settingsStore,
sidebarStore,
soundsStore,
talkHashStore,
Expand Down
43 changes: 43 additions & 0 deletions src/stores/__tests__/settings.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { setActivePinia, createPinia } from 'pinia'

import { PRIVACY } from '../../constants.js'
import { useSettingsStore } from '../settings.js'

jest.mock('@nextcloud/initial-state',
() => ({
loadState: jest.fn().mockReturnValue(0),
}))

jest.mock('../../services/settingsService',
() => ({
setReadStatusPrivacy: jest.fn().mockReturnValue('success'),
setTypingStatusPrivacy: jest.fn().mockReturnValue('success'),
}))

describe('settingsStore', () => {
beforeEach(() => {
// creates a fresh pinia and make it active, so it's automatically picked
// up by any useStore() call without having to pass it to it:
// `useStore(pinia)`
setActivePinia(createPinia())
})

it('shows correct loaded values for statuses', () => {
const settingsStore = useSettingsStore()

expect(settingsStore.readStatusPrivacy).toBe(PRIVACY.PUBLIC)
expect(settingsStore.typingStatusPrivacy).toBe(PRIVACY.PUBLIC)
})

it('toggles statuses correctly', async () => {
const settingsStore = useSettingsStore()

expect(settingsStore.readStatusPrivacy).toBe(PRIVACY.PUBLIC)
await settingsStore.updateReadStatusPrivacy(PRIVACY.PRIVATE)
expect(settingsStore.readStatusPrivacy).toBe(PRIVACY.PRIVATE)

expect(settingsStore.typingStatusPrivacy).toBe(PRIVACY.PUBLIC)
await settingsStore.updateTypingStatusPrivacy(PRIVACY.PRIVATE)
expect(settingsStore.typingStatusPrivacy).toBe(PRIVACY.PRIVATE)
})
})
57 changes: 57 additions & 0 deletions src/stores/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
*
* @author Maksim Sukharev <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { defineStore } from 'pinia'

import { loadState } from '@nextcloud/initial-state'

import { PRIVACY } from '../constants.js'
import { setReadStatusPrivacy, setTypingStatusPrivacy } from '../services/settingsService.js'

export const useSettingsStore = defineStore('settings', {
state: () => ({
readStatusPrivacy: loadState('spreed', 'read_status_privacy', PRIVACY.PRIVATE),
typingStatusPrivacy: loadState('spreed', 'typing_privacy', PRIVACY.PRIVATE),
}),

actions: {
/**
* Update the read status privacy for the user
*
* @param {number} privacy The new selected privacy
*/
async updateReadStatusPrivacy(privacy) {
await setReadStatusPrivacy(privacy)
this.readStatusPrivacy = privacy
},

/**
* Update the typing status privacy for the user
*
* @param {number} privacy The new selected privacy
*/
async updateTypingStatusPrivacy(privacy) {
await setTypingStatusPrivacy(privacy)
this.typingStatusPrivacy = privacy
},
},
})