git ssb

0+

cel / ssb-issues



Commit d5694339a3115c17b822de430711589b7e5c52e4

Add isStatusChanged

Charles Lehner committed on 3/27/2016, 1:57:54 AM
Parent: 67f4dc0ca60e582b79d0e500a198e3463fef7cf5

Files changed

README.mdchanged
index.jschanged
test.jschanged
README.mdView
@@ -129,8 +129,21 @@
129129 `id` (MsgRef): id of the issue to reopen
130130 `opts.open` (boolean): set open/closed status
131131 `opts.title` (string): set title
132132
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+
133146 ### schemas
134147
135148 ```js
136149 var issueSchemas = Issues.schemas
index.jsView
@@ -20,13 +20,32 @@
2020 createFeedStream: 'source',
2121 new: 'async',
2222 edit: 'async',
2323 close: 'async',
24- reopen: 'async'
24+ reopen: 'async',
25+ isStatusChanged: 'sync'
2526 }
2627
2728 exports.schemas = issueSchemas
2829
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+
2948 exports.init = function (ssb) {
3049
3150 var ssbGet = asyncMemo(ssb.get)
3251
@@ -205,7 +224,8 @@
205224 createFeedStream: createFeedStream,
206225 new: newIssue,
207226 edit: editIssue,
208227 close: closeIssue,
209- reopen: reopenIssue
228+ reopen: reopenIssue,
229+ isStatusChanged: isStatusChanged
210230 }
211231 }
test.jsView
@@ -105,8 +105,9 @@
105105 var msg = schemas.post('I like closing issues')
106106 Issues.schemas.closes(msg, issue1.id)
107107 sbot.publish(msg, function (err, msg) {
108108 t.error(err, 'publish')
109+ t.equals(issues.isStatusChanged(msg, issue1), false)
109110 awaitMsg(sbot, msg, function (err) {
110111 t.error(err, 'await')
111112 t.equals(issue1.open, false, 'closed')
112113 t.ok(issue1.updated_at > updated_at, 'updated_at is updated')

Built with git-ssb-web