migrate and fix profileConfig

This commit is contained in:
Henry Jameson 2026-09-01 18:02:38 +03:00
commit 316bf4c226
10 changed files with 85 additions and 71 deletions

View file

@ -17,7 +17,8 @@ const CHANGE_EMAIL_URL = '/api/pleroma/change_email'
const CHANGE_PASSWORD_URL = '/api/pleroma/change_password' const CHANGE_PASSWORD_URL = '/api/pleroma/change_password'
const MOVE_ACCOUNT_URL = '/api/pleroma/move_account' const MOVE_ACCOUNT_URL = '/api/pleroma/move_account'
const ALIASES_URL = '/api/pleroma/aliases' const ALIASES_URL = '/api/pleroma/aliases'
const NOTIFICATION_SETTINGS_URL = '/api/pleroma/notification_settings' const NOTIFICATION_SETTINGS_URL = ({ blockFromStrangers, hideNotificationContents }) =>
`/api/pleroma/notification_settings${paramsString({ blockFromStrangers, hideNotificationContents })}`
export const NOTIFICATION_READ_URL = '/api/v1/pleroma/notifications/read' export const NOTIFICATION_READ_URL = '/api/v1/pleroma/notifications/read'
const MFA_SETTINGS_URL = '/api/pleroma/accounts/mfa' const MFA_SETTINGS_URL = '/api/pleroma/accounts/mfa'
@ -432,10 +433,9 @@ export const exportFriends = ({ id, credentials }) => {
// #Profile settings // #Profile settings
export const updateNotificationSettings = ({ credentials, settings }) => { export const updateNotificationSettings = ({ credentials, settings }) => {
return promisedRequest({ return promisedRequest({
url: NOTIFICATION_SETTINGS_URL, url: NOTIFICATION_SETTINGS_URL(settings),
credentials, credentials,
method: 'PUT', method: 'PUT',
payload: settings,
}) })
} }

View file

@ -1,7 +1,7 @@
import { useFollowRequestsStore } from 'src/stores/follow_requests.js'
import FollowRequestCard from 'src/components/follow_request_card/follow_request_card.vue' import FollowRequestCard from 'src/components/follow_request_card/follow_request_card.vue'
import { useFollowRequestsStore } from 'src/stores/follow_requests.js'
const FollowRequests = { const FollowRequests = {
components: { components: {
FollowRequestCard, FollowRequestCard,

View file

@ -9,6 +9,7 @@ import { useInterfaceStore } from 'src/stores/interface.js'
import { useLocalConfigStore } from 'src/stores/local_config.js' import { useLocalConfigStore } from 'src/stores/local_config.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js' import { useSyncConfigStore } from 'src/stores/sync_config.js'
import { useProfileConfigStore } from 'src/stores/profile_config.js'
export default { export default {
components: { components: {
@ -236,7 +237,7 @@ export default {
configSource() { configSource() {
switch (this.realSource) { switch (this.realSource) {
case 'profile': case 'profile':
return this.$store.state.profileConfig return useProfileConfigStore().config
case 'admin': case 'admin':
return useAdminSettingsStore().config return useAdminSettingsStore().config
default: default:
@ -253,7 +254,7 @@ export default {
switch (this.realSource) { switch (this.realSource) {
case 'profile': case 'profile':
return (k, v) => return (k, v) =>
this.$store.dispatch('setProfileOption', { name: k, value: v }) useProfileConfigStore().setProfileOption({ name: k, value: v })
case 'admin': case 'admin':
return (k, v) => return (k, v) =>
useAdminSettingsStore().pushAdminSetting({ path: k, value: v }) useAdminSettingsStore().pushAdminSetting({ path: k, value: v })

View file

@ -17,6 +17,7 @@ import { useInterfaceStore } from 'src/stores/interface.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useOAuthStore } from 'src/stores/oauth.js' import { useOAuthStore } from 'src/stores/oauth.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js' import { useSyncConfigStore } from 'src/stores/sync_config.js'
import { useProfileConfigStore } from 'src/stores/profile_config.js'
import { useUsersStore } from 'src/stores/users.js' import { useUsersStore } from 'src/stores/users.js'
import { updateProfile } from 'src/api/user.js' import { updateProfile } from 'src/api/user.js'
@ -109,6 +110,9 @@ const ComposingTab = {
FontControl, FontControl,
}, },
computed: { computed: {
defaultScope() {
return useProfileConfigStore().config.defaultScope
},
postFormats() { postFormats() {
return useInstanceCapabilitiesStore().postFormats return useInstanceCapabilitiesStore().postFormats
}, },
@ -135,7 +139,7 @@ const ComposingTab = {
}, },
methods: { methods: {
changeDefaultScope(value) { changeDefaultScope(value) {
this.$store.dispatch('setProfileOption', { name: 'defaultScope', value }) useProfileConfigStore().setProfileOption({ name: 'defaultScope', value })
}, },
clearCache(key) { clearCache(key) {
clearCache(key) clearCache(key)

View file

@ -11,10 +11,10 @@
<ScopeSelector <ScopeSelector
class="scope-selector setting-control" class="scope-selector setting-control"
:show-all="true" :show-all="true"
:user-default="$store.state.profileConfig.defaultScope" :user-default="defaultScope"
:initial-scope="$store.state.profileConfig.defaultScope" :initial-scope="defaultScope"
:on-scope-change="changeDefaultScope"
:unstyled="false" :unstyled="false"
@change="changeDefaultScope"
/> />
</label> </label>
</li> </li>

View file

@ -1,7 +1,5 @@
import drafts from './drafts.js' import drafts from './drafts.js'
import profileConfig from './profileConfig.js'
export default { export default {
profileConfig,
drafts, drafts,
} }

View file

@ -32,6 +32,6 @@ export const useFollowRequestsStore = defineStore('followRequests', {
}, },
remove(id) { remove(id) {
this.requests.delete(id) this.requests.delete(id)
} },
}, },
}) })

View file

@ -1,34 +1,36 @@
import { get, set } from 'lodash' import { get, set } from 'lodash'
import { defineStore } from 'pinia'
import { useOAuthStore } from 'src/stores/oauth.js' import { useOAuthStore } from 'src/stores/oauth.js'
import { useUsersStore } from 'src/stores/users.js' import { useUsersStore } from 'src/stores/users.js'
import { updateNotificationSettings, updateProfile } from 'src/api/user.js' import { updateNotificationSettings, updateProfileJSON } from 'src/api/user.js'
const defaultApi = ({ rootState, commit }, { path, value }) => { const defaultApi = async ({ path, value }) => {
const params = {} const params = {}
set(params, path, value) set(params, path, value)
return updateProfile({
return await updateProfileJSON({
params, params,
credentials: useOAuthStore().token, credentials: useOAuthStore().token,
}).then((result) => {
useUsersStore().addNewUsers(result)
}) })
} }
const notificationsApi = ({ rootState, commit }, { path, value, oldValue }) => { const notificationsApi = async ({ path, value, oldValue }) => {
const settings = {} const settings = {}
set(settings, path, value) set(settings, path, value)
return updateNotificationSettings({
const result = await updateNotificationSettings({
settings, settings,
credentials: useOAuthStore().token, credentials: useOAuthStore().token,
}).then(({ data: result }) => {
if (result.status === 'success') {
commit('confirmProfileOption', { name, value })
} else {
commit('confirmProfileOption', { name, value: oldValue })
}
}) })
if (result.data.status === 'success') {
// a bit of a hack
return { ...result, success: true }
} else {
throw new Error('Failed updating notification settings', result)
}
} }
/** /**
@ -84,60 +86,65 @@ export const settingsMap = {
// NotificationSettingsAPIs // NotificationSettingsAPIs
webPushHideContents: { webPushHideContents: {
get: 'pleroma.notification_settings.hide_notification_contents', get: 'pleroma.notification_settings.hide_notification_contents',
set: 'hide_notification_contents', set: 'hideNotificationContents',
api: notificationsApi, api: notificationsApi,
}, },
blockNotificationsFromStrangers: { blockNotificationsFromStrangers: {
get: 'pleroma.notification_settings.block_from_strangers', get: 'pleroma.notification_settings.block_from_strangers',
set: 'block_from_strangers', set: 'blockFromStrangers',
api: notificationsApi, api: notificationsApi,
}, },
} }
export const defaultState = Object.fromEntries( export const defaultState = () => ({
Object.keys(settingsMap).map((key) => [key, null]), config: Object.fromEntries(Object.keys(settingsMap).map((key) => [key, null]))
) })
const profileConfig = { export const useProfileConfigStore = defineStore('profileConfig', {
state: { ...defaultState }, state: defaultState,
mutations: { actions: {
confirmProfileOption(state, { name, value }) { confirmProfileOption({ name, value }) {
set(state, name, value) set(this.config, name, value)
},
wipeProfileOption(state, { name }) {
set(state, name, null)
},
wipeAllProfileOptions(state) {
Object.keys(settingsMap).forEach((key) => {
set(state, key, null)
})
}, },
// Set the settings based on their path location // Set the settings based on their path location
setCurrentUser(state, user) { async setProfileOption({ name, value }) {
const oldValue = get(this, name)
const map = settingsMap[name]
if (!map) throw new Error('Invalid server-side setting')
const { set: path = map, api = defaultApi } = map
set(this.config, name, null)
try {
const result = await api({ path, value, oldValue })
const { success } = result
if (success) {
set(this.config, name, value)
return
}
useUsersStore().addNewUsers(result)
this.update(user)
} catch (e) {
console.warn('Error setting server-side option:', e)
set(this.config, name, oldValue)
}
},
update(user) {
Object.entries(settingsMap).forEach((map) => { Object.entries(settingsMap).forEach((map) => {
const [name, value] = map const [name, value] = map
const { get: path = value } = value const { get: path = value } = value
set(state, name, get(user._original, path)) set(this.config, name, get(user._original, path))
})
},
onLogin(user) {
this.update(user)
},
onLogout() {
Object.keys(settingsMap).forEach((key) => {
set(this.config, key, null)
}) })
}, },
}, },
actions: { })
setProfileOption({ rootState, state, commit }, { 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('wipeProfileOption', { name })
api({ rootState, commit }, { path, value, oldValue }).catch((e) => {
console.warn('Error setting server-side option:', e)
commit('confirmProfileOption', { name, value: oldValue })
})
},
logout({ commit }) {
commit('wipeAllProfileOptions')
},
},
}
export default profileConfig

View file

@ -1,6 +1,6 @@
import { Socket } from 'phoenix' import { Socket } from 'phoenix'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useUsersStore } from 'src/stores/users.js' import { useUsersStore } from 'src/stores/users.js'
@ -14,7 +14,7 @@ export const useShoutStore = defineStore('shout', {
socket: null, socket: null,
}), }),
getters: { getters: {
token: () => useUsersStore().currentUser?.token token: () => useUsersStore().currentUser?.token,
}, },
actions: { actions: {
initializeSocket() { initializeSocket() {
@ -50,6 +50,6 @@ export const useShoutStore = defineStore('shout', {
disconnectSocket() { disconnectSocket() {
this.socket?.disconnect() this.socket?.disconnect()
this.socket = null this.socket = null
} },
}, },
}) })

View file

@ -11,13 +11,14 @@ import { useInstanceStore } from 'src/stores/instance.js'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useInterfaceStore } from 'src/stores/interface.js' import { useInterfaceStore } from 'src/stores/interface.js'
import { useListsStore } from 'src/stores/lists.js' import { useListsStore } from 'src/stores/lists.js'
import { useShoutStore } from 'src/stores/shout.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useNotificationsStore } from 'src/stores/notifications.js' import { useNotificationsStore } from 'src/stores/notifications.js'
import { useOAuthStore } from 'src/stores/oauth.js' import { useOAuthStore } from 'src/stores/oauth.js'
import { useShoutStore } from 'src/stores/shout.js'
import { useStatusesStore } from 'src/stores/statuses.js' import { useStatusesStore } from 'src/stores/statuses.js'
import { useStreamingStore } from 'src/stores/streaming.js' import { useStreamingStore } from 'src/stores/streaming.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js' import { useSyncConfigStore } from 'src/stores/sync_config.js'
import { useProfileConfigStore } from 'src/stores/profile_config.js'
import { useTimelinesStore } from 'src/stores/timelines.js' import { useTimelinesStore } from 'src/stores/timelines.js'
import { useUserHighlightStore } from 'src/stores/user_highlight.js' import { useUserHighlightStore } from 'src/stores/user_highlight.js'
@ -142,6 +143,7 @@ export const useUsersStore = defineStore('users', {
if (user.id === this.currentUser?.id) { if (user.id === this.currentUser?.id) {
this.currentUser = reactive this.currentUser = reactive
useProfileConfigStore().update(reactive)
} }
// Initialize some stuff // Initialize some stuff
@ -648,6 +650,7 @@ export const useUsersStore = defineStore('users', {
console.error('Error setting theme', e) console.error('Error setting theme', e)
}) })
}) })
useProfileConfigStore().onLogin(user)
useUserHighlightStore().initUserHighlight(user) useUserHighlightStore().initUserHighlight(user)
@ -780,6 +783,7 @@ export const useUsersStore = defineStore('users', {
Cookies.remove('__Host-pleroma_key', { path: '/' }) Cookies.remove('__Host-pleroma_key', { path: '/' })
useInterfaceStore().onLogout() useInterfaceStore().onLogout()
useProfileConfigStore().onLogout()
}) })
.catch((e) => { .catch((e) => {
useInterfaceStore().pushGlobalNotice({ useInterfaceStore().pushGlobalNotice({