-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (26 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* @format
*/
import { AppRegistry, Linking } from 'react-native';
import App from './src';
import { name as appName } from './app.json';
import messaging from '@react-native-firebase/messaging'
import { onDisplayNotification } from './src/common/utils/firebaseUtils';
import notifee, { EventType } from '@notifee/react-native';
import { insertPublicationDateItemToDB } from './src/database/services/publicationService';
messaging().setBackgroundMessageHandler(async remoteMessage => {
const messageData = JSON.parse(JSON.stringify(remoteMessage));
// notifee.deleteChannel('push_channel');
onDisplayNotification(messageData);
});
notifee.onBackgroundEvent(async ({ type, detail }) => {
const { notification, pressAction } = detail;
const { slug, gid, name } = detail?.notification?.data;
if (type === EventType.PRESS) {
const date = new Date().toISOString().slice(0, 10);
await insertPublicationDateItemToDB(slug, gid, date);
Linking.openURL(`ranenetwork://myWallTab/articleListPage/${name}/${slug}/${gid}`);
await notifee.cancelNotification(notification.id);
}
});
AppRegistry.registerComponent(appName, () => App);