Skip to content

Commit

Permalink
Prompt if user had also participated in the meditation upon clicking …
Browse files Browse the repository at this point in the history
…notification
  • Loading branch information
henryw4k committed Aug 24, 2020
1 parent 7455e99 commit 8d6526a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/CountdownScreen/CountdownScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function CountdownScreen(props: Props) {
{
en: `Your friend ${displayName} just finished a ${countdownDuration} minute sit ${settingsString}🙂`,
},
{},
{ duration: countdownDuration, friendName: displayName, possibleGroupMed: true },
friendsToNotify,
)
}, 1000) // Run after 1sec delay to ensure we have a connection now
Expand Down
49 changes: 48 additions & 1 deletion src/onesignal-helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import PushNotificationIOS from '@react-native-community/push-notification-ios'
import firestore from '@react-native-firebase/firestore'
import { Platform } from 'react-native'
import { Alert } from 'react-native'
import OneSignal from 'react-native-onesignal'

import { setStatePayload } from './reducer'
import { Props, setStatePayload } from './reducer'

function init(setState: (payload: setStatePayload) => void) {
OneSignal.init('bcfb2833-18d0-4b12-8e53-647f1068c5a8', {
Expand Down Expand Up @@ -50,5 +53,49 @@ function onOpened(setState: (payload: setStatePayload) => void) {
if (body.includes('New friend request') || body.includes('Go send them a friend request')) {
setState({ expandFriendsSection: true, screen: 'SettingsScreen' })
}
const data = openResult.notification.payload?.additionalData // could be .data
if (data.hasOwnProperty('possibleGroupMed')) {
Alert.alert(
'Group Meditation?',
`Did you participated with ${data?.friendName} in their ${data?.duration} min session?`,
[
{
onPress: () => console.log('No Pressed'),
style: 'cancel',
text: 'No',
},
{
onPress: () => (props: Props) => addMinsToUser(props, data?.duration),
text: 'Yes',
},
],
)
}
}
}

async function addMinsToUser(props: any, duration: string) {
const { autoSyncCompletedSits, user } = props

console.log('...Attempting to autoSync completed sit')
if (!user) {
return console.log(' Not logged in.')
}

if (!autoSyncCompletedSits) {
return console.log(' AutoSync disabled.')
}

const durationInt = parseInt(duration, 10)
setTimeout(async () => {
await firestore()
.collection('sits')
.add({ durationInt, user_id: user.uid, user_phone: user.phoneNumber })
console.log('⬆️ Autosync complete.')
}, 500)

// Clear Notification Center reminders
if (Platform.OS === 'ios') {
PushNotificationIOS.removeAllDeliveredNotifications()
}
}

0 comments on commit 8d6526a

Please sign in to comment.