2022-02-22 21:31:40 +00:00
|
|
|
import { get, set } from 'lodash'
|
|
|
|
|
2022-03-13 09:30:38 +00:00
|
|
|
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)
|
|
|
|
})
|
2022-02-22 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2022-03-13 09:30:38 +00:00
|
|
|
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 = {
|
2022-02-22 21:31:40 +00:00
|
|
|
'defaultScope': 'source.privacy',
|
2022-03-13 09:30:38 +00:00
|
|
|
'defaultNSFW': 'source.sensitive', // BROKEN: pleroma/pleroma#2837
|
|
|
|
'stripRichContent': {
|
|
|
|
get: 'source.pleroma.no_rich_text',
|
|
|
|
set: 'no_rich_text'
|
|
|
|
},
|
2022-02-22 21:31:40 +00:00
|
|
|
// Privacy
|
|
|
|
'locked': 'locked',
|
2022-03-13 09:30:38 +00:00
|
|
|
'acceptChatMessages': {
|
|
|
|
get: 'pleroma.accepts_chat_messages',
|
|
|
|
set: 'accepts_chat_messages'
|
|
|
|
},
|
|
|
|
'allowFollowingMove': {
|
|
|
|
get: 'pleroma.allow_following_move',
|
|
|
|
set: 'allow_following_move'
|
|
|
|
},
|
2022-02-22 21:31:40 +00:00
|
|
|
'discoverable': 'source.discoverable',
|
2022-03-13 09:30:38 +00:00
|
|
|
'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'
|
|
|
|
},
|
2022-02-22 21:31:40 +00:00
|
|
|
// NotificationSettingsAPIs
|
2022-03-13 09:30:38 +00:00
|
|
|
'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
|
|
|
|
}
|
2022-02-22 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
2022-03-13 09:30:38 +00:00
|
|
|
export const defaultState = Object.fromEntries(Object.keys(settingsMap).map(key => [key, null]))
|
2022-02-22 21:31:40 +00:00
|
|
|
|
|
|
|
const serverSideConfig = {
|
|
|
|
state: { ...defaultState },
|
|
|
|
mutations: {
|
|
|
|
confirmServerSideOption (state, { name, value }) {
|
|
|
|
set(state, name, value)
|
|
|
|
},
|
|
|
|
wipeServerSideOption (state, { name }) {
|
2022-02-28 16:01:41 +00:00
|
|
|
set(state, name, null)
|
2022-02-22 21:31:40 +00:00
|
|
|
},
|
2022-02-28 16:17:13 +00:00
|
|
|
wipeAllServerSideOptions (state) {
|
2022-03-13 09:30:38 +00:00
|
|
|
Object.keys(settingsMap).forEach(key => {
|
2022-02-28 16:17:13 +00:00
|
|
|
set(state, key, null)
|
|
|
|
})
|
|
|
|
},
|
2022-02-22 21:31:40 +00:00
|
|
|
// Set the settings based on their path location
|
|
|
|
setCurrentUser (state, user) {
|
2022-03-13 09:30:38 +00:00
|
|
|
Object.entries(settingsMap).forEach((map) => {
|
|
|
|
const [name, value] = map
|
|
|
|
const { get: path = value } = value
|
2022-02-22 21:31:40 +00:00
|
|
|
set(state, name, get(user._original, path))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
setServerSideOption ({ rootState, state, commit, dispatch }, { name, value }) {
|
|
|
|
const oldValue = get(state, name)
|
2022-03-13 09:30:38 +00:00
|
|
|
const map = settingsMap[name]
|
|
|
|
if (!map) throw new Error('Invalid server-side setting')
|
|
|
|
const { set: path = map, api = defaultApi } = map
|
2022-02-22 21:31:40 +00:00
|
|
|
commit('wipeServerSideOption', { name })
|
|
|
|
|
2022-03-13 09:30:38 +00:00
|
|
|
api({ rootState, commit }, { path, value, oldValue })
|
2022-02-22 21:31:40 +00:00
|
|
|
.catch((e) => {
|
|
|
|
console.warn('Error setting server-side option:', e)
|
|
|
|
commit('confirmServerSideOption', { name, value: oldValue })
|
|
|
|
})
|
2022-02-28 16:17:13 +00:00
|
|
|
},
|
|
|
|
logout ({ commit }) {
|
|
|
|
commit('wipeAllServerSideOptions')
|
2022-02-22 21:31:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default serverSideConfig
|