2018-04-24 19:34:03 +00:00
|
|
|
import { InteractionManager } from 'react-native';
|
2018-10-15 20:22:42 +00:00
|
|
|
import * as SDK from '@rocket.chat/sdk';
|
2018-05-18 17:55:08 +00:00
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
import reduxStore from '../createStore';
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2018-10-15 20:22:42 +00:00
|
|
|
// TODO: fix api (get emojis by date/version....)
|
2018-04-24 19:34:03 +00:00
|
|
|
export default async function() {
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
|
|
|
const lastMessage = getLastMessage();
|
2018-12-21 10:55:35 +00:00
|
|
|
// RC 0.61.0
|
2018-12-05 20:52:08 +00:00
|
|
|
const result = await SDK.api.get('emoji-custom');
|
|
|
|
let { emojis } = result;
|
2018-05-18 17:55:08 +00:00
|
|
|
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
|
|
|
}
|