Expert settings and serverside settings + new defaults See merge request pleroma/pleroma-fe!1438merge-requests/1521/head
commit
b632d740c1
@ -0,0 +1,51 @@
|
||||
<template>
|
||||
<span
|
||||
v-if="serverSide"
|
||||
class="ServerSideIndicator"
|
||||
>
|
||||
<Popover
|
||||
trigger="hover"
|
||||
>
|
||||
<template v-slot:trigger>
|
||||
|
||||
<FAIcon
|
||||
icon="server"
|
||||
:aria-label="$t('settings.setting_server_side')"
|
||||
/>
|
||||
</template>
|
||||
<template v-slot:content>
|
||||
<div class="serverside-tooltip">
|
||||
{{ $t('settings.setting_server_side') }}
|
||||
</div>
|
||||
</template>
|
||||
</Popover>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Popover from 'src/components/popover/popover.vue'
|
||||
import { library } from '@fortawesome/fontawesome-svg-core'
|
||||
import { faServer } from '@fortawesome/free-solid-svg-icons'
|
||||
|
||||
library.add(
|
||||
faServer
|
||||
)
|
||||
|
||||
export default {
|
||||
components: { Popover },
|
||||
props: ['serverSide']
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.ServerSideIndicator {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
|
||||
.serverside-tooltip {
|
||||
margin: 0.5em 1em;
|
||||
min-width: 10em;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
</style>
|
@ -0,0 +1,137 @@
|
||||
import { get, set } from 'lodash'
|
||||
|
||||
const defaultApi = ({ rootState, commit }, { path, value }) => {
|
||||
const params = {}
|
||||
set(params, path, value)
|
||||
return rootState
|
||||
.api
|
||||
.backendInteractor
|
||||
.updateProfile({ params })
|
||||
.then(result => {
|
||||
commit('addNewUsers', [result])
|
||||
commit('setCurrentUser', result)
|
||||
})
|
||||
}
|
||||
|
||||
const notificationsApi = ({ rootState, commit }, { path, value, oldValue }) => {
|
||||
const settings = {}
|
||||
set(settings, path, value)
|
||||
return rootState
|
||||
.api
|
||||
.backendInteractor
|
||||
.updateNotificationSettings({ settings })
|
||||
.then(result => {
|
||||
if (result.status === 'success') {
|
||||
commit('confirmServerSideOption', { name, value })
|
||||
} else {
|
||||
commit('confirmServerSideOption', { name, value: oldValue })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Map that stores relation between path for reading (from user profile),
|
||||
* for writing (into API) an what API to use.
|
||||
*
|
||||
* Shorthand - instead of { get, set, api? } object it's possible to use string
|
||||
* in case default api is used and get = set
|
||||
*
|
||||
* If no api is specified, defaultApi is used (see above)
|
||||
*/
|
||||
export const settingsMap = {
|
||||
'defaultScope': 'source.privacy',
|
||||
'defaultNSFW': 'source.sensitive', // BROKEN: pleroma/pleroma#2837
|
||||
'stripRichContent': {
|
||||
get: 'source.pleroma.no_rich_text',
|
||||
set: 'no_rich_text'
|
||||
},
|
||||
// Privacy
|
||||
'locked': 'locked',
|
||||
'acceptChatMessages': {
|
||||
get: 'pleroma.accepts_chat_messages',
|
||||
set: 'accepts_chat_messages'
|
||||
},
|
||||
'allowFollowingMove': {
|
||||
get: 'pleroma.allow_following_move',
|
||||
set: 'allow_following_move'
|
||||
},
|
||||
'discoverable': 'source.discoverable',
|
||||
'hideFavorites': {
|
||||
get: 'pleroma.hide_favorites',
|
||||
set: 'hide_favorites'
|
||||
},
|
||||
'hideFollowers': {
|
||||
get: 'pleroma.hide_followers',
|
||||
set: 'hide_followers'
|
||||
},
|
||||
'hideFollows': {
|
||||
get: 'pleroma.hide_follows',
|
||||
set: 'hide_follows'
|
||||
},
|
||||
'hideFollowersCount': {
|
||||
get: 'pleroma.hide_followers_count',
|
||||
set: 'hide_followers_count'
|
||||
},
|
||||
'hideFollowsCount': {
|
||||
get: 'pleroma.hide_follows_count',
|
||||
set: 'hide_follows_count'
|
||||
},
|
||||
// NotificationSettingsAPIs
|
||||
'webPushHideContents': {
|
||||
get: 'pleroma.notification_settings.hide_notification_contents',
|
||||
set: 'hide_notification_contents',
|
||||
api: notificationsApi
|
||||
},
|
||||
'blockNotificationsFromStrangers': {
|
||||
get: 'pleroma.notification_settings.block_from_strangers',
|
||||
set: 'block_from_strangers',
|
||||
api: notificationsApi
|
||||
}
|
||||
}
|
||||
|
||||
export const defaultState = Object.fromEntries(Object.keys(settingsMap).map(key => [key, null]))
|
||||
|
||||
const serverSideConfig = {
|
||||
state: { ...defaultState },
|
||||
mutations: {
|
||||
confirmServerSideOption (state, { name, value }) {
|
||||
set(state, name, value)
|
||||
},
|
||||
wipeServerSideOption (state, { name }) {
|
||||
set(state, name, null)
|
||||
},
|
||||
wipeAllServerSideOptions (state) {
|
||||
Object.keys(settingsMap).forEach(key => {
|
||||
set(state, key, null)
|
||||
})
|
||||
},
|
||||
// Set the settings based on their path location
|
||||
setCurrentUser (state, user) {
|
||||
Object.entries(settingsMap).forEach((map) => {
|
||||
const [name, value] = map
|
||||
const { get: path = value } = value
|
||||
set(state, name, get(user._original, path))
|
||||
})
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setServerSideOption ({ rootState, state, commit, dispatch }, { name, value }) {
|
||||
const oldValue = get(state, name)
|
||||
const map = settingsMap[name]
|
||||
if (!map) throw new Error('Invalid server-side setting')
|
||||
const { set: path = map, api = defaultApi } = map
|
||||
commit('wipeServerSideOption', { name })
|
||||
|
||||
api({ rootState, commit }, { path, value, oldValue })
|
||||
.catch((e) => {
|
||||
console.warn('Error setting server-side option:', e)
|
||||
commit('confirmServerSideOption', { name, value: oldValue })
|
||||
})
|
||||
},
|
||||
logout ({ commit }) {
|
||||
commit('wipeAllServerSideOptions')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default serverSideConfig
|
Loading…
Reference in new issue