aboutsummaryrefslogtreecommitdiff
path: root/src/modules/instance.js
diff options
context:
space:
mode:
authorHJ <30-hj@users.noreply.git.pleroma.social>2019-11-08 22:01:42 +0000
committerHJ <30-hj@users.noreply.git.pleroma.social>2019-11-08 22:01:42 +0000
commit2b68134ab01266913b89b79ea6c3e9575278ecb2 (patch)
tree69a410f34429c52c7cdd335e1bdfeba795ba8f6c /src/modules/instance.js
parent5679dcdd18750a1fc9ac1d4eeea3fd3b642a2151 (diff)
parenta3501d58d8703379d5f60e1bb53dfb0dbb1022b2 (diff)
Merge branch 'emoji-optimizations' into 'develop'
Emoji fixes, optimizations and improvements Closes #690, #686, #682, #674, and #678 See merge request pleroma/pleroma-fe!969
Diffstat (limited to 'src/modules/instance.js')
-rw-r--r--src/modules/instance.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/modules/instance.js b/src/modules/instance.js
index 0c1235ca..7b0e0da4 100644
--- a/src/modules/instance.js
+++ b/src/modules/instance.js
@@ -36,7 +36,9 @@ const defaultState = {
// Nasty stuff
pleromaBackend: true,
emoji: [],
+ emojiFetched: false,
customEmoji: [],
+ customEmojiFetched: false,
restrictedNicknames: [],
postFormats: [],
@@ -94,9 +96,68 @@ const instance = {
break
}
},
+ 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]
+ }
+ }).sort((a, b) => a.displayText - b.displayText)
+ 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 {
+ 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
+ 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
+ }).sort((a, b) => a.displayText.toLowerCase() > b.displayText.toLowerCase() ? 1 : 0)
+ commit('setInstanceOption', { name: 'customEmoji', value: emoji })
+ } else {
+ throw (res)
+ }
+ } catch (e) {
+ console.warn("Can't load custom emojis")
+ console.warn(e)
+ }
+ },
+
setTheme ({ commit }, themeName) {
commit('setInstanceOption', { name: 'theme', value: themeName })
return setPreset(themeName, commit)
+ },
+ fetchEmoji ({ dispatch, state }) {
+ if (!state.customEmojiFetched) {
+ state.customEmojiFetched = true
+ dispatch('getCustomEmoji')
+ }
+ if (!state.emojiFetched) {
+ state.emojiFetched = true
+ dispatch('getStaticEmoji')
+ }
}
}
}