2018-07-10 13:40:32 +00:00
|
|
|
import EJSON from 'ejson';
|
|
|
|
|
|
|
|
import PushNotification from './push';
|
2019-06-10 16:23:19 +00:00
|
|
|
import store from '../../lib/createStore';
|
|
|
|
import { deepLinkingOpen } from '../../actions/deepLinking';
|
2018-07-10 13:40:32 +00:00
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
export const onNotification = (notification) => {
|
2018-07-10 13:40:32 +00:00
|
|
|
if (notification) {
|
|
|
|
const data = notification.getData();
|
|
|
|
if (data) {
|
|
|
|
try {
|
|
|
|
const {
|
2020-07-30 17:25:52 +00:00
|
|
|
rid, name, sender, type, host, messageType
|
2018-07-10 13:40:32 +00:00
|
|
|
} = EJSON.parse(data.ejson);
|
|
|
|
|
|
|
|
const types = {
|
2020-02-07 13:24:16 +00:00
|
|
|
c: 'channel', d: 'direct', p: 'group', l: 'channels'
|
2018-07-10 13:40:32 +00:00
|
|
|
};
|
2020-02-07 13:24:16 +00:00
|
|
|
let roomName = type === 'd' ? sender.username : name;
|
|
|
|
if (type === 'l') {
|
|
|
|
roomName = sender.name;
|
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
|
|
|
|
const params = {
|
|
|
|
host,
|
|
|
|
rid,
|
2020-07-30 17:25:52 +00:00
|
|
|
path: `${ types[type] }/${ roomName }`,
|
|
|
|
isCall: messageType === 'jitsi_call_started'
|
2018-07-10 13:40:32 +00:00
|
|
|
};
|
|
|
|
store.dispatch(deepLinkingOpen(params));
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
export const getDeviceToken = () => PushNotification.getDeviceToken();
|
|
|
|
export const setBadgeCount = count => PushNotification.setBadgeCount(count);
|
|
|
|
export const initializePushNotifications = () => {
|
|
|
|
setBadgeCount();
|
|
|
|
return PushNotification.configure({
|
2018-07-10 13:40:32 +00:00
|
|
|
onNotification
|
|
|
|
});
|
|
|
|
};
|