mirror of
https://git.youjo.love/youjo/youjo-fe.git
synced 2024-11-20 05:49:54 +01:00
remove old emoji added, everything emoji-bearing uses RichContent now
This commit is contained in:
parent
4c974f5ca2
commit
97e86381c8
2 changed files with 3 additions and 48 deletions
|
@ -65,8 +65,8 @@ export const parseUser = (data) => {
|
||||||
output.fields = data.fields
|
output.fields = data.fields
|
||||||
output.fields_html = data.fields.map(field => {
|
output.fields_html = data.fields.map(field => {
|
||||||
return {
|
return {
|
||||||
name: addEmojis(escape(field.name), data.emojis),
|
name: escape(field.name),
|
||||||
value: addEmojis(field.value, data.emojis)
|
value: field.value
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
output.fields_text = data.fields.map(field => {
|
output.fields_text = data.fields.map(field => {
|
||||||
|
@ -241,16 +241,6 @@ export const parseAttachment = (data) => {
|
||||||
|
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
export const addEmojis = (string, emojis) => {
|
|
||||||
const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g
|
|
||||||
return emojis.reduce((acc, emoji) => {
|
|
||||||
const regexSafeShortCode = emoji.shortcode.replace(matchOperatorsRegex, '\\$&')
|
|
||||||
return acc.replace(
|
|
||||||
new RegExp(`:${regexSafeShortCode}:`, 'g'),
|
|
||||||
`<img src='${emoji.url}' alt=':${emoji.shortcode}:' title=':${emoji.shortcode}:' class='emoji' />`
|
|
||||||
)
|
|
||||||
}, string)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const parseStatus = (data) => {
|
export const parseStatus = (data) => {
|
||||||
const output = {}
|
const output = {}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { parseStatus, parseUser, parseNotification, addEmojis, parseLinkHeaderPagination } from '../../../../../src/services/entity_normalizer/entity_normalizer.service.js'
|
import { parseStatus, parseUser, parseNotification, parseLinkHeaderPagination } from '../../../../../src/services/entity_normalizer/entity_normalizer.service.js'
|
||||||
import mastoapidata from '../../../../fixtures/mastoapi.json'
|
import mastoapidata from '../../../../fixtures/mastoapi.json'
|
||||||
import qvitterapidata from '../../../../fixtures/statuses.json'
|
import qvitterapidata from '../../../../fixtures/statuses.json'
|
||||||
|
|
||||||
|
@ -338,41 +338,6 @@ describe('API Entities normalizer', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('MastoAPI emoji adder', () => {
|
|
||||||
const emojis = makeMockEmojiMasto()
|
|
||||||
const imageHtml = '<img src="https://example.com/image.png" alt=":image:" title=":image:" class="emoji" />'
|
|
||||||
.replace(/"/g, '\'')
|
|
||||||
const thinkHtml = '<img src="https://example.com/think.png" alt=":thinking:" title=":thinking:" class="emoji" />'
|
|
||||||
.replace(/"/g, '\'')
|
|
||||||
|
|
||||||
it('correctly replaces shortcodes in supplied string', () => {
|
|
||||||
const result = addEmojis('This post has :image: emoji and :thinking: emoji', emojis)
|
|
||||||
expect(result).to.include(thinkHtml)
|
|
||||||
expect(result).to.include(imageHtml)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('handles consecutive emojis correctly', () => {
|
|
||||||
const result = addEmojis('Lelel emoji spam :thinking::thinking::thinking::thinking:', emojis)
|
|
||||||
expect(result).to.include(thinkHtml + thinkHtml + thinkHtml + thinkHtml)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Doesn\'t replace nonexistent emojis', () => {
|
|
||||||
const result = addEmojis('Admin add the :tenshi: emoji', emojis)
|
|
||||||
expect(result).to.equal('Admin add the :tenshi: emoji')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Doesn\'t blow up on regex special characters', () => {
|
|
||||||
const emojis = makeMockEmojiMasto([{
|
|
||||||
shortcode: 'c++'
|
|
||||||
}, {
|
|
||||||
shortcode: '[a-z] {|}*'
|
|
||||||
}])
|
|
||||||
const result = addEmojis('This post has :c++: emoji and :[a-z] {|}*: emoji', emojis)
|
|
||||||
expect(result).to.include('title=\':c++:\'')
|
|
||||||
expect(result).to.include('title=\':[a-z] {|}*:\'')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Link header pagination', () => {
|
describe('Link header pagination', () => {
|
||||||
it('Parses min and max ids as integers', () => {
|
it('Parses min and max ids as integers', () => {
|
||||||
const linkHeader = '<https://example.com/api/v1/notifications?max_id=861676>; rel="next", <https://example.com/api/v1/notifications?min_id=861741>; rel="prev"'
|
const linkHeader = '<https://example.com/api/v1/notifications?max_id=861676>; rel="next", <https://example.com/api/v1/notifications?min_id=861741>; rel="prev"'
|
||||||
|
|
Loading…
Reference in a new issue