aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-04-23 16:36:14 -0400
committerGitHub <noreply@github.com>2021-04-23 16:36:14 -0400
commitfc6e1452bb615e6d2cdf9a3cf812931aa34054e7 (patch)
treee90368915c33d1b6d922a7536b16673d2e3ff5eb /src
parent5acc51f2d74ee536aeb4d7dcf94aba4ab63b4ed7 (diff)
parent77082b5cd9c095af6fc289ed24b284c4b738a59d (diff)
Merge pull request #385 from IvanIFChen/tma813-chat-push-notification
[TMA-813] Chat push notification
Diffstat (limited to 'src')
-rw-r--r--src/routes/Routes.tsx4
-rw-r--r--src/services/FCMService.ts8
2 files changed, 8 insertions, 4 deletions
diff --git a/src/routes/Routes.tsx b/src/routes/Routes.tsx
index 6fc766ab..384021bc 100644
--- a/src/routes/Routes.tsx
+++ b/src/routes/Routes.tsx
@@ -52,9 +52,9 @@ const Routes: React.FC = () => {
useEffect(() => {
if (userId) {
fcmService.setUpPushNotifications();
- fcmService.sendFcmTokenToServer();
+ fcmService.sendFcmTokenToServer(chatClient);
}
- }, []);
+ });
useEffect(() => {
if (loggedInUserId) {
diff --git a/src/services/FCMService.ts b/src/services/FCMService.ts
index 84f30f09..711483ec 100644
--- a/src/services/FCMService.ts
+++ b/src/services/FCMService.ts
@@ -2,8 +2,10 @@ import AsyncStorage from '@react-native-community/async-storage';
import messaging from '@react-native-firebase/messaging';
import {Platform} from 'react-native';
import {getDeviceId, getDeviceName} from 'react-native-device-info';
+import {StreamChat} from 'stream-chat';
import {FCM_ENDPOINT} from '../constants';
import * as RootNavigation from '../RootNavigation';
+
class FCMService {
setUpPushNotifications = () => {
// Requesting user to permit notifications
@@ -78,10 +80,13 @@ class FCMService {
return '';
};
- sendFcmTokenToServer = async () => {
+ sendFcmTokenToServer = async (chatClient: StreamChat) => {
const registration_id: string | null = await AsyncStorage.getItem(
'@fcmToken',
);
+ if (registration_id !== null) {
+ chatClient.addDevice(registration_id, 'firebase');
+ }
const device_id = getDeviceId();
const type = Platform.OS;
let active: boolean = false;
@@ -117,7 +122,6 @@ class FCMService {
console.log('Successfully stored device token!');
} else {
console.log('Failed to store device token!');
- console.log(response);
}
}
};