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

Commit

Permalink
Merge branch 'master' into andrew/fix-inverted-flatlist
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewxhill authored Mar 25, 2019
2 parents dd4e749 + 3bfda29 commit b167292
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 11 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>"
16 changes: 10 additions & 6 deletions App/Components/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ export interface Props {
message?: string
time: string
containerStyle?: ViewStyle
isSameUser?: boolean
}

const Message = (props: Props) => {
const alignItems = props.message ? 'flex-start' : 'center'
return (
<View style={[CONTAINER(alignItems), props.containerStyle]}>
<Avatar style={AVATAR} target={props.avatar} />
<View style={[CONTAINER(alignItems), props.containerStyle, props.isSameUser && {paddingTop: 0}]}>
{props.isSameUser && <View style={AVATAR} />}
{!props.isSameUser && <Avatar style={AVATAR} target={props.avatar} />}
<View style={CONTENT}>
<View style={META}>
<Text style={USERNAME}>{props.username}</Text>
<Text style={TIME}>{props.time.toUpperCase()}</Text>
</View>
{!props.isSameUser &&
<View style={META}>
<Text style={USERNAME}>{props.username}</Text>
<Text style={TIME}>{props.time.toUpperCase()}</Text>
</View>
}
{props.message &&
<Text style={MESSAGE}>{props.message}</Text>
}
Expand Down
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
22 changes: 20 additions & 2 deletions App/screens/group/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import UIActions from '../../Redux/UIRedux'
import PhotoViewingActions from '../../Redux/PhotoViewingRedux'
import { CommentData } from '../../Components/comments'
import { color } from '../../styles'
import { pb } from '@textile/react-native-sdk'

const momentSpec: moment.CalendarSpec = {
sameDay: 'LT',
Expand Down Expand Up @@ -137,7 +138,21 @@ class Group extends Component<Props, State> {
)
}

renderRow = ({ item }: ListRenderItemInfo<Item>) => {
sameUserAgain = (user: pb.IUser, previous: Item): boolean => {
if (!previous || !previous.type) {
return false
}
switch (previous.type) {
case 'message': {
return user.address === previous.data.user.address
}
default: {
return false
}
}
}

renderRow = ({ item, index }: ListRenderItemInfo<Item>) => {
switch (item.type) {
case 'photo': {
const { user, caption, date, target, files, likes, comments, block } = item.data
Expand Down Expand Up @@ -181,13 +196,16 @@ class Group extends Component<Props, State> {
}
case 'message': {
const { user, body, date } = item.data
const isSameUser = this.sameUserAgain(user, this.props.items[(index + 1)])
const avatar = isSameUser ? undefined : user.avatar
return (
<Message
avatar={user.avatar}
avatar={avatar}
username={user.name || 'unknown'}
message={body}
// TODO: deal with pb Timestamp to JS Date!
time={moment(util.timestampToDate(date)).calendar(undefined, momentSpec)}
isSameUser={isSameUser}
/>
)
}
Expand Down

0 comments on commit b167292

Please sign in to comment.