Commit d5694339a3115c17b822de430711589b7e5c52e4
Add isStatusChanged
Charles Lehner committed on 3/27/2016, 1:57:54 AMParent: 67f4dc0ca60e582b79d0e500a198e3463fef7cf5
Files changed
README.md | changed |
index.js | changed |
test.js | changed |
README.md | ||
---|---|---|
@@ -129,8 +129,21 @@ | ||
129 | 129 | `id` (MsgRef): id of the issue to reopen |
130 | 130 | `opts.open` (boolean): set open/closed status |
131 | 131 | `opts.title` (string): set title |
132 | 132 | |
133 | +#### isStatusChanged: sync | |
134 | + | |
135 | +```js | |
136 | +var open = issueSchemas.isStatusChanged(issue, msg) | |
137 | +``` | |
138 | + | |
139 | +Check if a message changes an issue's status | |
140 | + | |
141 | +- `msg` (Msg in metadata): message to check | |
142 | +- `issue` (Issue): issue to check for update | |
143 | +- `open` (boolean?): whether the message updates the issue to be open (true) | |
144 | + closed (false), or does not affect it (null) | |
145 | + | |
133 | 146 | ### schemas |
134 | 147 | |
135 | 148 | ```js |
136 | 149 | var issueSchemas = Issues.schemas |
index.js | ||
---|---|---|
@@ -20,13 +20,32 @@ | ||
20 | 20 | createFeedStream: 'source', |
21 | 21 | new: 'async', |
22 | 22 | edit: 'async', |
23 | 23 | close: 'async', |
24 | - reopen: 'async' | |
24 | + reopen: 'async', | |
25 | + isStatusChanged: 'sync' | |
25 | 26 | } |
26 | 27 | |
27 | 28 | exports.schemas = issueSchemas |
28 | 29 | |
30 | +function isStatusChanged(msg, issue) { | |
31 | + var c = msg.value.content | |
32 | + if (msg.key == issue.id || c.issue == issue.id || c.link == issue.id) | |
33 | + if (c.open != null) | |
34 | + return c.open | |
35 | + if (c.issues) { | |
36 | + var changed | |
37 | + for (var i = 0; i < c.issues.length; i++) { | |
38 | + changed = isStatusChanged({value: { | |
39 | + timestamp: msg.value.timestamp, | |
40 | + author: msg.value.author, | |
41 | + content: c.issues[i] | |
42 | + }}, issue) | |
43 | + if (changed != null) return changed | |
44 | + } | |
45 | + } | |
46 | +} | |
47 | + | |
29 | 48 | exports.init = function (ssb) { |
30 | 49 | |
31 | 50 | var ssbGet = asyncMemo(ssb.get) |
32 | 51 | |
@@ -205,7 +224,8 @@ | ||
205 | 224 | createFeedStream: createFeedStream, |
206 | 225 | new: newIssue, |
207 | 226 | edit: editIssue, |
208 | 227 | close: closeIssue, |
209 | - reopen: reopenIssue | |
228 | + reopen: reopenIssue, | |
229 | + isStatusChanged: isStatusChanged | |
210 | 230 | } |
211 | 231 | } |
test.js | ||
---|---|---|
@@ -105,8 +105,9 @@ | ||
105 | 105 | var msg = schemas.post('I like closing issues') |
106 | 106 | Issues.schemas.closes(msg, issue1.id) |
107 | 107 | sbot.publish(msg, function (err, msg) { |
108 | 108 | t.error(err, 'publish') |
109 | + t.equals(issues.isStatusChanged(msg, issue1), false) | |
109 | 110 | awaitMsg(sbot, msg, function (err) { |
110 | 111 | t.error(err, 'await') |
111 | 112 | t.equals(issue1.open, false, 'closed') |
112 | 113 | t.ok(issue1.updated_at > updated_at, 'updated_at is updated') |
Built with git-ssb-web