|
|
|
|
|
import * as React from 'react'; |
|
|
import { timeDifference } from 'shared/time-difference'; |
|
|
import { renderAvatars } from './avatars'; |
|
|
import type { GetDirectMessageThreadType } from 'shared/graphql/queries/directMessageThread/getDirectMessageThread'; |
|
|
import { |
|
|
Wrapper, |
|
|
WrapperLink, |
|
|
Row, |
|
|
Meta, |
|
|
MessageGroupTextContainer, |
|
|
MessageGroupByline, |
|
|
Usernames, |
|
|
Timestamp, |
|
|
} from './style'; |
|
|
|
|
|
type Props = { |
|
|
active: boolean, |
|
|
currentUser: Object, |
|
|
thread: GetDirectMessageThreadType, |
|
|
}; |
|
|
|
|
|
class ListCardItemDirectMessageThread extends React.Component<Props> { |
|
|
render() { |
|
|
const { thread, currentUser, active } = this.props; |
|
|
|
|
|
|
|
|
const timestamp = new Date(thread.threadLastActive).getTime(); |
|
|
|
|
|
|
|
|
const threadTimeDifference = timeDifference(Date.now(), timestamp); |
|
|
|
|
|
|
|
|
const participants = thread.participants.filter( |
|
|
user => user.userId !== currentUser.id |
|
|
); |
|
|
|
|
|
let participantsArray = |
|
|
participants.length > 1 |
|
|
? participants |
|
|
.map(user => user.name) |
|
|
.join(', ') |
|
|
.replace(/,(?!.*,)/gim, ' and') |
|
|
: participants[0].name; |
|
|
|
|
|
const avatars = renderAvatars(participants); |
|
|
|
|
|
return ( |
|
|
<Wrapper active={active}> |
|
|
<WrapperLink to={`/messages/${thread.id}`}> |
|
|
<Row> |
|
|
{avatars} |
|
|
<MessageGroupTextContainer> |
|
|
<MessageGroupByline> |
|
|
<Usernames> |
|
|
<p>{participantsArray}</p> |
|
|
</Usernames> |
|
|
<Timestamp>{threadTimeDifference}</Timestamp> |
|
|
</MessageGroupByline> |
|
|
<Meta nowrap>{thread.snippet}</Meta> |
|
|
</MessageGroupTextContainer> |
|
|
</Row> |
|
|
</WrapperLink> |
|
|
</Wrapper> |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
export default ListCardItemDirectMessageThread; |
|
|
|