11import { useEffect , useRef , useState } from 'react' ;
2- import { StreamChat , PushProvider , DeliveredMessageConfirmation } from 'stream-chat' ;
2+ import { StreamChat , PushProvider } from 'stream-chat' ;
33import {
44 getMessaging ,
55 AuthorizationStatus ,
6- setBackgroundMessageHandler ,
76 FirebaseMessagingTypes ,
87} from '@react-native-firebase/messaging' ;
98import notifee from '@notifee/react-native' ;
@@ -13,7 +12,6 @@ import AsyncStore from '../utils/AsyncStore';
1312
1413import type { LoginConfig } from '../types' ;
1514import { PermissionsAndroid , Platform } from 'react-native' ;
16- import AsyncStorage from '@react-native-async-storage/async-storage' ;
1715
1816const messaging = getMessaging ( ) ;
1917
@@ -41,38 +39,6 @@ const displayNotification = async (
4139 }
4240} ;
4341
44- setBackgroundMessageHandler ( messaging , async ( remoteMessage ) => {
45- try {
46- const loginConfigStringified = await AsyncStorage . getItem ( '@stream-rn-sampleapp-login-config' ) ;
47- const loginConfig = JSON . parse ( loginConfigStringified ?? '' ) ;
48- const chatClient = StreamChat . getInstance ( loginConfig . apiKey ) ;
49- chatClient . _setToken ( { id : loginConfig . userId } , loginConfig . userToken ) ;
50-
51- const notification = remoteMessage . data ;
52-
53- const deliverMessageConfirmation = [
54- {
55- cid : notification ?. cid ,
56- id : notification ?. id ,
57- } ,
58- ] ;
59-
60- await chatClient ?. markChannelsDelivered ( {
61- latest_delivered_messages : deliverMessageConfirmation as DeliveredMessageConfirmation [ ] ,
62- } ) ;
63-
64- // create the android channel to send the notification to
65- const channelId = await notifee . createChannel ( {
66- id : 'chat-messages' ,
67- name : 'Chat Messages' ,
68- } ) ;
69- // display the notification
70- await displayNotification ( remoteMessage , channelId ) ;
71- } catch ( error ) {
72- console . error ( error ) ;
73- }
74- } ) ;
75-
7642// Request Push Notification permission from device.
7743const requestNotificationPermission = async ( ) => {
7844 const authStatus = await messaging . requestPermission ( ) ;
0 commit comments