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
1=== modified file 'client/session/session.go'
2--- client/session/session.go 2014-02-01 21:04:32 +0000
3+++ client/session/session.go 2014-02-02 22:07:30 +0000
4@@ -33,7 +33,8 @@
5 var wireVersionBytes = []byte{protocol.ProtocolWireVersion}
6
7 type Notification struct {
8- // something something something
9+ channel string
10+ level int64
11 }
12
13 type serverMsg struct {
14@@ -61,6 +62,8 @@
15 MsgCh chan *Notification
16 }
17
18+// NewSession creates and initializes a Ubuntu Push Notifications client
19+// session.
20 func NewSession(serverAddr string, pem []byte, exchangeTimeout time.Duration,
21 deviceId string, log logger.Logger) (*ClientSession, error) {
22 sess := &ClientSession{
23@@ -94,6 +97,7 @@
24 return nil
25 }
26
27+// Close disconnects the session and sets the Connection attribute to nil.
28 func (sess *ClientSession) Close() {
29 if sess.Connection != nil {
30 sess.Connection.Close()
31@@ -125,8 +129,7 @@
32 bcast.ChanId, bcast.AppId, bcast.TopLevel, bcast.Payloads)
33 if bcast.ChanId == protocol.SystemChannelId {
34 // the system channel id, the only one we care about for now
35- sess.Levels.Set(bcast.ChanId, bcast.TopLevel)
36- sess.MsgCh <- &Notification{}
37+ sess.MsgCh <- &Notification{channel: bcast.ChanId, level: bcast.TopLevel}
38 } else {
39 sess.Log.Debugf("what is this weird channel, %#v?", bcast.ChanId)
40 }
41@@ -224,3 +227,9 @@
42 }
43 return sess.run(sess.Close, sess.connect, sess.start, sess.loop)
44 }
45+
46+// Shown should be called after the given notification was successfully
47+// displayed to the user (otherwise you'll keep on getting it).
48+func (sess *ClientSession) Shown(n *Notification) {
49+ sess.Levels.Set(n.channel, n.level)
50+}
51
52=== modified file 'client/session/session_test.go'
53--- client/session/session_test.go 2014-02-01 21:04:32 +0000
54+++ client/session/session_test.go 2014-02-02 22:07:30 +0000
55@@ -309,9 +309,9 @@
56 s.upCh <- nil // ack ok
57 c.Check(<-s.errCh, Equals, nil)
58 c.Assert(len(s.sess.MsgCh), Equals, 1)
59- c.Check(<-s.sess.MsgCh, Equals, &Notification{})
60- // and finally, the session keeps track of the levels
61- c.Check(s.sess.Levels.GetAll(), DeepEquals, map[string]int64{"0": 2})
62+ c.Check(<-s.sess.MsgCh, DeepEquals, &Notification{channel: "0", level: 2})
63+ // but the session doesn't update the levelmap yet
64+ c.Check(s.sess.Levels.GetAll(), DeepEquals, map[string]int64{})
65 }
66
67 func (s *msgSuite) TestHandleBroadcastBadAckWrite(c *C) {
68@@ -688,9 +688,9 @@
69 c.Check(takeNext(downCh), Equals, protocol.AckMsg{"ack"})
70 upCh <- nil
71 // ...get bubbled up,
72- c.Check(<-sess.MsgCh, NotNil)
73- // and their TopLevel remembered
74- c.Check(sess.Levels.GetAll(), DeepEquals, map[string]int64{"0": 2})
75+ c.Check(<-sess.MsgCh, DeepEquals, &Notification{channel: "0", level: 2})
76+ // (but their TopLevel remain unchanged)
77+ c.Check(sess.Levels.GetAll(), DeepEquals, map[string]int64{})
78
79 // and ping still work even after that.
80 c.Check(takeNext(downCh), Equals, "deadline 110ms")
81@@ -700,3 +700,15 @@
82 upCh <- failure
83 c.Check(<-sess.ErrCh, Equals, failure)
84 }
85+
86+/****************************************************************
87+ Shown() tests
88+****************************************************************/
89+
90+func (cs *clientSessionSuite) TestAckWorks(c *C) {
91+ sess, err := NewSession("", nil, 0, "wah", debuglog)
92+ c.Assert(err, IsNil)
93+ c.Check(sess.Levels.GetAll(), DeepEquals, map[string]int64{})
94+ sess.Shown(&Notification{channel: "0", level: 42})
95+ c.Check(sess.Levels.GetAll(), DeepEquals, map[string]int64{"0": 42})
96+}

Subscribers

People subscribed via source and target branches