2020-01-21 14:37:19 -08:00
|
|
|
import { getPreset, applyTheme } from '../services/style_setter/style_setter.js'
|
2020-02-22 00:57:08 -08:00
|
|
|
import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
|
2020-05-10 03:54:55 -07:00
|
|
|
import apiService from '../services/api/api.service.js'
|
2019-09-29 13:47:26 -07:00
|
|
|
import { instanceDefaultProperties } from './config.js'
|
2022-09-20 17:15:32 -07:00
|
|
|
import { langCodeToCldrName, ensureFinalFallback } from '../i18n/languages.js'
|
2018-09-09 11:21:23 -07:00
|
|
|
|
2022-01-08 13:55:00 -08:00
|
|
|
const SORTED_EMOJI_GROUP_IDS = [
|
|
|
|
'smileys-and-emotion',
|
|
|
|
'people-and-body',
|
|
|
|
'animals-and-nature',
|
|
|
|
'food-and-drink',
|
|
|
|
'travel-and-places',
|
|
|
|
'activities',
|
|
|
|
'objects',
|
|
|
|
'symbols',
|
|
|
|
'flags'
|
|
|
|
]
|
|
|
|
|
2022-09-20 18:50:40 -07:00
|
|
|
const REGIONAL_INDICATORS = (() => {
|
|
|
|
const start = 0x1F1E6
|
|
|
|
const end = 0x1F1FF
|
|
|
|
const A = 'A'.codePointAt(0)
|
|
|
|
const res = new Array(end - start + 1)
|
|
|
|
for (let i = start; i <= end; ++i) {
|
|
|
|
const letter = String.fromCodePoint(A + i - start)
|
|
|
|
res[i - start] = {
|
|
|
|
replacement: String.fromCodePoint(i),
|
|
|
|
imageUrl: false,
|
|
|
|
displayText: 'regional_indicator_' + letter,
|
|
|
|
displayTextI18n: {
|
|
|
|
key: 'emoji.regional_indicator',
|
|
|
|
args: { letter }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
})()
|
|
|
|
|
2021-12-28 15:30:34 -08:00
|
|
|
const REMOTE_INTERACTION_URL = '/main/ostatus'
|
|
|
|
|
2018-09-09 11:21:23 -07:00
|
|
|
const defaultState = {
|
2020-05-13 13:40:13 -07:00
|
|
|
// Stuff from apiConfig
|
2018-09-09 11:21:23 -07:00
|
|
|
name: 'Pleroma FE',
|
|
|
|
registrationOpen: true,
|
|
|
|
server: 'http://localhost:4040/',
|
2020-05-13 13:40:13 -07:00
|
|
|
textlimit: 5000,
|
2020-01-21 14:37:19 -08:00
|
|
|
themeData: undefined,
|
2020-05-13 13:40:13 -07:00
|
|
|
vapidPublicKey: undefined,
|
|
|
|
|
|
|
|
// Stuff from static/config.json
|
2018-12-02 19:47:35 -08:00
|
|
|
alwaysShowSubjectInput: true,
|
2020-07-08 03:11:17 -07:00
|
|
|
defaultAvatar: '/images/avi.png',
|
|
|
|
defaultBanner: '/images/banner.png',
|
2020-05-13 12:40:46 -07:00
|
|
|
background: '/static/aurora_borealis.jpg',
|
2018-09-09 11:21:23 -07:00
|
|
|
collapseMessageWithSubject: false,
|
2020-05-13 12:40:46 -07:00
|
|
|
greentext: false,
|
2022-01-09 21:37:39 -08:00
|
|
|
useAtIcon: false,
|
2022-01-09 22:16:33 -08:00
|
|
|
mentionLinkDisplay: 'short',
|
|
|
|
mentionLinkShowTooltip: true,
|
2022-01-20 09:07:09 -08:00
|
|
|
mentionLinkShowAvatar: false,
|
2022-01-09 23:31:26 -08:00
|
|
|
mentionLinkFadeDomain: true,
|
2022-02-03 12:34:57 -08:00
|
|
|
mentionLinkShowYous: false,
|
|
|
|
mentionLinkBoldenYou: true,
|
2020-05-13 12:40:46 -07:00
|
|
|
hideFilteredStatuses: false,
|
2021-06-08 06:14:01 -07:00
|
|
|
// bad name: actually hides posts of muted USERS
|
2020-05-13 12:40:46 -07:00
|
|
|
hideMutedPosts: false,
|
2021-06-08 06:14:01 -07:00
|
|
|
hideMutedThreads: true,
|
|
|
|
hideWordFilteredPosts: false,
|
2018-10-16 06:09:29 -07:00
|
|
|
hidePostStats: false,
|
2022-02-28 13:35:00 -08:00
|
|
|
hideBotIndication: false,
|
2019-12-01 16:34:01 -08:00
|
|
|
hideSitename: false,
|
2018-10-16 06:09:29 -07:00
|
|
|
hideUserStats: false,
|
2022-02-28 12:07:20 -08:00
|
|
|
muteBotStatuses: false,
|
2020-05-13 12:46:31 -07:00
|
|
|
loginMethod: 'password',
|
2020-11-02 09:37:01 -08:00
|
|
|
logo: '/static/logo.svg',
|
2020-05-13 12:40:46 -07:00
|
|
|
logoMargin: '.2em',
|
|
|
|
logoMask: true,
|
2020-10-29 12:13:31 -07:00
|
|
|
logoLeft: false,
|
2022-08-07 16:01:07 -07:00
|
|
|
disableUpdateNotification: false,
|
2020-05-13 12:40:46 -07:00
|
|
|
minimalScopesMode: false,
|
2018-12-13 09:41:01 -08:00
|
|
|
nsfwCensorImage: undefined,
|
2020-05-13 12:40:46 -07:00
|
|
|
postContentType: 'text/plain',
|
|
|
|
redirectRootLogin: '/main/friends',
|
|
|
|
redirectRootNoLogin: '/main/all',
|
2018-09-25 05:16:26 -07:00
|
|
|
scopeCopy: true,
|
2019-02-08 13:20:47 -08:00
|
|
|
showFeaturesPanel: true,
|
2020-05-13 12:40:46 -07:00
|
|
|
showInstanceSpecificPanel: false,
|
2020-05-12 11:59:52 -07:00
|
|
|
sidebarRight: false,
|
2018-09-25 04:47:02 -07:00
|
|
|
subjectLineBehavior: 'email',
|
2020-05-13 12:40:46 -07:00
|
|
|
theme: 'pleroma-dark',
|
2020-09-29 03:18:37 -07:00
|
|
|
virtualScrolling: true,
|
2021-02-23 00:00:23 -08:00
|
|
|
sensitiveByDefault: false,
|
2022-03-06 10:57:48 -08:00
|
|
|
conversationDisplay: 'linear',
|
|
|
|
conversationTreeAdvanced: false,
|
2021-09-05 13:35:47 -07:00
|
|
|
conversationOtherRepliesButton: 'below',
|
2022-03-06 11:13:35 -08:00
|
|
|
conversationTreeFadeAncestors: false,
|
2021-08-07 17:14:14 -07:00
|
|
|
maxDepthInThread: 6,
|
2018-09-09 11:51:40 -07:00
|
|
|
|
2018-09-09 11:21:23 -07:00
|
|
|
// Nasty stuff
|
|
|
|
customEmoji: [],
|
2019-10-09 12:50:00 -07:00
|
|
|
customEmojiFetched: false,
|
2022-01-08 13:55:00 -08:00
|
|
|
emoji: {},
|
2020-05-13 13:40:13 -07:00
|
|
|
emojiFetched: false,
|
2022-09-20 17:15:32 -07:00
|
|
|
unicodeEmojiAnnotations: {},
|
2020-05-13 13:40:13 -07:00
|
|
|
pleromaBackend: true,
|
2019-03-04 21:29:56 -08:00
|
|
|
postFormats: [],
|
2020-05-13 13:40:13 -07:00
|
|
|
restrictedNicknames: [],
|
|
|
|
safeDM: true,
|
2020-05-10 03:54:55 -07:00
|
|
|
knownDomains: [],
|
2018-09-09 11:51:40 -07:00
|
|
|
|
|
|
|
// Feature-set, apparently, not everything here is reported...
|
2020-08-03 16:44:35 -07:00
|
|
|
shoutAvailable: false,
|
2020-05-07 06:10:53 -07:00
|
|
|
pleromaChatMessagesAvailable: false,
|
2018-09-09 11:51:40 -07:00
|
|
|
gopherAvailable: false,
|
2020-05-13 13:48:21 -07:00
|
|
|
mediaProxyAvailable: false,
|
2018-09-09 11:51:40 -07:00
|
|
|
suggestionsEnabled: false,
|
|
|
|
suggestionsWeb: '',
|
|
|
|
|
2018-09-09 11:21:23 -07:00
|
|
|
// Html stuff
|
|
|
|
instanceSpecificPanelContent: '',
|
2019-03-10 16:58:12 -07:00
|
|
|
tos: '',
|
|
|
|
|
|
|
|
// Version Information
|
|
|
|
backendVersion: '',
|
2019-06-18 13:28:31 -07:00
|
|
|
frontendVersion: '',
|
|
|
|
|
|
|
|
pollsAvailable: false,
|
|
|
|
pollLimits: {
|
|
|
|
max_options: 4,
|
|
|
|
max_option_chars: 255,
|
|
|
|
min_expiration: 60,
|
|
|
|
max_expiration: 60 * 60 * 24
|
|
|
|
}
|
2018-09-09 11:21:23 -07:00
|
|
|
}
|
|
|
|
|
2022-09-20 17:15:32 -07:00
|
|
|
const loadAnnotations = (lang) => {
|
|
|
|
return import(
|
2022-09-20 20:13:07 -07:00
|
|
|
/* webpackChunkName: "emoji-annotations/[request]" */
|
2022-09-20 17:15:32 -07:00
|
|
|
`@kazvmoe-infra/unicode-emoji-json/annotations/${langCodeToCldrName(lang)}.json`
|
|
|
|
)
|
2022-09-20 19:03:31 -07:00
|
|
|
.then(k => k.default)
|
2022-09-20 17:15:32 -07:00
|
|
|
}
|
|
|
|
|
2022-09-20 17:44:52 -07:00
|
|
|
const injectAnnotations = (emoji, annotations) => {
|
|
|
|
const availableLangs = Object.keys(annotations)
|
|
|
|
|
|
|
|
return {
|
|
|
|
...emoji,
|
|
|
|
annotations: availableLangs.reduce((acc, cur) => {
|
|
|
|
acc[cur] = annotations[cur][emoji.replacement]
|
|
|
|
return acc
|
|
|
|
}, {})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-20 18:50:40 -07:00
|
|
|
const injectRegionalIndicators = groups => {
|
|
|
|
groups.symbols.push(...REGIONAL_INDICATORS)
|
|
|
|
return groups
|
|
|
|
}
|
|
|
|
|
2018-09-09 11:21:23 -07:00
|
|
|
const instance = {
|
|
|
|
state: defaultState,
|
|
|
|
mutations: {
|
|
|
|
setInstanceOption (state, { name, value }) {
|
2018-09-17 08:54:08 -07:00
|
|
|
if (typeof value !== 'undefined') {
|
2021-04-25 03:24:08 -07:00
|
|
|
state[name] = value
|
2018-09-17 08:54:08 -07:00
|
|
|
}
|
2020-05-10 03:54:55 -07:00
|
|
|
},
|
|
|
|
setKnownDomains (state, domains) {
|
|
|
|
state.knownDomains = domains
|
2022-09-20 17:15:32 -07:00
|
|
|
},
|
|
|
|
setUnicodeEmojiAnnotations (state, { lang, annotations }) {
|
|
|
|
state.unicodeEmojiAnnotations[lang] = annotations
|
2018-09-09 11:21:23 -07:00
|
|
|
}
|
|
|
|
},
|
2019-09-29 13:47:26 -07:00
|
|
|
getters: {
|
|
|
|
instanceDefaultConfig (state) {
|
|
|
|
return instanceDefaultProperties
|
|
|
|
.map(key => [key, state[key]])
|
|
|
|
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {})
|
2022-01-09 22:16:33 -08:00
|
|
|
},
|
2021-08-14 21:43:35 -07:00
|
|
|
groupedCustomEmojis (state) {
|
2021-10-08 12:30:55 -07:00
|
|
|
const packsOf = emoji => {
|
|
|
|
return emoji.tags
|
|
|
|
.filter(k => k.startsWith('pack:'))
|
|
|
|
.map(k => k.slice(5)) // remove 'pack:' prefix
|
|
|
|
}
|
|
|
|
|
2021-08-14 21:43:35 -07:00
|
|
|
return state.customEmoji
|
|
|
|
.reduce((res, emoji) => {
|
2021-10-08 12:30:55 -07:00
|
|
|
packsOf(emoji).forEach(packName => {
|
2021-08-14 21:43:35 -07:00
|
|
|
const packId = `custom-${packName}`
|
|
|
|
if (!res[packId]) {
|
|
|
|
res[packId] = ({
|
|
|
|
id: packId,
|
|
|
|
text: packName,
|
|
|
|
image: emoji.imageUrl,
|
|
|
|
emojis: []
|
|
|
|
})
|
|
|
|
}
|
|
|
|
res[packId].emojis.push(emoji)
|
|
|
|
})
|
|
|
|
return res
|
|
|
|
}, {})
|
|
|
|
},
|
2022-01-08 13:55:00 -08:00
|
|
|
standardEmojiList (state) {
|
|
|
|
return SORTED_EMOJI_GROUP_IDS
|
2022-09-20 17:44:52 -07:00
|
|
|
.map(groupId => (state.emoji[groupId] || []).map(k => injectAnnotations(k, state.unicodeEmojiAnnotations)))
|
2022-01-08 13:55:00 -08:00
|
|
|
.reduce((a, b) => a.concat(b), [])
|
|
|
|
},
|
|
|
|
standardEmojiGroupList (state) {
|
|
|
|
return SORTED_EMOJI_GROUP_IDS.map(groupId => ({
|
|
|
|
id: groupId,
|
2022-09-20 17:44:52 -07:00
|
|
|
emojis: (state.emoji[groupId] || []).map(k => injectAnnotations(k, state.unicodeEmojiAnnotations))
|
2022-01-08 13:55:00 -08:00
|
|
|
}))
|
|
|
|
},
|
2022-01-09 22:16:33 -08:00
|
|
|
instanceDomain (state) {
|
|
|
|
return new URL(state.server).hostname
|
2021-12-28 15:30:34 -08: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 13:47:26 -07:00
|
|
|
}
|
|
|
|
},
|
2018-09-09 11:21:23 -07:00
|
|
|
actions: {
|
|
|
|
setInstanceOption ({ commit, dispatch }, { name, value }) {
|
2019-07-05 00:02:14 -07:00
|
|
|
commit('setInstanceOption', { name, value })
|
2018-09-09 11:21:23 -07:00
|
|
|
switch (name) {
|
|
|
|
case 'name':
|
|
|
|
dispatch('setPageTitle')
|
|
|
|
break
|
2020-08-03 16:44:35 -07:00
|
|
|
case 'shoutAvailable':
|
2019-08-17 01:18:42 -07:00
|
|
|
if (value) {
|
|
|
|
dispatch('initializeSocket')
|
|
|
|
}
|
|
|
|
break
|
2020-01-21 14:37:19 -08:00
|
|
|
case 'theme':
|
|
|
|
dispatch('setTheme', value)
|
|
|
|
break
|
2018-09-09 11:21:23 -07:00
|
|
|
}
|
2019-02-09 01:26:35 -08:00
|
|
|
},
|
2019-10-09 12:50:00 -07:00
|
|
|
async getStaticEmoji ({ commit }) {
|
|
|
|
try {
|
2022-09-20 20:13:07 -07:00
|
|
|
const values = (await import(/* webpackChunkName: 'emoji' */ '../../static/emoji.json')).default
|
2022-09-20 19:03:31 -07:00
|
|
|
|
|
|
|
const emoji = Object.keys(values).reduce((res, groupId) => {
|
|
|
|
res[groupId] = values[groupId].map(e => ({
|
|
|
|
displayText: e.slug,
|
|
|
|
imageUrl: false,
|
|
|
|
replacement: e.emoji
|
|
|
|
}))
|
|
|
|
return res
|
|
|
|
}, {})
|
|
|
|
commit('setInstanceOption', { name: 'emoji', value: injectRegionalIndicators(emoji) })
|
2019-10-09 12:50:00 -07:00
|
|
|
} catch (e) {
|
|
|
|
console.warn("Can't load static emoji")
|
|
|
|
console.warn(e)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-09-20 17:15:32 -07:00
|
|
|
loadUnicodeEmojiData ({ commit, state }, language) {
|
2022-09-20 17:44:52 -07:00
|
|
|
const langList = ensureFinalFallback(language)
|
2022-09-20 17:15:32 -07:00
|
|
|
|
|
|
|
return Promise.all(
|
|
|
|
langList
|
2022-09-20 18:50:40 -07:00
|
|
|
.map(async lang => {
|
2022-09-20 17:15:32 -07:00
|
|
|
if (!state.unicodeEmojiAnnotations[lang]) {
|
|
|
|
const annotations = await loadAnnotations(lang)
|
|
|
|
commit('setUnicodeEmojiAnnotations', { lang, annotations })
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
|
2019-10-09 12:50:00 -07:00
|
|
|
async getCustomEmoji ({ commit, state }) {
|
|
|
|
try {
|
|
|
|
const res = await window.fetch('/api/pleroma/emoji.json')
|
|
|
|
if (res.ok) {
|
|
|
|
const result = await res.json()
|
|
|
|
const values = Array.isArray(result) ? Object.assign({}, ...result) : result
|
2021-08-14 18:23:45 -07:00
|
|
|
const caseInsensitiveStrCmp = (a, b) => {
|
|
|
|
const la = a.toLowerCase()
|
|
|
|
const lb = b.toLowerCase()
|
|
|
|
return la > lb ? 1 : (la < lb ? -1 : 0)
|
|
|
|
}
|
|
|
|
const byPackThenByName = (a, b) => {
|
|
|
|
const packOf = emoji => (emoji.tags.filter(k => k.startsWith('pack:'))[0] || '').slice(5)
|
|
|
|
return caseInsensitiveStrCmp(packOf(a), packOf(b)) || caseInsensitiveStrCmp(a.displayText, b.displayText)
|
|
|
|
}
|
|
|
|
|
2019-10-09 12:50:00 -07:00
|
|
|
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-08-14 18:23:45 -07:00
|
|
|
}).sort(byPackThenByName)
|
2019-10-09 12:50:00 -07: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 14:37:19 -08:00
|
|
|
setTheme ({ commit, rootState }, themeName) {
|
2019-02-09 01:26:35 -08:00
|
|
|
commit('setInstanceOption', { name: 'theme', value: themeName })
|
2020-01-21 14:37:19 -08: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 00:57:08 -08:00
|
|
|
|
|
|
|
// New theme presets don't have 'theme' property, they use 'source'
|
|
|
|
const themeSource = themeData.source
|
2020-02-28 09:20:40 -08:00
|
|
|
if (!themeData.theme || (themeSource && themeSource.themeEngineVersion === CURRENT_VERSION)) {
|
2020-02-22 00:57:08 -08:00
|
|
|
applyTheme(themeSource)
|
|
|
|
} else {
|
|
|
|
applyTheme(themeData.theme)
|
|
|
|
}
|
2020-01-21 14:37:19 -08:00
|
|
|
})
|
2019-10-09 12:50:00 -07:00
|
|
|
},
|
|
|
|
fetchEmoji ({ dispatch, state }) {
|
|
|
|
if (!state.customEmojiFetched) {
|
|
|
|
state.customEmojiFetched = true
|
|
|
|
dispatch('getCustomEmoji')
|
|
|
|
}
|
|
|
|
if (!state.emojiFetched) {
|
|
|
|
state.emojiFetched = true
|
|
|
|
dispatch('getStaticEmoji')
|
|
|
|
}
|
2020-05-10 03:54:55 -07: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 11:21:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default instance
|