-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added a utility function for displaying notifications using Notifee to streamline notification handling. - Removed the `channelInboxNotificationAcknowledgement` object state from `homeSlice` to simplify state management
- Loading branch information
1 parent
00c35dc
commit d0346a8
Showing
6 changed files
with
112 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type NotificationTypes = | ||
| 'PUSH_NOTIFICATION_CHANNEL' | ||
| 'PUSH_NOTIFICATION_CHAT'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {Notification} from '@notifee/react-native'; | ||
import {FirebaseMessagingTypes} from '@react-native-firebase/messaging'; | ||
import Globals from 'src/Globals'; | ||
|
||
import {NotificationTypes} from './helpers.types'; | ||
|
||
export const getNotifeeConfig = ( | ||
type: NotificationTypes, | ||
remoteMessage: FirebaseMessagingTypes.RemoteMessage, | ||
): Notification => { | ||
const parsedDetails = remoteMessage.data?.details | ||
? JSON.parse(remoteMessage.data?.details as string) | ||
: {}; | ||
if (type === 'PUSH_NOTIFICATION_CHANNEL') { | ||
const largeIcon = parsedDetails?.info?.icon ?? 'ic_launcher_round'; | ||
return { | ||
id: remoteMessage.messageId, | ||
title: remoteMessage.notification?.title, | ||
body: remoteMessage.notification?.body, | ||
ios: { | ||
sound: 'default', | ||
foregroundPresentationOptions: { | ||
banner: true, | ||
list: true, | ||
badge: true, | ||
sound: true, | ||
}, | ||
}, | ||
android: { | ||
channelId: 'default', | ||
largeIcon, | ||
smallIcon: | ||
remoteMessage.notification?.android?.smallIcon ?? 'ic_notification', | ||
color: | ||
remoteMessage.notification?.android?.color ?? | ||
Globals.COLORS.IC_NOTIFICATION, | ||
circularLargeIcon: true, | ||
pressAction: { | ||
id: 'default', | ||
}, | ||
}, | ||
data: remoteMessage.data, | ||
}; | ||
} else { | ||
return {}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,36 @@ | ||
import {PayloadAction, createSlice} from '@reduxjs/toolkit'; | ||
|
||
export type ChannelInboxNotificationAcknowledgement = { | ||
notificationReceived?: boolean; | ||
notificationOpened?: boolean; | ||
}; | ||
|
||
type HomeInitialState = { | ||
channelInboxNotificationAcknowledgement: ChannelInboxNotificationAcknowledgement; | ||
notificationReceived: boolean; | ||
notificationOpened: boolean; | ||
}; | ||
|
||
type ReturnTypeHome = {home: HomeInitialState}; | ||
|
||
const initialState: HomeInitialState = { | ||
channelInboxNotificationAcknowledgement: { | ||
notificationReceived: false, | ||
notificationOpened: false, | ||
}, | ||
notificationReceived: false, | ||
notificationOpened: false, | ||
}; | ||
|
||
const homeSlice = createSlice({ | ||
name: 'home', | ||
initialState, | ||
reducers: { | ||
updateInboxNotificationAcknowledgement: ( | ||
state, | ||
action: PayloadAction<ChannelInboxNotificationAcknowledgement>, | ||
) => { | ||
state.channelInboxNotificationAcknowledgement = { | ||
...state.channelInboxNotificationAcknowledgement, | ||
...action.payload, | ||
}; | ||
updateNotificationReceived: (state, action: PayloadAction<boolean>) => { | ||
state.notificationReceived = action.payload; | ||
}, | ||
updateNotificationOpened: (state, action: PayloadAction<boolean>) => { | ||
state.notificationOpened = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const {updateInboxNotificationAcknowledgement} = homeSlice.actions; | ||
export const {updateNotificationReceived, updateNotificationOpened} = | ||
homeSlice.actions; | ||
|
||
export const selectInboxNotificationAcknowledgement = (state: ReturnTypeHome) => | ||
state.home.channelInboxNotificationAcknowledgement; | ||
export const selectNotificationReceived = (state: ReturnTypeHome) => | ||
state.home.notificationReceived; | ||
export const selectNotificationOpened = (state: ReturnTypeHome) => | ||
state.home.notificationOpened; | ||
|
||
export default homeSlice.reducer; |