Files: 25a8b716544bd1f58eeba52a1feb6bb5a6eb78ae / modules_basic / message-name.js
771 bytesRaw
1 | |
2 | function title (s) { |
3 | var m = /^\n*([^\n]{0,40})/.exec(s) |
4 | return m && (m[1].length == 40 ? m[1]+'...' : m[1]) |
5 | } |
6 | |
7 | exports.needs = { sbot_get: 'first' } |
8 | exports.gives = 'message_name' |
9 | |
10 | //TODO: rewrite as observable? |
11 | |
12 | exports.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