From 94d4848061dd92d6ed120813b58523d8da96d598 Mon Sep 17 00:00:00 2001 From: Sacha Froment Date: Wed, 13 Mar 2019 14:36:50 +0100 Subject: [PATCH] fix(mobile): fix contact request seen Signed-off-by: Sacha Froment --- .../components/Navigator/BottomNavigator.js | 21 +++++++++---------- .../graphql/subscriptions/ContactRequest.js | 2 +- core/node/nodeapi.go | 9 ++++---- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/client/react-native/common/components/Navigator/BottomNavigator.js b/client/react-native/common/components/Navigator/BottomNavigator.js index 529a759d67..948a79703e 100644 --- a/client/react-native/common/components/Navigator/BottomNavigator.js +++ b/client/react-native/common/components/Navigator/BottomNavigator.js @@ -29,8 +29,8 @@ class TabBarIconBase extends Component { stored: [], queryList: queries.EventList.graphql, queryVariables: props.routeName === 'contacts' - ? merge([queries.EventList.defaultVariables, { filter: { kind: 201 }, onlyWithoutSeenAt: 1 }]) - : merge([queries.EventList.defaultVariables, { filter: { kind: 302 } }]), + ? merge([queries.EventList.defaultVariables, { filter: { kind: 201, direction: 1 }, onlyWithoutSeenAt: 1 }]) + : merge([queries.EventList.defaultVariables, { filter: { kind: 302, direction: 1 } }]), subscription: props.routeName === 'contacts' ? [subscriptions.contactRequest] : [subscriptions.message], @@ -49,18 +49,17 @@ class TabBarIconBase extends Component { } = props const { routeName } = this.props let { stored } = this.state + const idx = stored.indexOf(id) - if (stored.indexOf(id) === -1) { - if (routeName === 'chats' && new Date(seenAt).getTime() > 0) { - return null - } + if (idx === -1 && seenAt === null) { + console.log('props.data', props.data) this.setState({ stored: [ ...stored, id, ], }) - } else if (routeName === 'chats' && new Date(seenAt).getTime() > 0) { + } else if (idx !== -1 && routeName === 'chats' && new Date(seenAt).getTime() > 0) { stored.splice(stored.indexOf(id), 1) this.setState({ stored, @@ -70,13 +69,13 @@ class TabBarIconBase extends Component { return null } - contactSeen = () => { + contactSeen = async () => { if (this.state.stored.length > 0) { - this.state.stored.forEach((val) => { - this.props.context.mutations.eventSeen({ + await Promise.all(this.state.stored.map((val) => { + return this.props.context.mutations.eventSeen({ id: val, }) - }) + })) this.setState({ stored: [], diff --git a/client/react-native/common/graphql/subscriptions/ContactRequest.js b/client/react-native/common/graphql/subscriptions/ContactRequest.js index 660ef15f14..eb3aed7959 100644 --- a/client/react-native/common/graphql/subscriptions/ContactRequest.js +++ b/client/react-native/common/graphql/subscriptions/ContactRequest.js @@ -13,7 +13,7 @@ export default context => ({ if (data.EventStream.kind === 201) { const attributes = parseEmbedded(data.EventStream.attributes) const id = btoa('contact:' + attributes.me.id) - updater(store, { id }) + updater(store, data.EventStream) await context.queries.Contact.fetch({ filter: { id }, }) diff --git a/core/node/nodeapi.go b/core/node/nodeapi.go index 934e7ac0ef..525f874947 100644 --- a/core/node/nodeapi.go +++ b/core/node/nodeapi.go @@ -99,12 +99,11 @@ func (n *Node) EventSeen(ctx context.Context, input *entity.Event) (*entity.Even return event, nil } + seenAt := time.Now().UTC() + event.SeenAt = &seenAt + // then mark as seen - if err := sql. - Model(event). - Where(&entity.Event{ID: event.ID}). - UpdateColumn("seen_at", time.Now().UTC()). - First(event).Error; err != nil { + if err := sql.Save(event).Error; err != nil { return nil, errors.Wrap(err, "cannot set event as seen") }