2018-02-27 23:18:07 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { cacheFirstUpdateAfter } from '../_utils/sync'
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-16 20:56:21 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  getCustomEmoji as getCustomEmojiFromDatabase,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  setCustomEmoji as setCustomEmojiInDatabase
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								} from '../_database/meta'
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-27 23:18:07 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { getCustomEmoji } from '../_api/emoji'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { store } from '../_store/store'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export async function updateCustomEmojiForInstance (instanceName) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  await cacheFirstUpdateAfter(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    () => getCustomEmoji(instanceName),
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-16 20:56:21 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    () => getCustomEmojiFromDatabase(instanceName),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    emoji => setCustomEmojiInDatabase(instanceName, emoji),
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-27 23:18:07 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    emoji => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-19 09:37:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      let { customEmoji } = store.get()
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-27 23:18:07 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      customEmoji[instanceName] = emoji
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      store.set({customEmoji: customEmoji})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-03 14:51:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export function insertEmoji (realm, emoji) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-19 09:37:05 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  let { composeSelectionStart } = store.get()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  let idx = composeSelectionStart || 0
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-17 18:38:36 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  let oldText = store.getComposeData(realm, 'text') || ''
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  let pre = oldText.substring(0, idx)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  let post = oldText.substring(idx)
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-28 18:45:29 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  let newText = `${pre}:${emoji.shortcode}: ${post}`
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-03 14:51:48 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  store.setComposeData(realm, {text: newText})
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-27 23:18:07 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |