2018-04-24 19:34:03 +00:00
|
|
|
import { InteractionManager } from 'react-native';
|
2018-05-18 17:55:08 +00:00
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
import reduxStore from '../createStore';
|
|
|
|
// import { get } from './helpers/rest';
|
|
|
|
|
|
|
|
import database from '../realm';
|
|
|
|
import * as actions from '../../actions';
|
2018-05-18 17:55:08 +00:00
|
|
|
import log from '../../utils/log';
|
2018-04-24 19:34:03 +00:00
|
|
|
|
|
|
|
const getLastMessage = () => {
|
|
|
|
const setting = database.objects('customEmojis').sorted('_updatedAt', true)[0];
|
|
|
|
return setting && setting._updatedAt;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default async function() {
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
|
|
|
const lastMessage = getLastMessage();
|
|
|
|
let emojis = await this.ddp.call('listEmojiCustom');
|
|
|
|
emojis = emojis.filter(emoji => !lastMessage || emoji._updatedAt > lastMessage);
|
|
|
|
emojis = this._prepareEmojis(emojis);
|
|
|
|
InteractionManager.runAfterInteractions(() => database.write(() => {
|
|
|
|
emojis.forEach(emoji => database.create('customEmojis', emoji, true));
|
|
|
|
}));
|
|
|
|
reduxStore.dispatch(actions.setCustomEmojis(this.parseEmojis(emojis)));
|
|
|
|
} catch (e) {
|
|
|
|
log('getCustomEmojis', e);
|
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|