2018-07-10 13:40:32 +00:00
|
|
|
import EJSON from 'ejson';
|
2021-08-20 00:01:17 +00:00
|
|
|
|
2019-06-10 16:23:19 +00:00
|
|
|
import store from '../../lib/createStore';
|
|
|
|
import { deepLinkingOpen } from '../../actions/deepLinking';
|
2020-08-24 12:24:10 +00:00
|
|
|
import { isFDroidBuild } from '../../constants/environment';
|
2021-08-20 00:01:17 +00:00
|
|
|
import PushNotification from './push';
|
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 {
|
2021-05-26 17:24:54 +00:00
|
|
|
rid, name, sender, type, host, messageType, messageId
|
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,
|
2021-05-26 17:24:54 +00:00
|
|
|
messageId,
|
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 = () => {
|
2020-08-24 12:24:10 +00:00
|
|
|
if (!isFDroidBuild) {
|
|
|
|
setBadgeCount();
|
|
|
|
return PushNotification.configure({
|
|
|
|
onNotification
|
|
|
|
});
|
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
};
|