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

Commit

Permalink
Fixes Type.Message click from Notifications (#986)
Browse files Browse the repository at this point in the history
* removes old migration field

* adds notification prompt
  • Loading branch information
andrewxhill authored Mar 25, 2019
1 parent e9006e8 commit 9eca1e5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ RN_MAILCHIMP_API_URL="https://something.api.mailchimp.com"
RN_MAILCHIMP_API_KEY="a-key"
RN_MAILCHIMP_LIST_ID="a-list-id"
RN_MAILCHIMP_WAITLIST_ID="a-list-id"
RN_PEER_SWAP="https://<peer endpoint>"
RN_RELEASE_TYPE="dev"
RN_IOS_STORE_LINK="https://<ios store link>"
RN_ANDROID_STORE_LINK="https://<android store link>"
58 changes: 56 additions & 2 deletions App/Containers/Groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import React from 'react'
import {Dispatch} from 'redux'
import { NavigationScreenProps } from 'react-navigation'
import { connect } from 'react-redux'
import { FlatList, View, Text, TouchableOpacity } from 'react-native'
import { FlatList, View, Text, TouchableOpacity, Alert } from 'react-native'

import {RootAction, RootState} from '../Redux/Types'

import { getThreads } from '../Redux/PhotoViewingSelectors'
import { contactsSelectors } from '../features/contacts'
import UIActions from '../Redux/UIRedux'
import TextileEventsActions from '../Redux/TextileEventsRedux'
import PreferencesActions from '../Redux/PreferencesRedux'

import { pb } from '@textile/react-native-sdk'

Expand All @@ -29,11 +30,14 @@ interface GroupAuthors {

interface StateProps {
threads: ReadonlyArray<GroupAuthors>
showNotificationsPrompt: boolean
}

interface DispatchProps {
refreshMessages: () => void
navigateToThread: (id: string, name: string) => void
enableNotifications: () => void
completeNotifications: () => void
}

interface NavProps {
Expand Down Expand Up @@ -136,6 +140,13 @@ class Groups extends React.Component<Props, State> {
})
}

componentDidUpdate (prevProps, prevState) {
// ensure that it only gets called once by using the first update of the state or a new group add
if (this.props.threads.length && this.props.threads.length !== prevProps.threads.length && this.props.showNotificationsPrompt) {
this.notificationPrompt()
}
}

render () {
return (
<View style={styles.contentContainer} >
Expand All @@ -159,11 +170,40 @@ class Groups extends React.Component<Props, State> {
</View>
)
}

// Simple Alert based prompt to get Notification permissions
notificationPrompt () {
// never show it again
this.props.completeNotifications()
// give the user a prompt
Alert.alert(
'Notifications',
'Want to receive notifications when you receive new photos or invites?',
[
{
text: 'Yes please',
onPress: () => {
this.props.enableNotifications()
}
},
{ text: 'Not now', style: 'cancel' },
{
text: 'Show all options',
onPress: () => {
this.props.navigation.navigate('Settings')
}
}
],
{ cancelable: false }
)
}

}

const mapStateToProps = (state: RootState): StateProps => {
const ownAddress = state.account.address.value
const profile = state.account.profile.value
let memberCount = 0
const threads = getThreads(state, 'date')
.map((thread) => {
const selector = contactsSelectors.makeByThreadId(thread.id)
Expand All @@ -172,6 +212,8 @@ const mapStateToProps = (state: RootState): StateProps => {
members.unshift(profile)
}
const thumb = thread.photos.length ? thread.photos[0] : undefined
// just get a sense of how many group x members there are
memberCount += members.length
return {
id: thread.id,
name: thread.name,
Expand All @@ -181,8 +223,14 @@ const mapStateToProps = (state: RootState): StateProps => {
thumb
}
})

const showNotificationsPrompt = state.preferences.tourScreens.notifications &&
threads.length > 0 &&
memberCount > threads.length

return {
threads
threads,
showNotificationsPrompt
}
}

Expand All @@ -193,6 +241,12 @@ const mapDispatchToProps = (dispatch: Dispatch<RootAction>): DispatchProps => {
},
navigateToThread: (id: string, name: string) => {
dispatch(UIActions.navigateToThreadRequest(id, name))
},
enableNotifications: () => {
dispatch(PreferencesActions.toggleServicesRequest('notifications', true))
},
completeNotifications: () => {
dispatch(PreferencesActions.completeTourSuccess('notifications'))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions App/Sagas/NotificationsSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export function * notificationView (action: ActionType<typeof NotificationsActio
}
break
}
case pb.Notification.Type.MESSAGE_ADDED:
case pb.Notification.Type.PEER_JOINED:
case pb.Notification.Type.PEER_LEFT: {
const threadData: ThreadData | undefined = yield select(threadDataByThreadId, notification.threadId)
Expand Down

0 comments on commit 9eca1e5

Please sign in to comment.