Skip to content

Commit

Permalink
Merge pull request #664 from glouvigny/glouvigny/ui-notify-acked
Browse files Browse the repository at this point in the history
feat: send acked event to client (+ sent indicator on conversation view)
  • Loading branch information
glouvigny committed Nov 27, 2018
2 parents 760e3e6 + 2f73d99 commit 442b9fa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Platform, View } from 'react-native'
import React, { PureComponent } from 'react'

import { Pagination, RelayContext } from '../../../relay'
import { Text, Flex, Screen, Header } from '../../Library'
import { Text, Flex, Screen, Header, Icon } from '../../Library'
import { colors } from '../../../constants'
import { fragments } from '../../../graphql'
import { merge } from '../../../helpers'
Expand Down Expand Up @@ -53,6 +53,10 @@ const Message = fragments.Event(props => {
}}
>
{new Date(props.data.createdAt).toTimeString()}
{' '}
{isMyself
? <Icon name={props.data.ackedAt ? 'check-circle' : 'circle'} />
: null}
</Text>
</Flex.Rows>
)
Expand Down
15 changes: 13 additions & 2 deletions core/node/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,19 @@ func (n *Node) handleSenderAliasUpdate(ctx context.Context, input *p2p.Event) er
}

func (n *Node) handleAck(ctx context.Context, input *p2p.Event) error {
var ackedEvents []*p2p.Event
ackCount := 0
ackAttrs, err := input.GetAckAttrs()

if err != nil {
return errors.Wrap(err, "unable to unmarshal ack attrs")
}

if err = n.sql.
baseQuery := n.sql.
Model(&p2p.Event{}).
Where("id in (?)", ackAttrs.IDs).
Where("id in (?)", ackAttrs.IDs)

if err = baseQuery.
Count(&ackCount).
UpdateColumn("acked_at", time.Now().UTC()).
Error; err != nil {
Expand All @@ -203,10 +206,18 @@ func (n *Node) handleAck(ctx context.Context, input *p2p.Event) error {
return errors.Wrap(err, "no events to ack found")
}

if err = baseQuery.Find(&ackedEvents).Error; err != nil {
return errors.Wrap(err, "unable to fetch acked events")
}

if err := n.handleAckSenderAlias(ctx, ackAttrs); err != nil {
return errors.Wrap(err, "error while acking alias updates")
}

for _, ackedEvent := range ackedEvents {
n.clientEvents <- ackedEvent
}

return nil
}

Expand Down
22 changes: 11 additions & 11 deletions core/test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func TestWithEnqueuer(t *testing.T) {
So(err, ShouldBeNil)
So(res, ShouldResemble, &node.Void{})

So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{0, 0, 0, 0, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{0, 1, 0, 0, 0, 0})
// FIXME: check that event is acked in db

everythingWentFine()
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestWithEnqueuer(t *testing.T) {

time.Sleep(time.Second * 1)

So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{0, 0, 2, 2, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{0, 1, 2, 2, 0, 0})

everythingWentFine()
})
Expand All @@ -346,7 +346,7 @@ func TestWithEnqueuer(t *testing.T) {
So(err, ShouldBeNil)
So(res, ShouldResemble, &node.Void{})

So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{2, 3, 1, 2, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{2, 4, 1, 2, 0, 0})

everythingWentFine()
})
Expand All @@ -367,7 +367,7 @@ func TestWithEnqueuer(t *testing.T) {
So(event.Direction, ShouldEqual, p2p.Event_Incoming)
_, err = event.GetContactRequestAcceptedAttrs()
So(err, ShouldBeNil)
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{2, 0, 1, 2, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{2, 1, 1, 2, 0, 0})

everythingWentFine()
})
Expand All @@ -390,7 +390,7 @@ func TestWithEnqueuer(t *testing.T) {
So(err, ShouldBeNil)
So(res, ShouldResemble, &node.Void{})

So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{3, 2, 0, 2, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{3, 3, 0, 2, 0, 0})

everythingWentFine()
})
Expand All @@ -411,7 +411,7 @@ func TestWithEnqueuer(t *testing.T) {
So(err, ShouldBeNil)
So(attrs.Me.DisplayName, ShouldEqual, "Bob")
So(attrs.Me.DisplayStatus, ShouldBeEmpty)
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{3, 0, 0, 2, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{3, 1, 0, 2, 0, 0})

everythingWentFine()
})
Expand All @@ -436,7 +436,7 @@ func TestWithEnqueuer(t *testing.T) {
So(err, ShouldBeNil)
So(res, ShouldResemble, &node.Void{})

So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{2, 0, 1, 4, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{2, 1, 1, 4, 0, 0})

everythingWentFine()
})
Expand All @@ -459,7 +459,7 @@ func TestWithEnqueuer(t *testing.T) {
So(err, ShouldBeNil)
So(res, ShouldResemble, &node.Void{})

So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{1, 0, 1, 4, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{1, 1, 1, 5, 0, 0})

everythingWentFine()
})
Expand All @@ -482,7 +482,7 @@ func TestWithEnqueuer(t *testing.T) {
So(err, ShouldBeNil)
So(res, ShouldResemble, &node.Void{})

So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{0, 0, 1, 4, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{0, 1, 1, 6, 0, 0})

everythingWentFine()
})
Expand All @@ -504,7 +504,7 @@ func TestWithEnqueuer(t *testing.T) {
So(err, ShouldBeNil)
So(res, ShouldResemble, &node.Void{})

So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{0, 0, 0, 4, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{0, 2, 0, 6, 0, 0})

everythingWentFine()
})
Expand All @@ -528,7 +528,7 @@ func TestWithEnqueuer(t *testing.T) {
So(attrs.Me.Status, ShouldEqual, entity.Contact_Unknown)
So(attrs.Me.DisplayStatus, ShouldBeEmpty)
So(attrs.Me.Devices, ShouldBeNil)
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{0, 0, 0, 0, 0, 0})
So(nodeChansLens(alice, bob, eve), ShouldResemble, []int{0, 2, 0, 2, 0, 0})

everythingWentFine()
})
Expand Down

0 comments on commit 442b9fa

Please sign in to comment.