Skip to content

Commit

Permalink
fix(rn): conversation add new message
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Dec 11, 2018
1 parent 56a0f84 commit 5cefaee
Show file tree
Hide file tree
Showing 12 changed files with 2,229 additions and 2,711 deletions.
2 changes: 1 addition & 1 deletion client/react-native/Makefile
Expand Up @@ -188,7 +188,7 @@ webapp.list:
| sed 's/\(0\.\)\{3\}0:1\([0-9]\)\{3\}->1\([0-9]\)\{3\}\/tcp\, \(0\.\)\{3\}0://g' | sed 's/->.*$$//g'

webapp.logs:
@docker-compose logs -f $(SERV)
@docker-compose logs --tail=100 -f $(SERV)

webapp.open:
@GQL_PORTS=`docker ps -f name=react-native_core-service --format "{{.Ports}}" | \
Expand Down
4 changes: 4 additions & 0 deletions client/react-native/common/components/Screens/Chats/Detail.js
Expand Up @@ -27,6 +27,9 @@ class Message extends React.PureComponent {
await this.props.screenProps.context.mutations.eventSeen({
id: this.props.data.id,
})
await this.props.screenProps.context.mutations.conversationRead({
id: conversation.id,
})
}

async componentDidUpdate (prevProps) {
Expand Down Expand Up @@ -114,6 +117,7 @@ class Input extends PureComponent {
this.setState({ input: '' }, async () => {
try {
const conversation = this.props.navigation.getParam('conversation')
console.log('conversation', conversation)
await this.props.screenProps.context.mutations.conversationAddMessage({
conversation: {
id: conversation.id,
Expand Down
15 changes: 6 additions & 9 deletions client/react-native/common/components/Screens/Chats/List.js
Expand Up @@ -10,8 +10,8 @@ import { conversation as utils } from '../../../utils'

const Item = fragments.Conversation(({ data, navigation }) => {
const { id, updatedAt, readAt } = data
const isInvite = new Date(updatedAt).getTime() > 0
const isRead = new Date(readAt).getTime() > 0
const isInvite = new Date(updatedAt).getTime() > 0 && !isRead
return (
<Flex.Cols
align='center'
Expand All @@ -31,10 +31,10 @@ const Item = fragments.Conversation(({ data, navigation }) => {
{utils.getTitle(data)}
</Text>
<Text color={colors.subtleGrey} tiny middle left bold={!isRead}>
{isRead
? 'No new message'
: isInvite
? 'New conversation'
{isInvite
? 'New conversation'
: isRead
? 'No new message'
: 'You have a new message'}
</Text>
</Flex.Rows>
Expand Down Expand Up @@ -81,10 +81,7 @@ export default class ListScreen extends PureComponent {
variables={queries.ConversationList.defaultVariables}
fragment={fragments.ConversationList}
alias='ConversationList'
subscriptions={[
subscriptions.conversationInvite,
subscriptions.conversationNewMessage,
]}
subscriptions={[subscriptions.conversationInvite]}
renderItem={props => <Item {...props} navigation={navigation} />}
/>
</Screen>
Expand Down
Expand Up @@ -14,7 +14,6 @@ export default context => ({
'conversation:' + attributes.conversation.id
)
updater(store, attributes.conversation)
console.log('ConversationInvite', attributes)
await context.queries.Conversation.fetch({
id: attributes.conversation.id,
})
Expand Down
Expand Up @@ -8,12 +8,10 @@ export default context => ({
updater &&
(async (store, data) => {
if (data.EventStream.kind === 302) {
console.log('new message', data.EventStream)
const conversation = await context.queries.Conversation.fetch({
updater(store, data.EventStream)
await context.queries.Conversation.fetch({
id: data.EventStream.conversationId,
})
console.log('ConversationNewMessage: conversation:', conversation)
return updater(store, conversation)
}
}),
}),
Expand Down
11 changes: 9 additions & 2 deletions client/react-native/common/graphql/subscriptions/EventStream.js
@@ -1,4 +1,6 @@
import { graphql } from 'react-relay'

import { enums } from '..'
import { subscriber } from '../../relay'

const EventStream = graphql`
Expand Down Expand Up @@ -28,10 +30,15 @@ let _subscriber = null

export default context => {
if (subscriber === null || context !== _context) {
return (_subscriber = subscriber({
_subscriber = subscriber({
environment: context.environment,
subscription: EventStream,
}))
})
_subscriber.subscribe({
updater: (store, data) => {
console.log(enums.ValueBertyP2pKindInputKind[data.EventStream.kind])
},
})
}
return _subscriber
}
8 changes: 5 additions & 3 deletions client/react-native/common/relay/genericUpdater.js
Expand Up @@ -31,9 +31,9 @@ const deepFilterEqual = (a, b) => {
//
export default (fragment, alias, args) => {
return (store, data, deletion) => {
console.log(data, args)
const helper = new FragmentHelper(fragment)
const connectionHelper = helper.getConnection(alias)
console.log(alias, data, args)

const root = store.getRoot()

Expand All @@ -60,17 +60,19 @@ export default (fragment, alias, args) => {

const edges = connection.getLinkedRecords('edges')

const field = args.orderBy || args.sortBy || 'id'
let field = args.orderBy || args.sortBy || 'id'
field = data[field] ? field : Case.camel(field)

const node =
store.get(data.id) ||
store.create(data.id, connectionHelper.getEdgeNodeType())
node.setValue(data.id, 'id')
node.setValue(data[field], 'field')

const cursor =
field === 'id'
? atob(data.id).split(/:(.+)/)[1]
: data[Case.camel(field)] || data[field]
: atob(data.id).split(/:(.+)/)[1] + ':' + data[field]

if (
edges.length > 0 &&
Expand Down

0 comments on commit 5cefaee

Please sign in to comment.