Skip to content

Commit 8ac20f8

Browse files
committed
fix: ignore background notification if it already exists
1 parent 057e5d2 commit 8ac20f8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

examples/SampleApp/src/hooks/useChatClient.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { USER_TOKENS, USERS } from '../ChatUsers';
77
import AsyncStore from '../utils/AsyncStore';
88

99
import type { LoginConfig, StreamChatGenerics } from '../types';
10-
import { PermissionsAndroid, Platform } from 'react-native';
10+
import { Alert, PermissionsAndroid, Platform } from 'react-native';
1111

1212
const messaging = getMessaging();
1313

@@ -21,6 +21,7 @@ const requestNotificationPermission = async () => {
2121
};
2222

2323
messaging.setBackgroundMessageHandler(async (remoteMessage) => {
24+
Alert.alert(`NEW REMOTE MESSAGE: ${remoteMessage.messageId}`);
2425
const messageId = remoteMessage.data?.id as string;
2526
if (!messageId) {
2627
return;
@@ -50,7 +51,7 @@ messaging.setBackgroundMessageHandler(async (remoteMessage) => {
5051
name: 'Chat Messages',
5152
});
5253

53-
if (message.message.user?.name && message.message.text) {
54+
if (message.message.user?.name && message.message.text && !remoteMessage.notification) {
5455
const { stream, ...rest } = remoteMessage.data ?? {};
5556
const data = {
5657
...rest,
@@ -63,9 +64,9 @@ messaging.setBackgroundMessageHandler(async (remoteMessage) => {
6364
id: 'default',
6465
},
6566
},
67+
title: 'Background: New message from ' + message.message.user.name,
6668
body: message.message.text,
6769
data,
68-
title: 'New message from ' + message.message.user.name,
6970
});
7071
}
7172
});
@@ -161,7 +162,7 @@ export const useChatClient = () => {
161162
},
162163
body: message.message.text,
163164
data,
164-
title: 'New message from ' + message.message.user.name,
165+
title: 'Foreground: New message from ' + message.message.user.name,
165166
});
166167
}
167168
});

0 commit comments

Comments
 (0)