Skip to content

Commit

Permalink
fix(mobile): fix contact request seen
Browse files Browse the repository at this point in the history
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
  • Loading branch information
sfroment committed Mar 13, 2019
1 parent 2c900e1 commit 94d4848
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
21 changes: 10 additions & 11 deletions client/react-native/common/components/Navigator/BottomNavigator.js
Expand Up @@ -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],
Expand All @@ -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,
Expand All @@ -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: [],
Expand Down
Expand Up @@ -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 },
})
Expand Down
9 changes: 4 additions & 5 deletions core/node/nodeapi.go
Expand Up @@ -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")
}

Expand Down

0 comments on commit 94d4848

Please sign in to comment.