This repository was archived by the owner on Oct 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Mobile direct messages view #3132
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d134db3
WIP: Mobile DM view
mxstbr 6d8c126
Render DM thread items
mxstbr 1b2d900
Add DM thread screen, render DM thread messages
mxstbr adef0dc
Move timeDifference util to shared
mxstbr e85eb3f
First styling of direct message threads list
mxstbr 197da94
Send direct messages from mobile
mxstbr f8dd41a
Furhter style on dm thread list and individual dm thread
mxstbr be5e34a
Switch mobile <Messages> to use <InfiniteList>
mxstbr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // @flow | ||
| import styled from 'styled-components/native'; | ||
|
|
||
| export default styled.View` | ||
| flex-direction: column; | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // @flow | ||
| import styled from 'styled-components/native'; | ||
|
|
||
| export default styled.View` | ||
| flex-direction: row; | ||
| `; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
mobile/views/DirectMessageThread/components/DirectMessageThread.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // @flow | ||
| import React, { Fragment } from 'react'; | ||
| import { View } from 'react-native'; | ||
| import compose from 'recompose/compose'; | ||
| import { Query } from 'react-apollo'; | ||
| import Text from '../../../components/Text'; | ||
| import ChatInput from '../../../components/ChatInput'; | ||
| import Messages from '../../../components/Messages'; | ||
| import Avatar from '../../../components/Avatar'; | ||
| import Column from '../../../components/Flex/Column'; | ||
| import Row from '../../../components/Flex/Row'; | ||
| import ViewNetworkHandler, { | ||
| type ViewNetworkHandlerProps, | ||
| } from '../../../components/ViewNetworkHandler'; | ||
|
|
||
| import sentencify from '../../../../shared/sentencify'; | ||
| import getDirectMessageThread, { | ||
| type GetDirectMessageThreadType, | ||
| } from '../../../../shared/graphql/queries/directMessageThread/getDirectMessageThread'; | ||
| import getDirectMessageThreadMessageConnection from '../../../../shared/graphql/queries/directMessageThread/getDirectMessageThreadMessageConnection'; | ||
| import type { GetUserType } from '../../../../shared/graphql/queries/user/getUser'; | ||
| import sendDirectMessage from '../../../../shared/graphql/mutations/message/sendDirectMessage'; | ||
|
|
||
| import type { DirectMessageThreadInfoType } from '../../../../shared/graphql/fragments/directMessageThread/directMessageThreadInfo'; | ||
|
|
||
| const DirectMessageThreadMessages = getDirectMessageThreadMessageConnection( | ||
| Messages | ||
| ); | ||
|
|
||
| type Props = { | ||
| ...$Exact<ViewNetworkHandlerProps>, | ||
| id: string, | ||
| sendDirectMessage: Function, | ||
| currentUser: GetUserType, | ||
| data: { | ||
| directMessageThread?: GetDirectMessageThreadType, | ||
| }, | ||
| }; | ||
|
|
||
| class DirectMessageThread extends React.Component<Props> { | ||
| sendMessage = text => { | ||
| if (!this.props.data.directMessageThread) return; | ||
| this.props.sendDirectMessage({ | ||
| threadId: this.props.data.directMessageThread.id, | ||
| threadType: 'directMessageThread', | ||
| messageType: 'text', | ||
| content: { | ||
| body: text, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| render() { | ||
| const { | ||
| isLoading, | ||
| hasError, | ||
| data: { directMessageThread }, | ||
| currentUser, | ||
| } = this.props; | ||
|
|
||
| if (directMessageThread) { | ||
| const participants = directMessageThread.participants.filter( | ||
| ({ userId }) => userId !== currentUser.id | ||
| ); | ||
| return ( | ||
| <View style={{ flex: 1 }}> | ||
| <DirectMessageThreadMessages | ||
| id={directMessageThread.id} | ||
| ListHeaderComponent={() => ( | ||
| <Column | ||
| style={{ | ||
| alignItems: 'center', | ||
| marginTop: 32, | ||
| marginBottom: 32, | ||
| marginRight: 8, | ||
| marginLeft: 8, | ||
| }} | ||
| > | ||
| <Row> | ||
| {participants.map(({ profilePhoto, id }) => ( | ||
| <Avatar | ||
| src={profilePhoto} | ||
| key={id} | ||
| size={60} | ||
| style={{ marginRight: 4, marginLeft: 4 }} | ||
| /> | ||
| ))} | ||
| </Row> | ||
| <Text type="title3" bold> | ||
| {sentencify(participants.map(({ name }) => name))} | ||
| </Text> | ||
| </Column> | ||
| )} | ||
| /> | ||
| <ChatInput onSubmit={this.sendMessage} /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| if (isLoading) return <Text>Loading...</Text>; | ||
| if (hasError) return <Text>Error :(</Text>; | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export default compose( | ||
| ViewNetworkHandler, | ||
| sendDirectMessage, | ||
| getDirectMessageThread | ||
| )(DirectMessageThread); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // @flow | ||
| import React from 'react'; | ||
| import compose from 'recompose/compose'; | ||
| import idx from 'idx'; | ||
| import Text from '../../components/Text'; | ||
| import ViewNetworkHandler, { | ||
| type ViewNetworkHandlerProps, | ||
| } from '../../components/ViewNetworkHandler'; | ||
|
|
||
| import { | ||
| getCurrentUser, | ||
| type GetUserType, | ||
| } from '../../../shared/graphql/queries/user/getUser'; | ||
|
|
||
| import DirectMessageThread from './components/DirectMessageThread'; | ||
| import { Wrapper } from './style'; | ||
|
|
||
| type Props = { | ||
| ...$Exact<ViewNetworkHandlerProps>, | ||
| data: { | ||
| user?: GetUserType, | ||
| }, | ||
| navigation?: { | ||
| state: { | ||
| params: { | ||
| id: string, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| class DirectMessageThreadView extends React.Component<Props> { | ||
| render() { | ||
| const id = idx(this.props, props => props.navigation.state.params.id); | ||
| if (!id) return <Text>Non-existant DM thread</Text>; | ||
| if (!this.props.data.user) return null; | ||
| return ( | ||
| <Wrapper> | ||
| {/* TODO(@mxstbr): We have to pass currentUser here because otherwise the sendDirectMessage mutation doesn't work. We should not make that a requirement. */} | ||
| <DirectMessageThread currentUser={this.props.data.user} id={id} /> | ||
| </Wrapper> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export default compose(ViewNetworkHandler, getCurrentUser)( | ||
| DirectMessageThreadView | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // @flow | ||
| import styled from 'styled-components/native'; | ||
|
|
||
| export const Wrapper = styled.View` | ||
| background-color: ${props => props.theme.bg.default}; | ||
| flex: 1; | ||
| `; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Row />and<Column />components