git ssb

16+

Dominic / patchbay



Commit 134d423c26820a78c6bbfbc506df577e0673b6b2

update everything

Dominic Tarr committed on 5/12/2016, 9:16:22 AM
Parent: 1b75f8ffcfadbde6d14a55155a3f436a7e485d94

Files changed

index.jschanged
modules/avatar.jschanged
modules/like.jschanged
modules/message.jschanged
modules/names.jschanged
modules/post.jschanged
modules/timestamp.jschanged
modules/feed.jsadded
modules/main.jsadded
modules/markdown.jsadded
modules/message-link.jsadded
modules/message-name.jsadded
modules/tabs.jsadded
modules/thread.jsadded
ui.jsadded
index.jsView
@@ -1,5 +1,6 @@
11 var h = require('hyperscript')
2+var u = require('./util')
23 var pull = require('pull-stream')
34 var combine = require('depject')
45 var fs = require('fs')
56 var path = require('path')
@@ -7,31 +8,17 @@
78 var modules = fs.readdirSync(path.join(__dirname, 'modules'))
89 .map(function (e) { return require('./modules/'+e) })
910
1011 var renderers = []
11-modules.unshift({message_render: renderers})
12+var app = []
13+modules.unshift({app: app})
1214
1315 combine(modules)
1416
1517 var u = require('./util')
1618
1719 require('ssb-client')(function (err, sbot) {
1820 if(err) throw err
19- pull(
20- sbot.createLogStream({reverse: true, limit: 100}),
21- pull.drain(function (data) {
22-
23- var el = u.first(renderers, function (render) {
24- return render(data, sbot)
25- })
26-
27- if('string' === typeof el) el = document.createTextNode(el)
28- if(el) document.body.appendChild(el)
29- })
30- )
21+ document.body.appendChild(u.decorate(app, sbot))
3122 })
3223
3324
34-
35-
36-
37-
modules/avatar.jsView
@@ -2,9 +2,9 @@
22 var h = require('hyperscript')
33 var u = require('../util')
44
55 exports.avatar = function (author, sbot) {
6- return h('a', {href:'#'}, u.first(exports.avatar_name, function (plug) {
6+ return h('a', {href:'#'+author}, u.first(exports.avatar_name, function (plug) {
77 return plug(author, sbot)
88 }))
99 }
1010
modules/like.jsView
@@ -1,9 +1,15 @@
11
22 var h = require('hyperscript')
3+var u = require('../util')
34
4-exports.message_content = function (msg) {
5- if(msg.value.content && msg.value.content.type === 'vote')
5+exports.message_content = function (msg, sbot) {
6+ if(msg.value.content.type !== 'vote') return
7+ var link = msg.value.content.vote.link
68 return h('div', msg.value.content.vote.value > 0 ? 'yup' : 'nah',
7- h('a', {href: '#/msg/'+msg.value.content.vote.link}, msg.key)
9+ u.decorate(exports.message_link, link, function (d, e, v) { return d(e, v, sbot) })
810 )
911 }
12+
13+exports.message_link = []
14+
15+
modules/message.jsView
@@ -1,10 +1,11 @@
11 var h = require('hyperscript')
22 var u = require('../util')
3+var pull = require('pull-stream')
34
45 exports.message_render = function (msg, sbot) {
56 var el = u.first(exports.message_content, function (fn) {
6- return fn(msg)
7+ return fn(msg, sbot)
78 })
89
910 if(el) console.log(el)
1011
@@ -13,22 +14,37 @@
1314 return plug(value, sbot)
1415 }).filter(Boolean)
1516 }
1617
18+ var backlinks = h('div.backlinks')
19+
20+ pull(
21+ sbot.links({dest: msg.key, rel: 'mentions', keys: true}),
22+ pull.collect(function (err, links) {
23+ if(links.length)
24+ backlinks.appendChild(h('label', 'backlinks:',
25+ h('div', links.map(function (link) {
26+ return u.decorate(exports.message_link, link.key, function (d, e, v) { return d(e, v, sbot) })
27+ }))
28+ ))
29+ })
30+ )
31+
1732 if(el)
1833 return h('div.message',
1934 h('div.title',
2035 h('div.avatar', map(exports.avatar, msg.value.author)),
2136 h('div.metadata', map(exports.message_meta, msg))
2237 ),
2338 h('div.content', el),
2439 h('div.footer',
25- h('div.actions', map(exports.message_actions))
26- )
40+ h('div.actions', map(exports.message_action))
41+ ),
42+ backlinks
2743 )
2844 }
2945
3046 exports.message_content = []
3147 exports.avatar = []
3248 exports.message_meta = []
3349 exports.message_action = []
34-
50+exports.message_link = []
modules/names.jsView
@@ -4,9 +4,9 @@
44 function all(stream, cb) {
55 pull(stream, pull.collect(cb))
66 }
77
8-exports.avatar =
8+exports.avatar_name =
99 function name (id, sbot) {
1010 var n = h('span', id.substring(0, 10))
1111 //choose the most popular name for this person.
1212 //for anything like this you'll see I have used sbot.links2
modules/post.jsView
@@ -1,17 +1,35 @@
11 var markdown = require('ssb-markdown')
22 var h = require('hyperscript')
3-
3+var u = require('../util')
44 //render a message
55
66 exports.message_content = function (data, sbot) {
7- if(data.value.content && data.value.content.text) {
8- var d = h('div'/*, data.value.root ? */)
9- d.innerHTML =
10- markdown.block(data.value.content.text, data.value.content.mentions)
11- return d
12- }
7+ if(!data.value.content || !data.value.content.text) return
8+
9+ var root = data.value.content.root
10+ var re = !root ? null : h('span', 're:',
11+ u.decorate(exports.message_link, root, function (d, e, v) { return d(e, v, sbot) })
12+ )
13+
14+ var content = h('div')
15+ var d = h('div', re, content)
16+
17+ var mentions = {}
18+ if(Array.isArray(data.value.content.mentions))
19+ data.value.content.mentions.forEach(function (link) {
20+ if(link.name) mentions["@"+link.name] = link.link
21+ })
22+
23+ content.innerHTML =
24+ markdown.block(data.value.content.text, {toUrl: function (id) {
25+ return '#'+(mentions[id]?mentions[id]:id)
26+ }})
27+ return d
1328 }
1429
30+exports.message_link = []
1531
1632
1733
34+
35+
modules/timestamp.jsView
@@ -1,6 +1,6 @@
11 var h = require('hyperscript')
22 var moment = require('moment')
33
44 exports.message_meta = function (msg) {
5- return h('a', {href: '#/'+msg.key}, moment(msg.value.timestamp).fromNow())
5+ return h('a', {href: '#'+msg.key}, moment(msg.value.timestamp).fromNow())
66 }
modules/feed.jsView
@@ -1,0 +1,17 @@
1+var ref = require('ssb-ref')
2+var ui = require('../ui')
3+
4+exports.screen_view = function (id, sbot) {
5+ if(ref.isFeed(id))
6+ return ui.createStream(
7+ sbot.createUserStream({id: id, limit: 100, reverse: true}),
8+ ui.createRenderers(exports.message_render, sbot)
9+ )
10+}
11+
12+exports.message_render = []
13+
14+
15+
16+
17+
modules/main.jsView
@@ -1,0 +1,18 @@
1+
2+var ui = require('../ui')
3+
4+exports.screen_view = function (path, sbot) {
5+ if(path === '/')
6+ return ui.createStream(
7+ sbot.createLogStream({limit: 100, reverse: true}),
8+ ui.createRenderers(exports.message_render, sbot)
9+ )
10+}
11+
12+exports.message_render = []
13+
14+
15+
16+
17+
18+
modules/markdown.jsView
@@ -1,0 +1,7 @@
1+
2+//
3+//exports.markdown = function (body, msg
4+//
5+//function (text, ref, title) {
6+// return <h
7+//}
modules/message-link.jsView
@@ -1,0 +1,19 @@
1+var h = require('hyperscript')
2+
3+exports.message_link = function (el, id, sbot) {
4+ console.log('MESSAGE_LINK', el, id)
5+ if(el) return el
6+
7+ var link = h('a', {href: '#'+id}, id.substring(0, 10)+'...')
8+
9+ sbot.get(id, function (err, value) {
10+ if(err) return
11+ console.log('LINKED', value)
12+ if(value.content.text)
13+ link.textContent = value.content.text.substring(0, 40)+'...'
14+ })
15+
16+ return link
17+}
18+
19+
modules/message-name.jsView
@@ -1,0 +1,7 @@
1+
2+
3+exports.message_name = function (id, sbot) {
4+ sbot.get(id, function (err, value) {
5+
6+ })
7+}
modules/tabs.jsView
@@ -1,0 +1,45 @@
1+var tabs = require('tabs')
2+var h = require('hyperscript')
3+var pull = require('pull-stream')
4+var u = require('../util')
5+
6+
7+function ancestor (el) {
8+ if(!el) return
9+ if(el.tagName !== 'A') return ancestor(el.parentElement)
10+ return el
11+}
12+exports.app = function (_, sbot) {
13+
14+ function screen (path) {
15+ return u.first(exports.screen_view, function (fn) {
16+ return fn(path, sbot)
17+ })
18+ }
19+
20+ var t = tabs()
21+ var main = screen('/')
22+ if(main) t.add('main', main, true)
23+
24+ t.onclick = function (ev) {
25+ var link = ancestor(ev.target)
26+ EV = ev
27+ var path = link.hash.substring(1)
28+ var el = screen(path)
29+ if(el) t.add(path, el, !ev.ctrlKey)
30+
31+ ev.preventDefault()
32+ ev.stopPropagation()
33+ }
34+
35+ return t
36+}
37+
38+exports.message_render = []
39+exports.screen_view = []
40+
41+
42+
43+
44+
45+
modules/thread.jsView
@@ -1,0 +1,53 @@
1+var ui = require('../ui')
2+var pull = require('pull-stream')
3+var Cat = require('pull-cat')
4+var Sort = require('pull-sort')
5+var ref = require('ssb-ref')
6+
7+function once (cont) {
8+ var ended = false
9+ return function (abort, cb) {
10+ if(abort) return cb(abort)
11+ else if (ended) return cb(ended)
12+ else
13+ cont(function (err, data) {
14+ if(err) return cb(ended = err)
15+ ended = true
16+ cb(null, data)
17+ })
18+ }
19+}
20+
21+function threadStream (root, sbot ) {
22+ //in this case, it's inconvienent that panel only takes
23+ //a stream. maybe it would be better to accept an array?
24+
25+ return pull(
26+ Cat([
27+ once(function (cb) {
28+ sbot.get(root, function (err, value) {
29+ cb(err, {key: root, value: value})
30+ })
31+ }),
32+ sbot.links({rel: 'root', dest: root, values: true, keys: true})
33+ ]),
34+ Sort(function (a, b) {
35+ //THIS IS WRONG AND HAS KNOWN BUGS!!!
36+ //TODO: sort by cryptographic causal ordering.
37+ return a.value.timestamp - b.value.timestamp
38+ })
39+ )
40+}
41+
42+exports.screen_view = function (id, sbot) {
43+ if(ref.isMsg(id))
44+ return ui.createStream(
45+ threadStream(id, sbot),
46+ ui.createRenderers(exports.message_render, sbot)
47+ )
48+}
49+
50+exports.message_render = []
51+
52+
53+
ui.jsView
@@ -1,0 +1,31 @@
1+var h = require('hyperscript')
2+var pull = require('pull-stream')
3+var u = require('./util')
4+
5+exports.createStream = function createStream (stream, render) {
6+ var div = h('div.content')
7+
8+ pull(
9+ stream,
10+ pull.drain(function (data) {
11+ var el = render(data)
12+ if('string' === typeof el) el = document.createTextNode(el)
13+ if(el) {
14+ if(div.children.length)
15+ div.appendChild(h('hr'))
16+ div.appendChild(el)
17+ }
18+
19+ })
20+ )
21+
22+ return div
23+}
24+
25+exports.createRenderers = function (renderers, sbot) {
26+ return function (data) {
27+ return u.first(renderers, function (fn) {
28+ return fn(data, sbot)
29+ })
30+ }
31+}

Built with git-ssb-web