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

Commit

Permalink
Only show one avatar if a block of messages in a row (#985)
Browse files Browse the repository at this point in the history
* removes old migration field

* just stacks message type entries from the same user

* fix avatar
  • Loading branch information
andrewxhill authored Mar 25, 2019
1 parent 9eca1e5 commit 3bfda29
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
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
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 3bfda29

Please sign in to comment.