pinafore/routes/_actions/emoji.js
greenkeeper[bot] 8dbc1b0503 Update standard to the latest version 🚀 (#519)
* chore(package): update standard to version 12.0.0

* package lock update

* fix eslint
2018-08-29 21:42:57 -07:00

28 lines
959 B
JavaScript

import { cacheFirstUpdateAfter } from '../_utils/sync'
import { database } from '../_database/database'
import { getCustomEmoji } from '../_api/emoji'
import { store } from '../_store/store'
export async function updateCustomEmojiForInstance (instanceName) {
await cacheFirstUpdateAfter(
() => getCustomEmoji(instanceName),
() => database.getCustomEmoji(instanceName),
emoji => database.setCustomEmoji(instanceName, emoji),
emoji => {
let { customEmoji } = store.get()
customEmoji[instanceName] = emoji
store.set({ customEmoji: customEmoji })
}
)
}
export function insertEmoji (realm, emoji) {
let { composeSelectionStart } = store.get()
let idx = composeSelectionStart || 0
let oldText = store.getComposeData(realm, 'text') || ''
let pre = oldText.substring(0, idx)
let post = oldText.substring(idx)
let newText = `${pre}:${emoji.shortcode}: ${post}`
store.setComposeData(realm, { text: newText })
}