git ssb

0+

Kira / %V53yIAO6ZNGv1Lx9tCP…



forked from cel / ssb-issues

Commit 6045860192b4a93aa6ab2006b28b4ce056237bd4

Add getMention method

Charles Lehner committed on 3/29/2016, 9:47:35 PM
Parent: afcbea7780f83c601550a863ce0be8c654a88d78

Files changed

README.mdchanged
index.jschanged
test.jschanged
README.mdView
@@ -142,8 +142,23 @@
142142 - `issue` (Issue): issue to check for update
143143 - `open` (boolean?): whether the message updates the issue to be open (true)
144144 closed (false), or does not affect it (null)
145145
146+#### getMention: sync
147+
148+```js
149+var mention = issueSchemas.getMention(issue, msg)
150+```
151+
152+Get a mention of an issue in a message, if any
153+
154+- `msg` (Msg in metadata): message to check
155+- `issue` (Issue): issue to check for update
156+- `mention` (object?): mention object, with properties like
157+ - `mention.open` (boolean?): whether the issue is updated to be open (true),
158+ closed (false), or not (null)
159+
160+
146161 ### schemas
147162
148163 ```js
149164 var issueSchemas = Issues.schemas
index.jsView
@@ -21,27 +21,34 @@
2121 new: 'async',
2222 edit: 'async',
2323 close: 'async',
2424 reopen: 'async',
25+ getMention: 'sync',
2526 isStatusChanged: 'sync'
2627 }
2728
2829 exports.schemas = issueSchemas
2930
3031 function isStatusChanged(msg, issue) {
32+ var mention = getMention(msg, issue)
33+ return mention ? mention.open : null
34+}
35+
36+function getMention(msg, issue) {
3137 var c = msg.value.content
3238 if (msg.key == issue.id || c.issue == issue.id || c.link == issue.id)
3339 if (c.open != null)
34- return c.open
40+ return c
3541 if (c.issues) {
36- var changed
42+ var mention
3743 for (var i = 0; i < c.issues.length; i++) {
38- changed = isStatusChanged({value: {
44+ mention = getMention({value: {
3945 timestamp: msg.value.timestamp,
4046 author: msg.value.author,
4147 content: c.issues[i]
4248 }}, issue)
43- if (changed != null) return changed
49+ if (mention)
50+ return mention
4451 }
4552 }
4653 }
4754
@@ -229,7 +236,8 @@
229236 new: newIssue,
230237 edit: editIssue,
231238 close: closeIssue,
232239 reopen: reopenIssue,
240+ getMention: getMention,
233241 isStatusChanged: isStatusChanged
234242 }
235243 }
test.jsView
@@ -94,8 +94,10 @@
9494 t.ok(msg, 'msg')
9595 awaitMsg(sbot, msg, function (err) {
9696 t.error(err, 'await')
9797 t.equals(issue1.open, true, 'open')
98+ var mention = issues.getMention(msg, issue1)
99+ t.equals(mention && mention.open, true, 'mention')
98100 updated_at = issue1.updated_at
99101 t.end()
100102 })
101103 })

Built with git-ssb-web