git ssb

16+

Dominic / patchbay



Tree: bd181a1782c01567bc952dfc20d005a712ff2fb0

Files: bd181a1782c01567bc952dfc20d005a712ff2fb0 / modules_basic / message-name.js

771 bytesRaw
1
2function title (s) {
3 var m = /^\n*([^\n]{0,40})/.exec(s)
4 return m && (m[1].length == 40 ? m[1]+'...' : m[1])
5}
6
7exports.needs = { sbot_get: 'first' }
8exports.gives = 'message_name'
9
10//TODO: rewrite as observable?
11
12exports.create = function (api) {
13 return function (id, cb) {
14 api.sbot_get(id, function (err, value) {
15 if(err && err.name == 'NotFoundError')
16 return cb(null, id.substring(0, 10)+'...(missing)')
17 if(value.content.type === 'post' && 'string' === typeof value.content.text)
18 return cb(null, title(value.content.text))
19 else if('string' === typeof value.content.text)
20 return cb(null, value.content.type + ':'+title(value.content.text))
21 else
22 return cb(null, id.substring(0, 10)+'...')
23 })
24 }
25}
26
27

Built with git-ssb-web