Skip to content
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
28 changes: 15 additions & 13 deletions src/components/AppNavigation/Settings/SettingsAddressbook.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@
{{ t('contacts', 'Download') }}
</ActionLink>

<template v-if="addressbook.writeProps">
<!-- enable/disable addressbook -->
<ActionCheckbox v-if="!toggleEnabledLoading"
:checked="enabled"
@change.stop.prevent="toggleAddressbookEnabled">
{{ t('contacts', 'Show') }}
</ActionCheckbox>
<ActionButton v-else>
<template #icon>
<IconLoading :size="20" />
</template>
{{ t('contacts', 'Show') }}
</ActionButton>
</template>

<template v-if="!addressbook.readOnly">
<!-- rename addressbook -->
<ActionButton v-if="!editingName"
Expand All @@ -86,19 +101,6 @@
<IconRename :size="20" />
</template>
</ActionInput>

<!-- enable/disable addressbook -->
<ActionCheckbox v-if="!toggleEnabledLoading"
:checked="enabled"
@change.stop.prevent="toggleAddressbookEnabled">
{{ t('contacts', 'Enabled') }}
</ActionCheckbox>
<ActionButton v-else>
<template #icon>
<IconLoading :size="20" />
</template>
{{ t('contacts', 'Enabled') }}
</ActionButton>
</template>

<!-- delete addressbook -->
Expand Down
22 changes: 17 additions & 5 deletions src/store/addressbooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function mapDavCollectionToAddressbook(addressbook) {
enabled: addressbook.enabled !== false,
owner: addressbook.owner,
readOnly: addressbook.readOnly === true,
writeProps: addressbook.currentUserPrivilegeSet.includes('{DAV:}write-properties') === true,
url: addressbook.url,
dav: addressbook,
shares: addressbook.shares
Expand Down Expand Up @@ -318,10 +319,17 @@ const actions = {
.update()
.then((response) => {
context.commit('toggleAddressbookEnabled', addressbook)
if (addressbook.enabled && Object.values(addressbook.contacts).length === 0) {
context.dispatch('getContactsFromAddressBook', { addressbook })
if (addressbook.enabled) {
// Add contacts from the just enabled address book to the contacts store
Object.values(addressbook.contacts).forEach((contact) => {
context.commit('addContact', contact)
})
} else {
// Remove contacts from the just disabled address book from the contacts store
Object.values(addressbook.contacts).forEach((contact) => {
context.commit('deleteContact', contact)
})
}

})
.catch((error) => { throw error })
},
Expand Down Expand Up @@ -386,9 +394,13 @@ const actions = {
}

context.commit('appendContactsToAddressbook', { addressbook, contacts })
context.commit('appendContacts', contacts)
context.commit('extractGroupsFromContacts', contacts)
context.commit('sortContacts')

// don't add contacts from disabled address book to contacts store
if (addressbook.enabled) {
context.commit('appendContacts', contacts)
context.commit('sortContacts')
}
return contacts
})
.catch((error) => {
Expand Down
2 changes: 1 addition & 1 deletion src/views/Contacts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ export default {
*/
fetchContacts() {
// wait for all addressbooks to have fetch their contacts
// don't filter disabled at this point, because sum of contacts per address book is shown
Promise.all(this.addressbooks
.filter(addressbook => addressbook.enabled)
.map(addressbook => {
return this.$store.dispatch('getContactsFromAddressBook', { addressbook })
})
Expand Down