first pass of migration - states and obvious replacements
This commit is contained in:
parent
02f952047d
commit
24ce2dc0a5
66 changed files with 398 additions and 568 deletions
157
src/stores/instance.js
Normal file
157
src/stores/instance.js
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
import { get, set } from 'lodash'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
import { ensureFinalFallback } from 'src/i18n/languages.js'
|
||||
import { useInterfaceStore } from 'src/stores/interface.js'
|
||||
import { instanceDefaultProperties } from '../modules/config.js'
|
||||
import {
|
||||
instanceDefaultConfig,
|
||||
staticOrApiConfigDefault,
|
||||
} from '../modules/default_config_state.js'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
|
||||
const REMOTE_INTERACTION_URL = '/main/ostatus'
|
||||
|
||||
const defaultState = {
|
||||
// Stuff from apiConfig
|
||||
name: 'Pleroma FE',
|
||||
registrationOpen: true,
|
||||
server: 'http://localhost:4040/',
|
||||
textlimit: 5000,
|
||||
private: false,
|
||||
federating: true,
|
||||
federationPolicy: null,
|
||||
themesIndex: null,
|
||||
stylesIndex: null,
|
||||
palettesIndex: null,
|
||||
themeData: null, // used for theme editor v2
|
||||
vapidPublicKey: null,
|
||||
|
||||
// Stuff from static/config.json
|
||||
loginMethod: 'password',
|
||||
disableUpdateNotification: false,
|
||||
|
||||
// Instance-wide configurations that should not be changed by individual users
|
||||
instanceIdentity: {
|
||||
...staticOrApiConfigDefault,
|
||||
},
|
||||
|
||||
limits: {
|
||||
bannerlimit: null,
|
||||
avatarlimit: null,
|
||||
backgroundlimit: null,
|
||||
uploadlimit: null,
|
||||
fieldsLimits: null,
|
||||
pollLimits: {
|
||||
max_options: 4,
|
||||
max_option_chars: 255,
|
||||
min_expiration: 60,
|
||||
max_expiration: 60 * 60 * 24,
|
||||
},
|
||||
},
|
||||
|
||||
// Instance admins can override default settings for the whole instance
|
||||
prefsStorage: {
|
||||
...instanceDefaultConfig,
|
||||
},
|
||||
|
||||
// Known domains list for user's domain-muting
|
||||
knownDomains: [],
|
||||
|
||||
// Moderation stuff
|
||||
staffAccounts: [],
|
||||
accountActivationRequired: null,
|
||||
accountApprovalRequired: null,
|
||||
birthdayRequired: false,
|
||||
birthdayMinAge: 0,
|
||||
restrictedNicknames: [],
|
||||
localBubbleInstances: [], // Akkoma
|
||||
|
||||
// Feature-set, apparently, not everything here is reported...
|
||||
featureSet: {
|
||||
postFormats: [],
|
||||
mailerEnabled: false,
|
||||
safeDM: true,
|
||||
shoutAvailable: false,
|
||||
pleromaExtensionsAvailable: true,
|
||||
pleromaChatMessagesAvailable: false,
|
||||
pleromaCustomEmojiReactionsAvailable: false,
|
||||
pleromaBookmarkFoldersAvailable: false,
|
||||
pleromaPublicFavouritesAvailable: true,
|
||||
statusNotificationTypeAvailable: true,
|
||||
gopherAvailable: false,
|
||||
editingAvailable: false,
|
||||
mediaProxyAvailable: false,
|
||||
suggestionsEnabled: false,
|
||||
suggestionsWeb: '',
|
||||
quotingAvailable: false,
|
||||
groupActorAvailable: false,
|
||||
blockExpiration: false,
|
||||
tagPolicyAvailable: false,
|
||||
pollsAvailable: false,
|
||||
localBubble: false, // Akkoma
|
||||
},
|
||||
|
||||
// Html stuff
|
||||
instanceSpecificPanelContent: '',
|
||||
tos: '',
|
||||
|
||||
// Version Information
|
||||
backendVersion: '',
|
||||
backendRepository: '',
|
||||
frontendVersion: '',
|
||||
}
|
||||
|
||||
export const useInstanceStore = defineStore('instance', {
|
||||
state: () => ({ ...defaultState }),
|
||||
getters: {
|
||||
instanceDefaultConfig(state) {
|
||||
return instanceDefaultProperties
|
||||
.map((key) => [key, state[key]])
|
||||
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {})
|
||||
},
|
||||
instanceDomain(state) {
|
||||
return new URL(this.server).hostname
|
||||
},
|
||||
remoteInteractionLink(state) {
|
||||
const server = this.server.endsWith('/')
|
||||
? this.server.slice(0, -1)
|
||||
: this.server
|
||||
const link = server + REMOTE_INTERACTION_URL
|
||||
|
||||
return ({ statusId, nickname }) => {
|
||||
if (statusId) {
|
||||
return `${link}?status_id=${statusId}`
|
||||
} else {
|
||||
return `${link}?nickname=${nickname}`
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
set({ path, value }) {
|
||||
if (get(defaultState, path) === undefined)
|
||||
console.error(`Unknown instance option ${path}, value: ${value}`)
|
||||
set(this, path, value)
|
||||
switch (name) {
|
||||
case 'name':
|
||||
useInterfaceStore().setPageTitle()
|
||||
break
|
||||
case 'shoutAvailable':
|
||||
if (value) {
|
||||
window.vuex.dispatch('initializeSocket')
|
||||
}
|
||||
break
|
||||
}
|
||||
},
|
||||
async getKnownDomains() {
|
||||
try {
|
||||
this.knownDomains = await apiService.fetchKnownDomains({
|
||||
credentials: window.vuex.state.users.currentUser.credentials,
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn("Can't load known domains\n", e)
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
@ -5,6 +5,7 @@ import {
|
|||
generatePreset,
|
||||
} from 'src/services/theme_data/theme_data.service.js'
|
||||
import { convertTheme2To3 } from 'src/services/theme_data/theme2_to_theme3.js'
|
||||
import { useInstanceStore } from 'src/stores/instance.js'
|
||||
import {
|
||||
applyTheme,
|
||||
getResourcesIndex,
|
||||
|
|
@ -86,7 +87,7 @@ export const useInterfaceStore = defineStore('interface', {
|
|||
},
|
||||
setPageTitle(option = '') {
|
||||
try {
|
||||
document.title = `${option} ${window.vuex.state.instance.name}`
|
||||
document.title = `${option} ${window.vuex.useInstanceStore().name}`
|
||||
} catch (error) {
|
||||
console.error(`${error}`)
|
||||
}
|
||||
|
|
@ -385,14 +386,14 @@ export const useInterfaceStore = defineStore('interface', {
|
|||
}
|
||||
|
||||
const { style: instanceStyleName, palette: instancePaletteName } =
|
||||
window.vuex.state.instance
|
||||
window.vuex.useInstanceStore()
|
||||
|
||||
let {
|
||||
theme: instanceThemeV2Name,
|
||||
themesIndex,
|
||||
stylesIndex,
|
||||
palettesIndex,
|
||||
} = window.vuex.state.instance
|
||||
} = window.vuex.useInstanceStore()
|
||||
|
||||
const {
|
||||
style: userStyleName,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
getClientToken,
|
||||
verifyAppToken,
|
||||
} from 'src/services/new_api/oauth.js'
|
||||
import { useInstanceStore } from 'src/stores/instance.js'
|
||||
|
||||
// status codes about verifyAppToken (GET /api/v1/apps/verify_credentials)
|
||||
const isAppTokenRejected = (error) =>
|
||||
|
|
@ -61,8 +62,7 @@ export const useOAuthStore = defineStore('oauth', {
|
|||
this.userToken = false
|
||||
},
|
||||
async createApp() {
|
||||
const { state } = window.vuex
|
||||
const instance = state.instance.server
|
||||
const instance = useInstanceStore().server
|
||||
const app = await createApp(instance)
|
||||
this.setClientData(app)
|
||||
return app
|
||||
|
|
@ -81,8 +81,7 @@ export const useOAuthStore = defineStore('oauth', {
|
|||
}
|
||||
},
|
||||
async getAppToken() {
|
||||
const { state } = window.vuex
|
||||
const instance = state.instance.server
|
||||
const instance = useInstanceStore().server
|
||||
const res = await getClientToken({
|
||||
clientId: this.clientId,
|
||||
clientSecret: this.clientSecret,
|
||||
|
|
@ -94,11 +93,10 @@ export const useOAuthStore = defineStore('oauth', {
|
|||
/// Use this if you want to ensure the app is still valid to use.
|
||||
/// @return {string} The access token to the app (not attached to any user)
|
||||
async ensureAppToken() {
|
||||
const { state } = window.vuex
|
||||
if (this.appToken) {
|
||||
try {
|
||||
await verifyAppToken({
|
||||
instance: state.instance.server,
|
||||
instance: useInstanceStore().server,
|
||||
appToken: this.appToken,
|
||||
})
|
||||
return this.appToken
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue