pinafore/routes/_actions/emoji.js

28 lines
959 B
JavaScript
Raw Normal View History

2018-02-28 07:18:07 +00:00
import { cacheFirstUpdateAfter } from '../_utils/sync'
import { database } from '../_database/database'
2018-02-28 07:18:07 +00:00
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),
2018-02-28 07:18:07 +00:00
emoji => {
let { customEmoji } = store.get()
2018-02-28 07:18:07 +00:00
customEmoji[instanceName] = emoji
store.set({ customEmoji: customEmoji })
2018-02-28 07:18:07 +00:00
}
)
}
2018-03-03 22:51:48 +00:00
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)
2018-03-01 02:45:29 +00:00
let newText = `${pre}:${emoji.shortcode}: ${post}`
store.setComposeData(realm, { text: newText })
2018-02-28 07:18:07 +00:00
}