Commit e7dc89b429e48057d0f7dbb658a2c9072fafd580
improve display and strip out markdown from message link display (replies, etc)
Matt McKegg committed on 11/1/2016, 10:54:57 AMParent: 8bd323651fb1b0b76a2af4d86690309d221f6ab1
Files changed
modules/message-name.js | added |
modules/message-name.js | ||
---|---|---|
@@ -1,0 +1,29 @@ | ||
1 … | + | |
2 … | +var sbot_get = require('patchbay/plugs').first(exports.sbot_get = []) | |
3 … | + | |
4 … | +exports.message_name = function (id, cb) { | |
5 … | + sbot_get(id, function (err, value) { | |
6 … | + if (err && err.name === 'NotFoundError') { | |
7 … | + return cb(null, id.substring(0, 10) + '...(missing)') | |
8 … | + } else if (value.content.type === 'post' && typeof value.content.text === 'string') { | |
9 … | + if (value.content.text.trim()) { | |
10 … | + return cb(null, titleFromMarkdown(value.content.text, 40)) | |
11 … | + } | |
12 … | + } else if (typeof value.content.text === 'string') { | |
13 … | + return cb(null, value.content.type + ': ' + titleFromMarkdown(value.content.text, 30)) | |
14 … | + } | |
15 … | + | |
16 … | + return cb(null, id.substring(0, 10) + '...') | |
17 … | + }) | |
18 … | +} | |
19 … | + | |
20 … | +function titleFromMarkdown (text, max) { | |
21 … | + text = text.trim().split('\n', 2).join('\n') | |
22 … | + text = text.replace(/\#|\[.*?\]|\(\S*?\)/g, '').trim() | |
23 … | + text = text.replace(/\:$/, '') | |
24 … | + text = text.trim().split('\n', 1)[0].trim() | |
25 … | + if (text.length > max) { | |
26 … | + text = text.substring(0, max - 2) + '...' | |
27 … | + } | |
28 … | + return text | |
29 … | +} |
Built with git-ssb-web