2020-01-21 22:37:19 +00:00
|
|
|
import { getPreset, applyTheme } from '../services/style_setter/style_setter.js'
|
2020-02-22 08:57:08 +00:00
|
|
|
import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
|
2020-05-10 10:54:55 +00:00
|
|
|
import apiService from '../services/api/api.service.js'
|
2019-09-29 20:47:26 +00:00
|
|
|
import { instanceDefaultProperties } from './config.js'
|
2018-09-09 18:21:23 +00:00
|
|
|
|
2022-09-19 17:39:21 +00:00
|
|
|
const REMOTE_INTERACTION_URL = '/main/ostatus'
|
|
|
|
|
2018-09-09 18:21:23 +00:00
|
|
|
const defaultState = {
|
2020-05-13 20:40:13 +00:00
|
|
|
// Stuff from apiConfig
|
2018-09-09 18:21:23 +00:00
|
|
|
name: 'Pleroma FE',
|
|
|
|
registrationOpen: true,
|
|
|
|
server: 'http://localhost:4040/',
|
2020-05-13 20:40:13 +00:00
|
|
|
textlimit: 5000,
|
2020-01-21 22:37:19 +00:00
|
|
|
themeData: undefined,
|
2020-05-13 20:40:13 +00:00
|
|
|
vapidPublicKey: undefined,
|
|
|
|
|
|
|
|
// Stuff from static/config.json
|
2018-12-03 03:47:35 +00:00
|
|
|
alwaysShowSubjectInput: true,
|
2020-07-08 10:11:17 +00:00
|
|
|
defaultAvatar: '/images/avi.png',
|
|
|
|
defaultBanner: '/images/banner.png',
|
2020-05-13 19:40:46 +00:00
|
|
|
background: '/static/aurora_borealis.jpg',
|
2022-09-06 17:00:15 +00:00
|
|
|
collapseMessageWithSubject: true,
|
2020-05-13 19:40:46 +00:00
|
|
|
greentext: false,
|
2022-01-10 05:37:39 +00:00
|
|
|
useAtIcon: false,
|
2022-01-10 06:16:33 +00:00
|
|
|
mentionLinkDisplay: 'short',
|
|
|
|
mentionLinkShowTooltip: true,
|
2022-01-20 17:07:09 +00:00
|
|
|
mentionLinkShowAvatar: false,
|
2022-01-10 07:31:26 +00:00
|
|
|
mentionLinkFadeDomain: true,
|
2022-02-03 20:34:57 +00:00
|
|
|
mentionLinkShowYous: false,
|
|
|
|
mentionLinkBoldenYou: true,
|
2020-05-13 19:40:46 +00:00
|
|
|
hideFilteredStatuses: false,
|
2021-06-08 13:14:01 +00:00
|
|
|
// bad name: actually hides posts of muted USERS
|
2020-05-13 19:40:46 +00:00
|
|
|
hideMutedPosts: false,
|
2021-06-08 13:14:01 +00:00
|
|
|
hideMutedThreads: true,
|
2022-07-31 21:47:25 +00:00
|
|
|
hideThreadsWithBlockedUsers: false,
|
2021-06-08 13:14:01 +00:00
|
|
|
hideWordFilteredPosts: false,
|
2018-10-16 13:09:29 +00:00
|
|
|
hidePostStats: false,
|
2022-02-28 21:35:00 +00:00
|
|
|
hideBotIndication: false,
|
2022-08-14 23:24:59 +00:00
|
|
|
hideSiteFavicon: false,
|
|
|
|
hideSiteName: false,
|
2018-10-16 13:09:29 +00:00
|
|
|
hideUserStats: false,
|
2022-02-28 20:07:20 +00:00
|
|
|
muteBotStatuses: false,
|
2022-08-26 11:58:33 +00:00
|
|
|
modalOnRepeat: false,
|
|
|
|
modalOnUnfollow: false,
|
|
|
|
modalOnBlock: true,
|
|
|
|
modalOnMute: false,
|
|
|
|
modalOnDelete: true,
|
|
|
|
modalOnLogout: true,
|
|
|
|
modalOnApproveFollow: false,
|
|
|
|
modalOnDenyFollow: false,
|
2020-05-13 19:46:31 +00:00
|
|
|
loginMethod: 'password',
|
2020-11-02 17:37:01 +00:00
|
|
|
logo: '/static/logo.svg',
|
2020-05-13 19:40:46 +00:00
|
|
|
logoMargin: '.2em',
|
|
|
|
logoMask: true,
|
2020-10-29 19:13:31 +00:00
|
|
|
logoLeft: false,
|
2018-12-13 17:41:01 +00:00
|
|
|
nsfwCensorImage: undefined,
|
2020-05-13 19:40:46 +00:00
|
|
|
postContentType: 'text/plain',
|
|
|
|
redirectRootLogin: '/main/friends',
|
|
|
|
redirectRootNoLogin: '/main/all',
|
2019-02-08 21:20:47 +00:00
|
|
|
showFeaturesPanel: true,
|
2020-05-13 19:40:46 +00:00
|
|
|
showInstanceSpecificPanel: false,
|
2022-08-14 23:24:59 +00:00
|
|
|
showNavShortcuts: true,
|
|
|
|
showWiderShortcuts: true,
|
2020-05-12 18:59:52 +00:00
|
|
|
sidebarRight: false,
|
2018-09-25 11:47:02 +00:00
|
|
|
subjectLineBehavior: 'email',
|
2020-05-13 19:40:46 +00:00
|
|
|
theme: 'pleroma-dark',
|
2020-09-29 10:18:37 +00:00
|
|
|
virtualScrolling: true,
|
2021-02-23 08:00:23 +00:00
|
|
|
sensitiveByDefault: false,
|
2022-06-28 13:53:12 +00:00
|
|
|
sensitiveIfSubject: true,
|
2022-08-11 09:21:00 +00:00
|
|
|
renderMisskeyMarkdown: true,
|
2022-08-08 15:47:06 +00:00
|
|
|
renderMfmOnHover: false,
|
2022-03-06 18:57:48 +00:00
|
|
|
conversationDisplay: 'linear',
|
|
|
|
conversationTreeAdvanced: false,
|
2021-09-05 20:35:47 +00:00
|
|
|
conversationOtherRepliesButton: 'below',
|
2022-03-06 19:13:35 +00:00
|
|
|
conversationTreeFadeAncestors: false,
|
2021-08-08 00:14:14 +00:00
|
|
|
maxDepthInThread: 6,
|
2018-09-09 18:51:40 +00:00
|
|
|
|
2018-09-09 18:21:23 +00:00
|
|
|
// Nasty stuff
|
|
|
|
customEmoji: [],
|
2019-10-09 19:50:00 +00:00
|
|
|
customEmojiFetched: false,
|
2020-05-13 20:40:13 +00:00
|
|
|
emoji: [],
|
|
|
|
emojiFetched: false,
|
|
|
|
pleromaBackend: true,
|
2019-03-05 05:29:56 +00:00
|
|
|
postFormats: [],
|
2020-05-13 20:40:13 +00:00
|
|
|
restrictedNicknames: [],
|
|
|
|
safeDM: true,
|
2020-05-10 10:54:55 +00:00
|
|
|
knownDomains: [],
|
2018-09-09 18:51:40 +00:00
|
|
|
|
|
|
|
// Feature-set, apparently, not everything here is reported...
|
2020-05-13 20:48:21 +00:00
|
|
|
mediaProxyAvailable: false,
|
2018-09-09 18:51:40 +00:00
|
|
|
suggestionsEnabled: false,
|
|
|
|
suggestionsWeb: '',
|
|
|
|
|
2018-09-09 18:21:23 +00:00
|
|
|
// Html stuff
|
|
|
|
instanceSpecificPanelContent: '',
|
2019-03-10 23:58:12 +00:00
|
|
|
tos: '',
|
|
|
|
|
|
|
|
// Version Information
|
|
|
|
backendVersion: '',
|
2019-06-18 20:28:31 +00:00
|
|
|
frontendVersion: '',
|
|
|
|
|
|
|
|
pollsAvailable: false,
|
|
|
|
pollLimits: {
|
|
|
|
max_options: 4,
|
|
|
|
max_option_chars: 255,
|
|
|
|
min_expiration: 60,
|
|
|
|
max_expiration: 60 * 60 * 24
|
|
|
|
}
|
2018-09-09 18:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const instance = {
|
|
|
|
state: defaultState,
|
|
|
|
mutations: {
|
|
|
|
setInstanceOption (state, { name, value }) {
|
2018-09-17 15:54:08 +00:00
|
|
|
if (typeof value !== 'undefined') {
|
2021-04-25 10:24:08 +00:00
|
|
|
state[name] = value
|
2018-09-17 15:54:08 +00:00
|
|
|
}
|
2020-05-10 10:54:55 +00:00
|
|
|
},
|
|
|
|
setKnownDomains (state, domains) {
|
|
|
|
state.knownDomains = domains
|
2018-09-09 18:21:23 +00:00
|
|
|
}
|
|
|
|
},
|
2019-09-29 20:47:26 +00:00
|
|
|
getters: {
|
|
|
|
instanceDefaultConfig (state) {
|
|
|
|
return instanceDefaultProperties
|
|
|
|
.map(key => [key, state[key]])
|
|
|
|
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {})
|
2022-01-10 06:16:33 +00:00
|
|
|
},
|
|
|
|
instanceDomain (state) {
|
|
|
|
return new URL(state.server).hostname
|
2022-09-19 17:39:21 +00:00
|
|
|
},
|
|
|
|
remoteInteractionLink (state) {
|
|
|
|
const server = state.server.endsWith('/') ? state.server.slice(0, -1) : state.server
|
|
|
|
const link = server + REMOTE_INTERACTION_URL
|
|
|
|
|
|
|
|
return ({ statusId, nickname }) => {
|
|
|
|
if (statusId) {
|
|
|
|
return `${link}?status_id=${statusId}`
|
|
|
|
} else {
|
|
|
|
return `${link}?nickname=${nickname}`
|
|
|
|
}
|
|
|
|
}
|
2019-09-29 20:47:26 +00:00
|
|
|
}
|
|
|
|
},
|
2018-09-09 18:21:23 +00:00
|
|
|
actions: {
|
|
|
|
setInstanceOption ({ commit, dispatch }, { name, value }) {
|
2019-07-05 07:02:14 +00:00
|
|
|
commit('setInstanceOption', { name, value })
|
2018-09-09 18:21:23 +00:00
|
|
|
switch (name) {
|
|
|
|
case 'name':
|
|
|
|
dispatch('setPageTitle')
|
|
|
|
break
|
2020-01-21 22:37:19 +00:00
|
|
|
case 'theme':
|
|
|
|
dispatch('setTheme', value)
|
|
|
|
break
|
2018-09-09 18:21:23 +00:00
|
|
|
}
|
2019-02-09 09:26:35 +00:00
|
|
|
},
|
2019-10-09 19:50:00 +00:00
|
|
|
async getStaticEmoji ({ commit }) {
|
|
|
|
try {
|
|
|
|
const res = await window.fetch('/static/emoji.json')
|
|
|
|
if (res.ok) {
|
|
|
|
const values = await res.json()
|
|
|
|
const emoji = Object.keys(values).map((key) => {
|
|
|
|
return {
|
|
|
|
displayText: key,
|
|
|
|
imageUrl: false,
|
|
|
|
replacement: values[key]
|
|
|
|
}
|
2021-01-04 19:09:12 +00:00
|
|
|
}).sort((a, b) => a.name > b.name ? 1 : -1)
|
2019-10-09 19:50:00 +00:00
|
|
|
commit('setInstanceOption', { name: 'emoji', value: emoji })
|
|
|
|
} else {
|
|
|
|
throw (res)
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("Can't load static emoji")
|
|
|
|
console.warn(e)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async getCustomEmoji ({ commit, state }) {
|
|
|
|
try {
|
2022-12-14 09:39:01 +00:00
|
|
|
const res = await window.fetch('/api/v1/pleroma/emoji')
|
2019-10-09 19:50:00 +00:00
|
|
|
if (res.ok) {
|
|
|
|
const result = await res.json()
|
|
|
|
const values = Array.isArray(result) ? Object.assign({}, ...result) : result
|
|
|
|
const emoji = Object.entries(values).map(([key, value]) => {
|
|
|
|
const imageUrl = value.image_url
|
|
|
|
return {
|
|
|
|
displayText: key,
|
|
|
|
imageUrl: imageUrl ? state.server + imageUrl : value,
|
|
|
|
tags: imageUrl ? value.tags.sort((a, b) => a > b ? 1 : 0) : ['utf'],
|
|
|
|
replacement: `:${key}: `
|
|
|
|
}
|
|
|
|
// Technically could use tags but those are kinda useless right now,
|
|
|
|
// should have been "pack" field, that would be more useful
|
2021-01-04 19:09:12 +00:00
|
|
|
}).sort((a, b) => a.displayText.toLowerCase() > b.displayText.toLowerCase() ? 1 : -1)
|
2019-10-09 19:50:00 +00:00
|
|
|
commit('setInstanceOption', { name: 'customEmoji', value: emoji })
|
|
|
|
} else {
|
|
|
|
throw (res)
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("Can't load custom emojis")
|
|
|
|
console.warn(e)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-21 22:37:19 +00:00
|
|
|
setTheme ({ commit, rootState }, themeName) {
|
2019-02-09 09:26:35 +00:00
|
|
|
commit('setInstanceOption', { name: 'theme', value: themeName })
|
2020-01-21 22:37:19 +00:00
|
|
|
getPreset(themeName)
|
|
|
|
.then(themeData => {
|
|
|
|
commit('setInstanceOption', { name: 'themeData', value: themeData })
|
|
|
|
// No need to apply theme if there's user theme already
|
|
|
|
const { customTheme } = rootState.config
|
|
|
|
if (customTheme) return
|
2020-02-22 08:57:08 +00:00
|
|
|
|
|
|
|
// New theme presets don't have 'theme' property, they use 'source'
|
|
|
|
const themeSource = themeData.source
|
2020-02-28 17:20:40 +00:00
|
|
|
if (!themeData.theme || (themeSource && themeSource.themeEngineVersion === CURRENT_VERSION)) {
|
2020-02-22 08:57:08 +00:00
|
|
|
applyTheme(themeSource)
|
|
|
|
} else {
|
|
|
|
applyTheme(themeData.theme)
|
|
|
|
}
|
2020-01-21 22:37:19 +00:00
|
|
|
})
|
2019-10-09 19:50:00 +00:00
|
|
|
},
|
|
|
|
fetchEmoji ({ dispatch, state }) {
|
|
|
|
if (!state.customEmojiFetched) {
|
|
|
|
state.customEmojiFetched = true
|
|
|
|
dispatch('getCustomEmoji')
|
|
|
|
}
|
|
|
|
if (!state.emojiFetched) {
|
|
|
|
state.emojiFetched = true
|
|
|
|
dispatch('getStaticEmoji')
|
|
|
|
}
|
2020-05-10 10:54:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
async getKnownDomains ({ commit, rootState }) {
|
|
|
|
try {
|
|
|
|
const result = await apiService.fetchKnownDomains({
|
|
|
|
credentials: rootState.users.currentUser.credentials
|
|
|
|
})
|
|
|
|
commit('setKnownDomains', result)
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("Can't load known domains")
|
|
|
|
console.warn(e)
|
|
|
|
}
|
2018-09-09 18:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default instance
|