2019-07-28 20:49:01 +00:00
|
|
|
'use strict'
|
2019-06-27 05:25:13 +00:00
|
|
|
const md = require('ssb-markdown')
|
2019-06-27 22:07:09 +00:00
|
|
|
const ssbMessages = require('ssb-msgs')
|
2019-06-27 05:25:13 +00:00
|
|
|
const ssbRef = require('ssb-ref')
|
2019-06-25 00:07:18 +00:00
|
|
|
|
2019-06-27 05:25:13 +00:00
|
|
|
const toUrl = (mentions = []) => {
|
2019-06-25 00:07:18 +00:00
|
|
|
var mentionNames = {}
|
|
|
|
|
2019-06-27 21:54:32 +00:00
|
|
|
ssbMessages.links(mentions, 'feed').forEach(function (link) {
|
2019-06-25 00:07:18 +00:00
|
|
|
if (link.name && typeof link.name === 'string') {
|
|
|
|
var name = (link.name.charAt(0) === '@') ? link.name : '@' + link.name
|
|
|
|
mentionNames[name] = link.link
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return (ref, isImage) => {
|
|
|
|
// @mentions
|
|
|
|
if (ref in mentionNames) {
|
|
|
|
return '/author/' + encodeURIComponent(mentionNames[ref])
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ssbRef.isFeedId(ref)) {
|
|
|
|
return '/author/' + encodeURIComponent(ref)
|
|
|
|
} else if (ssbRef.isMsgId(ref)) {
|
2019-06-25 03:10:13 +00:00
|
|
|
return '/thread/' + encodeURIComponent(ref)
|
2019-06-25 00:07:18 +00:00
|
|
|
} else if (ssbRef.isBlobId(ref)) {
|
|
|
|
return 'http://localhost:8989/blobs/get/' + encodeURIComponent(ref)
|
|
|
|
} else if (ref && ref[0] === '#') {
|
|
|
|
return '/hashtag/' + encodeURIComponent(ref.substr(1))
|
|
|
|
}
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
}
|
2019-06-27 05:25:13 +00:00
|
|
|
|
|
|
|
module.exports = (input, mentions) =>
|
|
|
|
md.block(input, {
|
|
|
|
toUrl: toUrl(mentions)
|
|
|
|
})
|