Skip to content

Commit c3b747f

Browse files
committed
feat: add delivery receipt support inside push notification
1 parent d03c905 commit c3b747f

File tree

1 file changed

+1
-35
lines changed

1 file changed

+1
-35
lines changed

examples/SampleApp/src/hooks/useChatClient.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { useEffect, useRef, useState } from 'react';
2-
import { StreamChat, PushProvider, DeliveredMessageConfirmation } from 'stream-chat';
2+
import { StreamChat, PushProvider } from 'stream-chat';
33
import {
44
getMessaging,
55
AuthorizationStatus,
6-
setBackgroundMessageHandler,
76
FirebaseMessagingTypes,
87
} from '@react-native-firebase/messaging';
98
import notifee from '@notifee/react-native';
@@ -13,7 +12,6 @@ import AsyncStore from '../utils/AsyncStore';
1312

1413
import type { LoginConfig } from '../types';
1514
import { PermissionsAndroid, Platform } from 'react-native';
16-
import AsyncStorage from '@react-native-async-storage/async-storage';
1715

1816
const 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.
7743
const requestNotificationPermission = async () => {
7844
const authStatus = await messaging.requestPermission();

0 commit comments

Comments
 (0)