pinafore/routes/_actions/emoji.js

30 lines
984 B
JavaScript
Raw Normal View History

2018-02-28 07:18:07 +00:00
import { cacheFirstUpdateAfter } from '../_utils/sync'
import { database } from '../_database/database'
import { getCustomEmoji } from '../_api/emoji'
import { store } from '../_store/store'
2018-03-01 02:45:29 +00:00
import { substring } from 'stringz'
2018-02-28 07:18:07 +00:00
export async function updateCustomEmojiForInstance (instanceName) {
await cacheFirstUpdateAfter(
() => getCustomEmoji(instanceName),
() => database.getCustomEmoji(instanceName),
emoji => database.setCustomEmoji(instanceName, emoji),
emoji => {
let customEmoji = store.get('customEmoji')
customEmoji[instanceName] = emoji
store.set({customEmoji: customEmoji})
}
)
}
export function insertEmoji (emoji) {
2018-03-01 02:45:29 +00:00
let idx = store.get('composeSelectionStart') || 0
2018-03-01 05:03:21 +00:00
let oldText = store.get('rawComposeText') || ''
let pre = oldText ? substring(oldText, 0, idx) : ''
let post = oldText ? substring(oldText, idx) : ''
2018-03-01 02:45:29 +00:00
let newText = `${pre}:${emoji.shortcode}: ${post}`
store.set({
rawComposeText: newText
})
2018-02-28 07:18:07 +00:00
}