git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: c18b233c6d62741496978cd8dc1f34a093946f8b

Files: c18b233c6d62741496978cd8dc1f34a093946f8b / message / html / name.js

782 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') { return cb(null, id.substring(0, 10) + '...(missing)') }
16 if (value.content.type === 'post' && typeof value.content.text === 'string') {
17 return cb(null, title(value.content.text))
18 } else if (typeof value.content.text === 'string') { return cb(null, value.content.type + ':' + title(value.content.text)) } else {
19 return cb(null, id.substring(0, 10) + '...')
20 }
21 })
22 }
23}
24

Built with git-ssb-web