git ssb

2+

ev / mvd



Commit 865c9963e0dbafc3967d90ab8cb10720bc68af62

add a msg/thread view

Ev Bogue committed on 4/23/2018, 7:27:28 PM
Parent: 959dcfc2f4186af999f316d3aeaff1833bc443b7

Files changed

index.jschanged
render.jschanged
scuttlebot.jschanged
views.jschanged
index.jsView
@@ -8,16 +8,18 @@
88
99 var src = window.location.hash.substring(1)
1010
1111 window.onhashchange = function () {
12- window.location.reload()
12 + window.location.reload()
1313 }
1414
1515 console.log(src)
1616
1717 if (src == 'raw') {
1818 views.rawstream()
1919 } else if (ref.isFeed(src)) {
2020 views.userstream(src)
21 +} else if (ref.isMsg(src)) {
22 + views.get(src)
2123 } else {
2224 views.logstream()
2325 }
render.jsView
@@ -1,14 +1,23 @@
11 var h = require('hyperscript')
22
33 var human = require('human-time')
4-
4 +var ref = require('ssb-ref')
55 var avatar = require('./avatar')
66
77 var markdown = require('ssb-markdown')
88 var config = require('./config')()
99
10-var rawJSON = require('patchapp-raw/json')
10 +function rawJSON (obj) {
11 + return JSON.stringify(obj, null, 2)
12 + .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/)
13 + .map(function (e) {
14 + if(ref.isMsg(e) || ref.isFeed(e) || ref.isBlob(e)) {
15 + return h('a', {href: '#' + e}, e)
16 + }
17 + return e
18 + })
19 +}
1120
1221 module.exports = function (msg) {
1322 if (msg.value.content.type == 'post') {
1423 return h('div.message__content',
@@ -35,8 +44,8 @@
3544 avatar.name(msg.value.author)
3645 )
3746 ),
3847 h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))),
39- h('pre.raw__json', {id: msg.key}, rawJSON(msg))
48 + h('pre', rawJSON(msg.value.content))
4049 )
4150 }
4251 }
scuttlebot.jsView
@@ -50,7 +50,19 @@
5050 )
5151 }),
5252 query: rec.source(function (query) {
5353 return sbot.query.read(query)
54 + }),
55 + get: rec.async(function (key, cb) {
56 + if('function' !== typeof cb)
57 + throw new Error('cb must be function')
58 + if(CACHE[key]) cb(null, CACHE[key])
59 + else sbot.get(key, function (err, value) {
60 + if(err) return cb(err)
61 + cb(null, CACHE[key] = value)
62 + })
63 + }),
64 + links: rec.source(function (query) {
65 + return sbot.links(query)
5466 })
5567 }
5668
views.jsView
@@ -23,14 +23,14 @@
2323 )
2424 }
2525
2626 pull(
27- createStream({old: false, limit: 100}),
27 + createStream({old: false, limit: 10}),
2828 stream.top(content)
2929 )
3030
3131 pull(
32- createStream({reverse: true, live: false, limit: 100}),
32 + createStream({reverse: true, live: false, limit: 10}),
3333 stream.bottom(content)
3434 )
3535 }
3636
@@ -94,4 +94,36 @@
9494 stream.bottom(content)
9595 )
9696
9797 }
98 +
99 +module.exports.get = function (src) {
100 + var content = h('div.content')
101 +
102 + document.body.appendChild(h('div.screen',
103 + {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}},
104 + hyperscroll(content)
105 + ))
106 +
107 + sbot.get(src, function (err, data) {
108 + if (err) {console.log('could not find message') }
109 + data.value = data
110 + console.log(data)
111 + var root = src
112 + if (data.value.content.root)
113 + root = data.value.content.root
114 + sbot.get(root, function (err, data) {
115 + if (err) { console.log('could not find root')}
116 + data.value = data
117 + data.key = root
118 + content.appendChild(h('div.message', render(data)))
119 + pull(
120 + sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}),
121 + pull.drain(function (msg) {
122 + console.log(msg)
123 + if (msg.value)
124 + content.appendChild(h('div.message', render(msg)))
125 + })
126 + )
127 + })
128 + })
129 +}

Built with git-ssb-web