-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (33 loc) · 1.11 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
30
31
32
33
34
35
36
37
/**
* @format
*/
import {AppRegistry} from 'react-native';
import App from './src/App';
import {name as appName} from './app.json';
import notifee, {EventType} from '@notifee/react-native';
import messaging from '@react-native-firebase/messaging';
import {displayNotification} from './src/features/chat/services/notifee';
import './src/features/chat/services/notifeeOnBackgroundEvent';
async function onMessageRecieved(message) {
try {
if (message.data.notifee) {
const parsedNotifee = JSON.parse(message.data.notifee);
const data = parsedNotifee.data;
if (parsedNotifee.id == 'chat-message') {
displayNotification({
sender_name: data.sender_name,
sender_uid: data.sender_uid,
sender_pfp: data.sender_pfp,
message: data.message,
chatId: data.chatId,
sender_fcm: data.sender_fcm,
});
}
}
} catch (error) {
console.log('Error FCM Notification:', error);
}
}
messaging().onMessage(onMessageRecieved);
messaging().setBackgroundMessageHandler(onMessageRecieved);
AppRegistry.registerComponent(appName, () => App);