aboutsummaryrefslogtreecommitdiff
path: root/src/boot/after_store.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/boot/after_store.js')
-rw-r--r--src/boot/after_store.js38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/boot/after_store.js b/src/boot/after_store.js
index 603de348..3fcbc246 100644
--- a/src/boot/after_store.js
+++ b/src/boot/after_store.js
@@ -3,6 +3,8 @@ import VueRouter from 'vue-router'
import routes from './routes'
import App from '../App.vue'
import { windowWidth } from '../services/window_utils/window_utils'
+import { getOrCreateApp, getClientToken } from '../services/new_api/oauth.js'
+import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
const getStatusnetConfig = async ({ store }) => {
try {
@@ -92,15 +94,14 @@ const setSettings = async ({ apiConfig, staticConfig, store }) => {
? 0
: config.logoMargin
})
+ store.commit('authFlow/setInitialStrategy', config.loginMethod)
copyInstanceOption('redirectRootNoLogin')
copyInstanceOption('redirectRootLogin')
copyInstanceOption('showInstanceSpecificPanel')
copyInstanceOption('minimalScopesMode')
- copyInstanceOption('formattingOptionsEnabled')
copyInstanceOption('hideMutedPosts')
copyInstanceOption('collapseMessageWithSubject')
- copyInstanceOption('loginMethod')
copyInstanceOption('scopeCopy')
copyInstanceOption('subjectLineBehavior')
copyInstanceOption('postContentType')
@@ -153,7 +154,11 @@ const getStaticEmoji = async ({ store }) => {
if (res.ok) {
const values = await res.json()
const emoji = Object.keys(values).map((key) => {
- return { shortcode: key, image_url: false, 'utf': values[key] }
+ return {
+ displayText: key,
+ imageUrl: false,
+ replacement: values[key]
+ }
})
store.dispatch('setInstanceOption', { name: 'emoji', value: emoji })
} else {
@@ -174,7 +179,12 @@ const getCustomEmoji = async ({ store }) => {
const result = await res.json()
const values = Array.isArray(result) ? Object.assign({}, ...result) : result
const emoji = Object.keys(values).map((key) => {
- return { shortcode: key, image_url: values[key].image_url || values[key] }
+ const imageUrl = values[key].image_url
+ return {
+ displayText: key,
+ imageUrl: imageUrl ? store.state.instance.server + imageUrl : values[key],
+ replacement: `:${key}: `
+ }
})
store.dispatch('setInstanceOption', { name: 'customEmoji', value: emoji })
store.dispatch('setInstanceOption', { name: 'pleromaBackend', value: true })
@@ -188,17 +198,29 @@ const getCustomEmoji = async ({ store }) => {
}
}
+const getAppSecret = async ({ store }) => {
+ const { state, commit } = store
+ const { oauth, instance } = state
+ return getOrCreateApp({ ...oauth, instance: instance.server, commit })
+ .then((app) => getClientToken({ ...app, instance: instance.server }))
+ .then((token) => {
+ commit('setAppToken', token.access_token)
+ commit('setBackendInteractor', backendInteractorService(store.getters.getToken()))
+ })
+}
+
const getNodeInfo = async ({ store }) => {
try {
const res = await window.fetch('/nodeinfo/2.0.json')
if (res.ok) {
const data = await res.json()
const metadata = data.metadata
-
const features = metadata.features
store.dispatch('setInstanceOption', { name: 'mediaProxyAvailable', value: features.includes('media_proxy') })
store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') })
store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') })
+ store.dispatch('setInstanceOption', { name: 'pollsAvailable', value: features.includes('polls') })
+ store.dispatch('setInstanceOption', { name: 'pollLimits', value: metadata.pollLimits })
store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames })
store.dispatch('setInstanceOption', { name: 'postFormats', value: metadata.postFormats })
@@ -228,14 +250,14 @@ const setConfig = async ({ store }) => {
const apiConfig = configInfos[0]
const staticConfig = configInfos[1]
- await setSettings({ store, apiConfig, staticConfig })
+ await setSettings({ store, apiConfig, staticConfig }).then(getAppSecret({ store }))
}
const checkOAuthToken = async ({ store }) => {
return new Promise(async (resolve, reject) => {
- if (store.state.oauth.token) {
+ if (store.getters.getUserToken()) {
try {
- await store.dispatch('loginUser', store.state.oauth.token)
+ await store.dispatch('loginUser', store.getters.getUserToken())
} catch (e) {
console.log(e)
}