fix: remove tokens from exposed emoji object
This commit is contained in:
parent
2c27795f99
commit
6cfc728ecf
|
@ -17,6 +17,7 @@ import {
|
|||
import { log } from '../shared/log'
|
||||
import { getETag, getETagAndData } from './utils/ajax'
|
||||
import { customEmojiIndex } from './customEmojiIndex'
|
||||
import { cleanEmoji } from './utils/cleanEmoji'
|
||||
|
||||
async function checkForUpdates (db, dataSource) {
|
||||
// just do a simple HEAD request first to see if the eTags match
|
||||
|
@ -87,15 +88,14 @@ export default class Database {
|
|||
async getEmojiByGroup (group) {
|
||||
assertNumber(group)
|
||||
await this.ready()
|
||||
const emojis = await getEmojiByGroup(this._db, group)
|
||||
return uniqEmoji(emojis)
|
||||
return uniqEmoji(await getEmojiByGroup(this._db, group)).map(cleanEmoji)
|
||||
}
|
||||
|
||||
async getEmojiBySearchQuery (query) {
|
||||
assertNonEmptyString(query)
|
||||
await this.ready()
|
||||
const customs = this._custom.search(query)
|
||||
const natives = uniqEmoji(await getEmojiBySearchQuery(this._db, query))
|
||||
const natives = uniqEmoji(await getEmojiBySearchQuery(this._db, query)).map(cleanEmoji)
|
||||
return [
|
||||
...customs,
|
||||
...natives
|
||||
|
@ -109,7 +109,7 @@ export default class Database {
|
|||
if (custom) {
|
||||
return custom
|
||||
}
|
||||
return getEmojiByShortcode(this._db, shortcode)
|
||||
return cleanEmoji(await getEmojiByShortcode(this._db, shortcode))
|
||||
}
|
||||
|
||||
async getEmojiByUnicodeOrName (unicodeOrName) {
|
||||
|
@ -119,7 +119,7 @@ export default class Database {
|
|||
if (custom) {
|
||||
return custom
|
||||
}
|
||||
return getEmojiByUnicode(this._db, unicodeOrName)
|
||||
return cleanEmoji(await getEmojiByUnicode(this._db, unicodeOrName))
|
||||
}
|
||||
|
||||
async getPreferredSkinTone () {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// remove some internal implementation details, i.e. the "tokens" array on the emoji object
|
||||
export function cleanEmoji (emoji) {
|
||||
if (!emoji) {
|
||||
return emoji
|
||||
}
|
||||
const res = {}
|
||||
for (const [key, value] of Object.entries(emoji)) {
|
||||
if (key !== 'tokens') {
|
||||
res[key] = value
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
|
@ -10,6 +10,7 @@ describe('getEmojiByGroup', () => {
|
|||
expect((await db.getEmojiByGroup(1)).length).toBe(20)
|
||||
expect((await db.getEmojiByGroup(2)).length).toBe(9)
|
||||
expect((await db.getEmojiByGroup(3)).length).toBe(20)
|
||||
expect((await db.getEmojiByGroup(1))[0].tokens).toBeFalsy()
|
||||
|
||||
await db.delete()
|
||||
})
|
||||
|
|
|
@ -62,6 +62,7 @@ describe('getEmojiBySearchQuery', () => {
|
|||
expect(await search('face monk')).toStrictEqual([
|
||||
{ annotation: 'monkey face', order: 2657 }
|
||||
])
|
||||
expect((await search('face monk'))[0].tokens).toBeFalsy()
|
||||
expect(await search('monkey facee')).toStrictEqual([])
|
||||
expect(await search('monk face')).toStrictEqual([])
|
||||
await db.delete()
|
||||
|
|
|
@ -8,6 +8,7 @@ describe('getEmojiByShortcode', () => {
|
|||
test('basic test', async () => {
|
||||
const db = new Database({ dataSource: ALL_EMOJI })
|
||||
expect((await db.getEmojiByShortcode('monkey')).annotation).toEqual('monkey')
|
||||
expect((await db.getEmojiByShortcode('monkey')).tokens).toBeFalsy()
|
||||
expect((await db.getEmojiByShortcode('monkey_face')).annotation).toEqual('monkey face')
|
||||
expect((await db.getEmojiByShortcode('MONKEY')).annotation).toEqual('monkey')
|
||||
expect((await db.getEmojiByShortcode('MONKEY_FACE')).annotation).toEqual('monkey face')
|
||||
|
|
|
@ -22,6 +22,7 @@ describe('getEmojiByUnicode', () => {
|
|||
const db = new Database({ dataSource: EMOJI_WITH_PIRATES })
|
||||
|
||||
expect((await db.getEmojiByUnicodeOrName('😀')).annotation).toBe('grinning face')
|
||||
expect((await db.getEmojiByUnicodeOrName('😀')).tokens).toBeFalsy()
|
||||
expect((await db.getEmojiByUnicodeOrName(pirate.emoji)).annotation).toBe('pirate flag')
|
||||
expect((await db.getEmojiByUnicodeOrName(pirate.emoji.substring(0, 1)))).toBe(null)
|
||||
expect((await db.getEmojiByUnicodeOrName('smile'))).toBe(null)
|
||||
|
|
|
@ -162,7 +162,6 @@ describe('Picker tests', () => {
|
|||
order: 1,
|
||||
shortcodes: ['gleeful'],
|
||||
tags: ['face', 'grin'],
|
||||
tokens: [':d', 'face', 'gleeful', 'grin', 'grinning'],
|
||||
unicode: '😀',
|
||||
version: 1,
|
||||
emoticon: ':D'
|
||||
|
@ -188,7 +187,6 @@ describe('Picker tests', () => {
|
|||
order: 280,
|
||||
shortcodes: ['thumbsup', '+1', 'yes'],
|
||||
tags: ['+1', 'hand', 'thumb', 'up'],
|
||||
tokens: ['+1', 'hand', 'thumb', 'thumbs', 'thumbsup', 'up', 'yes'],
|
||||
unicode: '👍️',
|
||||
version: 0.6,
|
||||
skins: [
|
||||
|
@ -214,7 +212,6 @@ describe('Picker tests', () => {
|
|||
order: 1,
|
||||
shortcodes: ['gleeful'],
|
||||
tags: ['face', 'grin'],
|
||||
tokens: [':d', 'face', 'gleeful', 'grin', 'grinning'],
|
||||
unicode: '😀',
|
||||
version: 1,
|
||||
emoticon: ':D'
|
||||
|
@ -254,7 +251,6 @@ describe('Picker tests', () => {
|
|||
order: 2658,
|
||||
shortcodes: ['monkey'],
|
||||
tags: ['monkey'],
|
||||
tokens: ['monkey'],
|
||||
unicode: '🐒',
|
||||
version: 0.6
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue