git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: 653e48dd0083bbc962d029960824b4212f96840f

Files: 653e48dd0083bbc962d029960824b4212f96840f / tools.js

2030 bytesRaw
1var h = require('hyperscript')
2var human = require('human-time')
3var avatar = require('./avatar')
4var ref = require('ssb-ref')
5
6var pull = require('pull-stream')
7
8var sbot = require('./scuttlebot')
9
10var config = require('./config')()
11
12function votes (msg) {
13 var votes = h('div.votes')
14 if (msg.key) {
15 pull(
16 sbot.links({dest: msg.key, rel: 'vote'}),
17 pull.drain(function (data) {
18 if (data) {
19 votes.appendChild(h('a', {href:'#' + data.key}, h('img.emoji', {src: config.emojiUrl + 'star.png'})))
20 } else {console.log(data)}
21 })
22 )
23 }
24 return votes
25}
26
27module.exports.timestamp = function (msg, edited) {
28 var timestamp
29 if (edited)
30 timestamp = h('span.timestamp', 'Edited: ', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp))))
31 else
32 timestamp = h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp))))
33 return timestamp
34}
35
36module.exports.header = function (msg) {
37 return h('div.header',
38 h('span.avatar',
39 h('a', {href: '#' + msg.value.author},
40 h('span.avatar--small', avatar.image(msg.value.author)),
41 avatar.name(msg.value.author)
42 )
43 ),
44 exports.timestamp(msg),
45 votes(msg)
46 )
47}
48
49module.exports.messageLink = function (msglink) {
50 var link = h('span', h('a', {href: '#' + msglink}, msglink.substring(0, 8) + '...'))
51 return link
52}
53
54module.exports.rawJSON = function (obj) {
55 return JSON.stringify(obj, null, 2)
56 .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/)
57 .map(function (e) {
58 if(ref.isMsg(e) || ref.isFeed(e) || ref.isBlob(e)) {
59 return h('a', {href: '#' + e}, e)
60 }
61 return e
62 })
63}
64
65var markdown = require('ssb-markdown')
66var config = require('./config')()
67
68module.exports.markdown = function (msg, md) {
69 return {innerHTML: markdown.block(msg, {toUrl: function (url, image) {
70 if(url[0] == '%' || url[0] == '@') return '#' + url
71 if(!image) return url
72 if(url[0] !== '&') return url
73 return config.blobsUrl + url
74 }})}
75}
76

Built with git-ssb-web