moved emoji fetching from user to instance since it's its state anyway
This commit is contained in:
parent
b02de56fcb
commit
c000879f2f
2 changed files with 62 additions and 52 deletions
|
@ -35,7 +35,9 @@ const defaultState = {
|
||||||
// Nasty stuff
|
// Nasty stuff
|
||||||
pleromaBackend: true,
|
pleromaBackend: true,
|
||||||
emoji: [],
|
emoji: [],
|
||||||
|
emojiFetched: false,
|
||||||
customEmoji: [],
|
customEmoji: [],
|
||||||
|
customEmojiFetched: false,
|
||||||
restrictedNicknames: [],
|
restrictedNicknames: [],
|
||||||
postFormats: [],
|
postFormats: [],
|
||||||
|
|
||||||
|
@ -86,9 +88,68 @@ const instance = {
|
||||||
break
|
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) {
|
setTheme ({ commit }, themeName) {
|
||||||
commit('setInstanceOption', { name: 'theme', value: themeName })
|
commit('setInstanceOption', { name: 'theme', value: themeName })
|
||||||
return setPreset(themeName, commit)
|
return setPreset(themeName, commit)
|
||||||
|
},
|
||||||
|
fetchEmoji ({ dispatch, state }) {
|
||||||
|
if (!state.customEmojiFetched) {
|
||||||
|
state.customEmojiFetched = true
|
||||||
|
dispatch('getCustomEmoji')
|
||||||
|
}
|
||||||
|
if (!state.emojiFetched) {
|
||||||
|
state.emojiFetched = true
|
||||||
|
dispatch('getStaticEmoji')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,56 +60,6 @@ const unmuteUser = (store, id) => {
|
||||||
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
|
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStaticEmoji = async (store) => {
|
|
||||||
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)
|
|
||||||
store.dispatch('setInstanceOption', { name: 'emoji', value: emoji })
|
|
||||||
} else {
|
|
||||||
throw (res)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("Can't load static emoji")
|
|
||||||
console.warn(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is also used to indicate if we have a 'pleroma backend' or not.
|
|
||||||
// Somewhat weird, should probably be somewhere else.
|
|
||||||
const getCustomEmoji = async (store) => {
|
|
||||||
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 ? store.rootState.instance.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)
|
|
||||||
store.dispatch('setInstanceOption', { name: 'customEmoji', value: emoji })
|
|
||||||
} else {
|
|
||||||
throw (res)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("Can't load custom emojis")
|
|
||||||
console.warn(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
setMuted (state, { user: { id }, muted }) {
|
setMuted (state, { user: { id }, muted }) {
|
||||||
const user = state.usersObject[id]
|
const user = state.usersObject[id]
|
||||||
|
@ -484,8 +434,7 @@ const users = {
|
||||||
commit('setCurrentUser', user)
|
commit('setCurrentUser', user)
|
||||||
commit('addNewUsers', [user])
|
commit('addNewUsers', [user])
|
||||||
|
|
||||||
getCustomEmoji(store)
|
store.dispatch('fetchEmoji')
|
||||||
getStaticEmoji(store)
|
|
||||||
|
|
||||||
getNotificationPermission()
|
getNotificationPermission()
|
||||||
.then(permission => commit('setNotificationPermission', permission))
|
.then(permission => commit('setNotificationPermission', permission))
|
||||||
|
|
Loading…
Reference in a new issue