Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Bypass the notification lookup stuff if the userinfo payload exists (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewxhill authored Mar 29, 2019
1 parent ed5ea0e commit f08bc93
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion App/Redux/NotificationsRedux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
Notification,
InviteReceivedNotification
} from '../Models/Notifications'
import { PushNotification } from 'react-native-push-notification'
import { RootState } from './Types'
import { PushNotification } from '../Services/EventHandlers/NotificationEventHandler'

const actions = {
readAllNotificationsRequest: createAction('CLEAR_ALL_NOTIFICATIONS_REQUEST', (resolve) => {
Expand Down
25 changes: 23 additions & 2 deletions App/Services/EventHandlers/NotificationEventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import { Store } from 'redux'
import { PushNotificationIOS, Platform } from 'react-native'
import RNPushNotification, { PushNotification } from 'react-native-push-notification'
import RNPushNotification from 'react-native-push-notification'

import { RootState } from '../../Redux/Types'
import NotificationsActions from '../../Redux/NotificationsRedux'
import { Notification } from '../../Models/Notifications'

export interface UserInfo {
notification: Notification
}

export interface PushNotification {
foreground: boolean
userInteraction: boolean
message: string|object
data: object
badge: number
alert: object
sound: string
userInfo?: UserInfo
finish: (fetchResult: string) => void
}

export default class NotificationEventHandler {
store: Store<RootState>
Expand All @@ -15,7 +32,11 @@ export default class NotificationEventHandler {

onNotification (notification: PushNotification) {
if (notification.userInteraction) {
this.store.dispatch(NotificationsActions.notificationEngagement(notification))
if (notification.userInfo && notification.userInfo.notification) {
this.store.dispatch(NotificationsActions.notificationSuccess(notification.userInfo.notification))
} else {
this.store.dispatch(NotificationsActions.notificationEngagement(notification))
}
}
if (notification.finish && Platform.OS === 'ios') {
notification.finish(PushNotificationIOS.FetchResult.NoData)
Expand Down

0 comments on commit f08bc93

Please sign in to comment.