Merge lp:~chipaca/ubuntu-push/shawn into lp:ubuntu-push

Proposed by John Lenton
Status: Rejected
Rejected by: John Lenton
Proposed branch: lp:~chipaca/ubuntu-push/shawn
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/client-session-getting-there
Diff against target: 96 lines (+30/-9)
2 files modified
client/session/session.go (+12/-3)
client/session/session_test.go (+18/-6)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/shawn
Reviewer Review Type Date Requested Status
John Lenton (community) Disapprove
Review via email: mp+204411@code.launchpad.net

Commit message

Gave ClientSession a Shown method that the client can use to indicate when a notification has been displayed (and made Client Session only update the levelmap on Shown).

Description of the change

Gave ClientSession a Shown method that the client can use to indicate when a notification has been displayed (and made Client Session only update the levelmap on Shown).

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) wrote :

After discussing this on IRC, I'll add Shown when I track shown vs. not shown in the session (the protocol-side ACK vs increasing levels is correct as it stands now).

review: Disapprove

Unmerged revisions

43. By John Lenton

Gave ClientSession a Shown method that the client can use to indicate when a notification has been displayed (and made Client Session only update the levelmap on Shown)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client/session/session.go'
--- client/session/session.go 2014-02-01 21:04:32 +0000
+++ client/session/session.go 2014-02-02 22:07:30 +0000
@@ -33,7 +33,8 @@
33var wireVersionBytes = []byte{protocol.ProtocolWireVersion}33var wireVersionBytes = []byte{protocol.ProtocolWireVersion}
3434
35type Notification struct {35type Notification struct {
36 // something something something36 channel string
37 level int64
37}38}
3839
39type serverMsg struct {40type serverMsg struct {
@@ -61,6 +62,8 @@
61 MsgCh chan *Notification62 MsgCh chan *Notification
62}63}
6364
65// NewSession creates and initializes a Ubuntu Push Notifications client
66// session.
64func NewSession(serverAddr string, pem []byte, exchangeTimeout time.Duration,67func NewSession(serverAddr string, pem []byte, exchangeTimeout time.Duration,
65 deviceId string, log logger.Logger) (*ClientSession, error) {68 deviceId string, log logger.Logger) (*ClientSession, error) {
66 sess := &ClientSession{69 sess := &ClientSession{
@@ -94,6 +97,7 @@
94 return nil97 return nil
95}98}
9699
100// Close disconnects the session and sets the Connection attribute to nil.
97func (sess *ClientSession) Close() {101func (sess *ClientSession) Close() {
98 if sess.Connection != nil {102 if sess.Connection != nil {
99 sess.Connection.Close()103 sess.Connection.Close()
@@ -125,8 +129,7 @@
125 bcast.ChanId, bcast.AppId, bcast.TopLevel, bcast.Payloads)129 bcast.ChanId, bcast.AppId, bcast.TopLevel, bcast.Payloads)
126 if bcast.ChanId == protocol.SystemChannelId {130 if bcast.ChanId == protocol.SystemChannelId {
127 // the system channel id, the only one we care about for now131 // the system channel id, the only one we care about for now
128 sess.Levels.Set(bcast.ChanId, bcast.TopLevel)132 sess.MsgCh <- &Notification{channel: bcast.ChanId, level: bcast.TopLevel}
129 sess.MsgCh <- &Notification{}
130 } else {133 } else {
131 sess.Log.Debugf("what is this weird channel, %#v?", bcast.ChanId)134 sess.Log.Debugf("what is this weird channel, %#v?", bcast.ChanId)
132 }135 }
@@ -224,3 +227,9 @@
224 }227 }
225 return sess.run(sess.Close, sess.connect, sess.start, sess.loop)228 return sess.run(sess.Close, sess.connect, sess.start, sess.loop)
226}229}
230
231// Shown should be called after the given notification was successfully
232// displayed to the user (otherwise you'll keep on getting it).
233func (sess *ClientSession) Shown(n *Notification) {
234 sess.Levels.Set(n.channel, n.level)
235}
227236
=== modified file 'client/session/session_test.go'
--- client/session/session_test.go 2014-02-01 21:04:32 +0000
+++ client/session/session_test.go 2014-02-02 22:07:30 +0000
@@ -309,9 +309,9 @@
309 s.upCh <- nil // ack ok309 s.upCh <- nil // ack ok
310 c.Check(<-s.errCh, Equals, nil)310 c.Check(<-s.errCh, Equals, nil)
311 c.Assert(len(s.sess.MsgCh), Equals, 1)311 c.Assert(len(s.sess.MsgCh), Equals, 1)
312 c.Check(<-s.sess.MsgCh, Equals, &Notification{})312 c.Check(<-s.sess.MsgCh, DeepEquals, &Notification{channel: "0", level: 2})
313 // and finally, the session keeps track of the levels313 // but the session doesn't update the levelmap yet
314 c.Check(s.sess.Levels.GetAll(), DeepEquals, map[string]int64{"0": 2})314 c.Check(s.sess.Levels.GetAll(), DeepEquals, map[string]int64{})
315}315}
316316
317func (s *msgSuite) TestHandleBroadcastBadAckWrite(c *C) {317func (s *msgSuite) TestHandleBroadcastBadAckWrite(c *C) {
@@ -688,9 +688,9 @@
688 c.Check(takeNext(downCh), Equals, protocol.AckMsg{"ack"})688 c.Check(takeNext(downCh), Equals, protocol.AckMsg{"ack"})
689 upCh <- nil689 upCh <- nil
690 // ...get bubbled up,690 // ...get bubbled up,
691 c.Check(<-sess.MsgCh, NotNil)691 c.Check(<-sess.MsgCh, DeepEquals, &Notification{channel: "0", level: 2})
692 // and their TopLevel remembered692 // (but their TopLevel remain unchanged)
693 c.Check(sess.Levels.GetAll(), DeepEquals, map[string]int64{"0": 2})693 c.Check(sess.Levels.GetAll(), DeepEquals, map[string]int64{})
694694
695 // and ping still work even after that.695 // and ping still work even after that.
696 c.Check(takeNext(downCh), Equals, "deadline 110ms")696 c.Check(takeNext(downCh), Equals, "deadline 110ms")
@@ -700,3 +700,15 @@
700 upCh <- failure700 upCh <- failure
701 c.Check(<-sess.ErrCh, Equals, failure)701 c.Check(<-sess.ErrCh, Equals, failure)
702}702}
703
704/****************************************************************
705 Shown() tests
706****************************************************************/
707
708func (cs *clientSessionSuite) TestAckWorks(c *C) {
709 sess, err := NewSession("", nil, 0, "wah", debuglog)
710 c.Assert(err, IsNil)
711 c.Check(sess.Levels.GetAll(), DeepEquals, map[string]int64{})
712 sess.Shown(&Notification{channel: "0", level: 42})
713 c.Check(sess.Levels.GetAll(), DeepEquals, map[string]int64{"0": 42})
714}

Subscribers

People subscribed via source and target branches