Merge branch 'emoji-mastoapi' into shigusegubu

* emoji-mastoapi:
  use mastoapi emoji endpoint since it's already sorted, should speed things up on instances with tons of emoji
  fix tests
This commit is contained in:
Henry Jameson 2019-09-26 21:38:57 +03:00
commit 0a5147edf2
2 changed files with 25 additions and 18 deletions

View file

@ -199,20 +199,18 @@ const getStaticEmoji = async ({ store }) => {
// Somewhat weird, should probably be somewhere else. // Somewhat weird, should probably be somewhere else.
const getCustomEmoji = async ({ store }) => { const getCustomEmoji = async ({ store }) => {
try { try {
const res = await window.fetch('/api/pleroma/emoji.json') const res = await window.fetch('/api/v1/custom_emojis')
if (res.ok) { if (res.ok) {
const result = await res.json() const result = await res.json()
const values = Array.isArray(result) ? Object.assign({}, ...result) : result const emoji = result.map(({ url, shortcode, tags, category }) => {
const emoji = Object.entries(values).map(([key, value]) => {
const imageUrl = value.image_url
return { return {
displayText: key, displayText: shortcode,
imageUrl: imageUrl ? store.state.instance.server + imageUrl : value, imageUrl: url,
tags: imageUrl ? value.tags.sort((a, b) => a > b ? 1 : 0) : ['utf'], tags,
replacement: `:${key}: ` category,
replacement: `:${shortcode}: `
} }
// 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 }) store.dispatch('setInstanceOption', { name: 'customEmoji', value: emoji })
store.dispatch('setInstanceOption', { name: 'pleromaBackend', value: true }) store.dispatch('setInstanceOption', { name: 'pleromaBackend', value: true })
} else { } else {

View file

@ -1,7 +1,7 @@
import { shallowMount, createLocalVue } from '@vue/test-utils' import { shallowMount, createLocalVue } from '@vue/test-utils'
import EmojiInput from 'src/components/emoji_input/emoji_input.vue' import EmojiInput from 'src/components/emoji_input/emoji_input.vue'
const generateInput = (value) => { const generateInput = (value, padEmoji = true) => {
const localVue = createLocalVue() const localVue = createLocalVue()
localVue.directive('click-outside', () => {}) localVue.directive('click-outside', () => {})
const wrapper = shallowMount(EmojiInput, { const wrapper = shallowMount(EmojiInput, {
@ -10,6 +10,15 @@ const generateInput = (value) => {
enableEmojiPicker: true, enableEmojiPicker: true,
value value
}, },
mocks: {
$store: {
state: {
config: {
padEmoji
}
}
}
},
slots: { slots: {
default: '<input />' default: '<input />'
}, },
@ -70,13 +79,13 @@ describe('EmojiInput', () => {
expect(wrapper.emitted().input[0][0]).to.eql('Spurdo :ebin: Sparde') expect(wrapper.emitted().input[0][0]).to.eql('Spurdo :ebin: Sparde')
}) })
it('inserts string without any padding in spam mode', () => { it('inserts string without any padding if padEmoji setting is set to false', () => {
const initialString = 'Eat some spam!' const initialString = 'Eat some spam!'
const [wrapper] = generateInput(initialString) const [wrapper] = generateInput(initialString, false)
const input = wrapper.find('input') const input = wrapper.find('input')
input.setValue(initialString) input.setValue(initialString)
wrapper.setData({ caret: initialString.length }) wrapper.setData({ caret: initialString.length, keepOpen: false })
wrapper.vm.insert({ insertion: ':spam:', keepOpen: true }) wrapper.vm.insert({ insertion: ':spam:' })
expect(wrapper.emitted().input[0][0]).to.eql('Eat some spam!:spam:') expect(wrapper.emitted().input[0][0]).to.eql('Eat some spam!:spam:')
}) })
@ -106,13 +115,13 @@ describe('EmojiInput', () => {
}) })
}) })
it('correctly sets caret after insertion in spam mode', (done) => { it('correctly sets caret after insertion if padEmoji setting is set to false', (done) => {
const initialString = '1234' const initialString = '1234'
const [wrapper, vue] = generateInput(initialString) const [wrapper, vue] = generateInput(initialString, false)
const input = wrapper.find('input') const input = wrapper.find('input')
input.setValue(initialString) input.setValue(initialString)
wrapper.setData({ caret: initialString.length }) wrapper.setData({ caret: initialString.length })
wrapper.vm.insert({ insertion: '1234', keepOpen: true }) wrapper.vm.insert({ insertion: '1234', keepOpen: false })
vue.nextTick(() => { vue.nextTick(() => {
expect(wrapper.vm.caret).to.eql(8) expect(wrapper.vm.caret).to.eql(8)
done() done()