git ssb

16+

Dominic / patchbay



Commit 798d7ea858881504d038705f550581dd75eabaa3

refactor so that sbot apis are a plugin, instead of being passed around

Dominic Tarr committed on 5/29/2016, 12:52:03 PM
Parent: 51bb7f2c4da0239b8114b4f425ca3da89741c261

Files changed

modules/avatar-image.jschanged
modules/avatar.jschanged
modules/compose.jschanged
modules/crypto.jschanged
modules/feed.jschanged
modules/file-input.jschanged
modules/follow.jschanged
modules/like.jschanged
modules/main.jschanged
modules/message-confirm.jschanged
modules/message-link.jschanged
modules/message-name.jschanged
modules/message.jschanged
modules/names.jschanged
modules/post.jschanged
modules/private.jschanged
modules/suggest-mentions.jschanged
modules/tabs.jschanged
modules/thread.jschanged
sbot-api.jschanged
plugs.jsadded
modules/avatar-image.jsView
@@ -2,15 +2,20 @@
22 var getAvatar = require('ssb-avatar')
33 var h = require('hyperscript')
44 var ref = require('ssb-ref')
55
6+var plugs = require('../plugs')
7+var sbot_whoami = plugs.first(exports.sbot_whoami = [])
8+var sbot_links = plugs.first(exports.sbot_links = [])
9+
610 exports.avatar_image = function (author, sbot) {
711 var img = h('img', {src: 'http://localhost:7777/img/fallback.png'})
8- sbot.whoami(function (err, me) {
9- getAvatar(sbot, me.id, author, function (err, avatar) {
12+ sbot_whoami(function (err, me) {
13+ getAvatar({links: sbot_links}, me.id, author, function (err, avatar) {
1014 if(ref.isBlob(avatar.image))
1115 img.src = 'http://localhost:7777/'+encodeURIComponent(avatar.image)
1216 })
1317 })
1418 return img
1519 }
1620
21+
modules/avatar.jsView
@@ -1,15 +1,17 @@
11
22 var h = require('hyperscript')
33 var u = require('../util')
44
5-exports.avatar_name = []
6-exports.avatar_image = []
75
8-exports.avatar = function (author, sbot) {
6+var plugs = require('../plugs')
7+var avatar_name = plugs.first(exports.avatar_name = [])
8+var avatar_image = plugs.first(exports.avatar_image = [])
9+
10+exports.avatar = function (author) {
911 return h('a.avatar',
1012 {href:'#'+author},
11- u.firstPlug(exports.avatar_image, author, sbot),
12- u.firstPlug(exports.avatar_name, author, sbot)
13+ avatar_image(author),
14+ avatar_name(author)
1315 )
1416 }
1517
modules/compose.jsView
@@ -4,19 +4,23 @@
44 var cont = require('cont')
55 var mentions = require('ssb-mentions')
66 var lightbox = require('hyperlightbox')
77
8+var plugs = require('../plugs')
9+
10+//var suggest = plugs.map(exports.suggest = [])
11+var publish = plugs.first(exports.publish = [])
12+var message_content = plugs.first(exports.message_content = [])
13+var message_confirm = plugs.first(exports.message_confirm = [])
14+var file_input = plugs.first(exports.file_input = [])
15+
816 exports.suggest = []
9-exports.publish = []
10-exports.message_content = []
11-exports.message_confirm = []
12-exports.file_input = []
1317
1418 //this decorator expects to be the first
1519
1620 function id (e) { return e }
1721
18-exports.message_compose = function (meta, prepublish, sbot) {
22+exports.message_compose = function (meta, prepublish) {
1923 if('function' !== typeof prepublish)
2024 sbot = prepublish, prepublish = id
2125 meta = meta || {}
2226 if(!meta.type) throw new Error('message must have type')
@@ -49,16 +53,16 @@
4953 meta = prepublish(meta)
5054 } catch (err) {
5155 return alert(err.message)
5256 }
53- u.firstPlug(exports.message_confirm, meta, sbot)
57+ message_confirm(meta)
5458 }
5559
5660
5761 var composer =
5862 h('div', h('div.column', ta,
5963 h('div.row',
60- u.firstPlug(exports.file_input, function (file) {
64+ file_input(function (file) {
6165 files.push(file)
6266
6367 var embed = file.type.indexOf('image/') === 0 ? '!' : ''
6468 ta.value += embed + '['+file.name+']('+file.link+')'
@@ -69,9 +73,9 @@
6973 )
7074
7175 suggest(ta, function (word, cb) {
7276 cont.para(exports.suggest.map(function (fn) {
73- return function (cb) { fn(word, sbot, cb) }
77+ return function (cb) { fn(word, cb) }
7478 }))
7579 (function (err, results) {
7680 if(err) console.error(err)
7781 results = results.reduce(function (ary, item) {
@@ -87,4 +91,6 @@
8791 return composer
8892
8993 }
9094
95+
96+
modules/crypto.jsView
@@ -18,8 +18,11 @@
1818 private: true
1919 }
2020 }
2121
22+
23+var sbot_publish = require('../plugs').first(exports.sbot_publish = [])
24+
2225 exports.message_unbox = function (msg) {
2326 if(msg.value) {
2427 var value = unbox_value(msg.value)
2528 if(value)
@@ -36,19 +39,15 @@
3639 return ref.isFeed(e) ? e : e.link
3740 }))
3841 }
3942
40-exports.message_meta = function (msg) {
41- if(msg.value.private)
42- return "PRIVATE"
43-}
44-
45-exports.publish = function (content, id, sbot) {
43+exports.publish = function (content, id) {
4644 if(content.recps)
4745 content = exports.message_box(content)
48- sbot.publish(content, function (err, msg) {
46+ sbot_publish(content, function (err, msg) {
4947 if(err) throw err
5048 console.log('PUBLISHED', msg)
5149 })
5250 }
5351
5452
53+
modules/feed.jsView
@@ -1,19 +1,20 @@
11 var ref = require('ssb-ref')
22 var ui = require('../ui')
33 var Scroller = require('pull-scroll')
4+
5+var plugs = require('../plugs')
6+var sbot_user_feed = plugs.first(exports.sbot_user_feed = [])
7+var message_render = plugs.first(exports.message_render = [])
8+
49 exports.screen_view = function (id, sbot) {
10+ //TODO: header of user info, avatars, names, follows.
11+
512 if(ref.isFeed(id)) {
6-
713 return ui.createStream(
8- sbot.createUserStream({id: id, reverse: true}),
9- ui.createRenderers(exports.message_render, sbot)
14+ sbot_user_feed({id: id, reverse: true}),
15+ message_render
1016 )
1117 }
1218 }
1319
14-exports.message_render = []
1520
16-
17-
18-
19-
modules/file-input.jsView
@@ -3,17 +3,11 @@
33 var pull = require('pull-stream')
44 var mime = require('mime-types')
55 var split = require('split-buffer')
66
7-function first(plug) {
8- return function () {
9- var args = [].slice.call(arguments)
10- args.unshift(plug)
11- return u.firstPlug.apply(null, args)
12- }
13-}
7+var plugs = require('../plugs')
148
15-var add = first(exports.sbot_blobs_add = [])
9+var add = plugs.first(exports.sbot_blobs_add = [])
1610
1711 exports.file_input = function FileInput(onAdded) {
1812
1913 return h('input', { type: 'file',
@@ -42,4 +36,5 @@
4236
4337
4438
4539
40+
modules/follow.jsView
@@ -1,16 +1,16 @@
11 var h = require('hyperscript')
22 var u = require('../util')
3-exports.avatar = []
3+var avatar = require('../plugs').first(exports.avatar = [])
44
55 //render a message when someone follows someone,
66 //so you see new users
77 exports.message_content = function (msg, sbot) {
88
99 if(msg.value.content.type == 'contact') {
1010 return h('div.contact',
1111 'follows',
12- u.firstPlug(exports.avatar, msg.value.content.contact, sbot)
12+ avatar(msg.value.content.contact)
1313 )
1414 }
1515 }
1616
modules/like.jsView
@@ -2,25 +2,29 @@
22 var h = require('hyperscript')
33 var u = require('../util')
44 var pull = require('pull-stream')
55
6-exports.message_confirm = []
7-exports.message_link = []
6+var plugs = require('../plugs')
87
8+var message_confirm = plugs.first(exports.message_confirm = [])
9+var message_link = plugs.first(exports.message_link = [])
10+var sbot_links = plugs.first(exports.sbot_links = [])
11+
912 exports.message_content = function (msg, sbot) {
1013 if(msg.value.content.type !== 'vote') return
1114 var link = msg.value.content.vote.link
12- return h('div', msg.value.content.vote.value > 0 ? 'yup' : 'nah',
13- u.decorate(exports.message_link, link, function (d, e, v) { return d(e, v, sbot) })
15+ return h('div',
16+ msg.value.content.vote.value > 0 ? 'yup' : 'nah',
17+ ' ', message_link(link)
1418 )
1519 }
1620
1721 exports.message_meta = function (msg, sbot) {
1822
1923 var yupps = h('a')
2024
2125 pull(
22- sbot.links({dest: msg.key, rel: 'vote'}),
26+ sbot_links({dest: msg.key, rel: 'vote'}),
2327 pull.collect(function (err, votes) {
2428 if(votes.length === 1)
2529 yupps.textContent = ' 1 yup'
2630 if(votes.length)
@@ -45,10 +49,14 @@
4549 yup.private = true
4650 }
4751 //TODO: actually publish...
4852
49- u.firstPlug(exports.message_confirm, yup, sbot)
53+ message_confirm(yup)
5054 }}, 'yup')
5155
5256 }
5357
5458
59+
60+
61+
62+
modules/main.jsView
@@ -3,37 +3,46 @@
33 var u = require('../util')
44 var pull = require('pull-stream')
55 var Scroller = require('pull-scroll')
66
7+var plugs = require('../plugs')
8+var message_render = plugs.first(exports.message_render = [])
9+var message_compose = plugs.first(exports.message_compose = [])
10+var sbot_log = plugs.first(exports.sbot_log = [])
11+
712 exports.screen_view = function (path, sbot) {
813 if(path === '/') {
914 var content = h('div.column')
10- var div = h('div.column', {style: {'overflow':'auto'}},
11- u.firstPlug(exports.message_compose, {type: 'post'}, sbot),
12- content
15+ var div = h('div.column',
16+ {style: {'overflow':'auto'}},
17+ message_compose({type: 'post'}), content
1318 )
14- var render = ui.createRenderers(exports.message_render, sbot)
1519
1620 pull(
17- sbot.createLogStream({old: false}),
18- Scroller(div, content, render, true, false)
21+ sbot_log({old: false}),
22+ Scroller(div, content, message_render, true, false)
1923 )
2024
2125 pull(
22- u.next(sbot.createLogStream, {reverse: true, limit: 100, live: false}),
23- Scroller(div, content, render, false, false)
26+ u.next(sbot_log, {reverse: true, limit: 100, live: false}),
27+ Scroller(div, content, message_render, false, false)
2428 )
2529
2630 return div
2731 }
2832 }
2933
30-exports.message_render = []
31-exports.message_compose = []
3234
3335
3436
3537
3638
3739
3840
3941
42+
43+
44+
45+
46+
47+
48+
modules/message-confirm.jsView
@@ -2,43 +2,38 @@
22 var h = require('hyperscript')
33 var u = require('../util')
44 //publish or add
55
6-exports.publish = []
7-exports.message_content = []
6+var plugs = require('../plugs')
87
8+var publish = plugs.first(exports.publish = [])
9+var message_content = plugs.first(exports.message_content = [])
10+
911 exports.message_confirm = function (content, sbot) {
1012
1113 var lb = lightbox()
1214 document.body.appendChild(lb)
1315
1416 var okay = h('button', 'okay', {onclick: function () {
15- u.firstPlug(exports.publish, content, null, sbot)
16- lb.remove()
17+ publish(content); lb.remove()
1718 }})
1819
1920 var cancel = h('button', 'cancel', {onclick: function () {
2021 lb.remove()
2122 }})
2223
23- var hidden = h('input', {style: {visible: 'hidden'}})
24-
25-
2624 okay.addEventListener('keydown', function (ev) {
2725 if(ev.keyCode === 27) cancel.click() //escape
2826 })
2927
3028 lb.show(h('div.column',
31- u.firstPlug(exports.message_content,
32- {key: "DRAFT", value: {content: content}}, sbot
33- ) || h('pre', JSON.stringify(content, null, 2)),
29+ message_content({key: "DRAFT", value: {content: content}})
30+ || h('pre', JSON.stringify(content, null, 2)),
3431 h('div.row', okay, cancel)
3532 ))
3633
3734 okay.focus()
3835
39-// hidden.focus()
40-
4136 }
4237
4338
4439
@@ -52,4 +47,7 @@
5247
5348
5449
5550
51+
52+
53+
modules/message-link.jsView
@@ -1,16 +1,24 @@
11 var h = require('hyperscript')
22
3-exports.message_link = function (el, id, sbot) {
4- if(el) return el
3+var sbot_get = require('../plugs').first(exports.sbot_get = [])
54
5+exports.message_link = function (id) {
6+
7+ if('string' !== typeof id)
8+ throw new Error('link must be to message id')
9+
610 var link = h('a', {href: '#'+id}, id.substring(0, 10)+'...')
711
8- sbot.get(id, function (err, value) {
9- if(err) return
12+ sbot_get(id, function (err, value) {
13+ if(err) return console.error(err)
1014 if(value.content.text)
1115 link.textContent = value.content.text.substring(0, 40)+'...'
1216 })
1317
1418 return link
1519 }
1620
21+
22+
23+
24+
modules/message-name.jsView
@@ -1,7 +1,8 @@
11
2+var sbot_get = require('../plugs').first(exports.sbot_get = [])
23
3-exports.message_name = function (id, sbot) {
4- sbot.get(id, function (err, value) {
4+exports.message_name = function (id) {
5+ sbot_get(id, function (err, value) {
56
67 })
78 }
modules/message.jsView
@@ -1,47 +1,49 @@
11 var h = require('hyperscript')
22 var u = require('../util')
33 var pull = require('pull-stream')
44
5+
6+
7+var plugs = require('../plugs')
8+var message_content = plugs.first(exports.message_content = [])
9+var avatar = plugs.first(exports.avatar = [])
10+var message_meta = plugs.map(exports.message_meta = [])
11+var message_action = plugs.map(exports.message_action = [])
12+var message_link = plugs.first(exports.message_link = [])
13+
14+var sbot_links = plugs.first(exports.sbot_links = [])
15+
516 exports.message_render = function (msg, sbot) {
6- var el = u.firstPlug(exports.message_content, msg, sbot)
17+ var el = message_content(msg)
18+ if(!el) return
719
8- function map (plugs, value) {
9- return plugs.map(function (plug) {
10- return plug(value, sbot)
11- }).filter(Boolean)
12- }
13-
1420 var backlinks = h('div.backlinks')
1521
1622 pull(
17- sbot.links({dest: msg.key, rel: 'mentions', keys: true}),
23+ sbot_links({dest: msg.key, rel: 'mentions', keys: true}),
1824 pull.collect(function (err, links) {
1925 if(links.length)
2026 backlinks.appendChild(h('label', 'backlinks:',
2127 h('div', links.map(function (link) {
22- return u.decorate(exports.message_link, link.key, function (d, e, v) { return d(e, v, sbot) })
28+ return message_link(link.key)
2329 }))
2430 ))
2531 })
2632 )
2733
28- if(el)
29- return h('div.message.column',
30- h('div.title.row',
31- h('div.avatar', map(exports.avatar, msg.value.author)),
32- h('div.message_meta.row', map(exports.message_meta, msg))
33- ),
34- h('div.message_content', el),
35- h('div.message_actions.row',
36- h('div.actions', map(exports.message_action, msg))
37- ),
38- backlinks
39- )
34+ return h('div.message.column',
35+ h('div.title.row',
36+ h('div.avatar', avatar(msg.value.author)),
37+ h('div.message_meta.row', message_meta(msg))
38+ ),
39+ h('div.message_content', el),
40+ h('div.message_actions.row',
41+ h('div.actions', message_action(msg))
42+ ),
43+ backlinks
44+ )
4045 }
4146
42-exports.message_content = []
43-exports.avatar = []
44-exports.message_meta = []
45-exports.message_action = []
46-exports.message_link = []
4747
48+
49+
modules/names.jsView
@@ -4,24 +4,30 @@
44 function all(stream, cb) {
55 pull(stream, pull.collect(cb))
66 }
77
8+var plugs = require('../plugs')
9+
10+var sbot_links2 = plugs.first(exports.sbot_links2 = [])
11+
812 exports.avatar_name =
913 function name (id, sbot) {
1014 var n = h('span', id.substring(0, 10))
15+
1116 //choose the most popular name for this person.
1217 //for anything like this you'll see I have used sbot.links2
1318 //which is the ssb-links plugin. as you'll see the query interface
1419 //is pretty powerful!
1520 //TODO: "most popular" name is easily gameable.
1621 //must come up with something better than this.
22+
1723 /*
1824 filter(rel: ['mentions', prefix('@')])
1925 .reduce(name: rel[1], value: count())
2026 */
2127
2228 all(
23- sbot.links2.read({query: [
29+ sbot_links2({query: [
2430 {$filter: {rel: ['mentions', {$prefix: '@'}], dest: id}},
2531 {$reduce: { name: ['rel', 1], count: {$count: true}
2632 }}
2733 ]}),
modules/post.jsView
@@ -4,15 +4,16 @@
44 var ref = require('ssb-ref')
55
66 //render a message
77
8+var plugs = require('../plugs')
9+var message_link = plugs.first(exports.message_link = [])
10+
811 exports.message_content = function (data, sbot) {
912 if(!data.value.content || !data.value.content.text) return
1013
1114 var root = data.value.content.root
12- var re = !root ? null : h('span', 're:',
13- u.decorate(exports.message_link, root, function (d, e, v) { return d(e, v, sbot) })
14- )
15+ var re = !root ? null : h('span', 're:', message_link(root))
1516
1617 var content = h('div')
1718 var d = h('div', re, content)
1819
@@ -30,10 +31,11 @@
3031 }})
3132 return d
3233 }
3334
34-exports.message_link = []
3535
3636
3737
3838
3939
40+
41+
modules/private.jsView
@@ -4,64 +4,68 @@
44 var pull = require('pull-stream')
55 var Scroller = require('pull-scroll')
66 var ref = require('ssb-ref')
77
8-exports.message_render = []
9-exports.message_compose = []
10-exports.message_unbox = []
8+var plugs = require('../plugs')
119
10+var message_render = plugs.first(exports.message_render = [])
11+var message_compose = plugs.first(exports.message_compose = [])
12+var message_unbox = plugs.first(exports.message_unbox = [])
13+var sbot_log = plugs.first(exports.sbot_log = [])
14+var sbot_whoami = plugs.first(exports.sbot_whoami = [])
15+
1216 function unbox () {
1317 return pull(
1418 pull.filter(function (msg) {
1519 return 'string' == typeof msg.value.content
1620 }),
1721 pull.map(function (msg) {
18- return u.firstPlug(exports.message_unbox, msg)
22+ return message_unbox(msg)
1923 }),
2024 pull.filter(Boolean)
2125 )
2226 }
2327
24-exports.screen_view = function (path, sbot) {
28+exports.screen_view = function (path) {
2529 if(path === '/private') {
26- SBOT = sbot
2730 var content = h('div.column')
2831 var id = null
29- sbot.whoami(function (err, me) {
32+ sbot_whoami(function (err, me) {
3033 id = me.id
3134 })
3235
3336 var div = h('div.column', {style: {'overflow':'auto'}},
34- u.firstPlug(exports.message_compose, {type: 'post', recps: [], private: true},
37+ message_compose({type: 'post', recps: [], private: true},
3538 function (msg) {
3639 msg.recps = [id].concat(msg.mentions).filter(function (e) {
3740 return ref.isFeed('string' === typeof e ? e : e.link)
3841 })
3942 if(!msg.recps.length)
4043 throw new Error('cannot make private message without recipients - just mention them in the message')
4144 return msg
42- },
43- sbot),
45+ }),
4446 content)
45- var render = ui.createRenderers(exports.message_render, sbot)
4647
4748 pull(
48- sbot.createLogStream({old: false}),
49+ sbot_log({old: false}),
4950 unbox(),
50- Scroller(div, content, render, true, false)
51+ Scroller(div, content, message_render, true, false)
5152 )
5253
5354 pull(
54- u.next(sbot.createLogStream, {reverse: true, limit: 1000}),
55+ u.next(sbot_log, {reverse: true, limit: 1000}),
5556 unbox(),
56- Scroller(div, content, render, false, false, function (err) {
57+ Scroller(div, content, message_render, false, false, function (err) {
5758 if(err) throw err
5859 })
5960 )
6061
6162 return div
6263 }
6364 }
6465
66+exports.message_meta = function (msg) {
67+ if(msg.value.private)
68+ return "PRIVATE"
69+}
6570
6671
67-
modules/suggest-mentions.jsView
@@ -1,12 +1,13 @@
11 var pull = require('pull-stream')
2-
2+var cont = require('cont')
33 function isImage (filename) {
44 return /\.(gif|jpg|png|svg)$/i.test(filename)
55 }
66
7-exports.suggest = function (word, sbot, cb) {
7+var sbot_links2 = require('../plugs').first(exports.sbot_links2 = [])
88
9+exports.suggest = cont.to(function (word, cb) {
910 if(!/^[@%&!]/.test(word[0])) return cb()
1011 if(word.length < 2) return cb()
1112
1213 var sigil = word[0]
@@ -14,9 +15,9 @@
1415 if(embed) sigil = '&'
1516 if(word[0] !== '@') word = word.substring(1)
1617
1718 pull(
18- sbot.links2.read({query: [
19+ sbot_links2({query: [
1920 {$filter: {rel: ['mentions', {$prefix: word}], dest: {$prefix: sigil}}},
2021 {$reduce: {id: 'dest', name: ['rel', 1], rank: {$count: true}}}
2122 ]}),
2223 pull.collect(function (err, ary) {
@@ -34,11 +35,9 @@
3435 rank: e.rank,
3536 image: isImage(e.name) ? 'http://localhost:7777/'+e.id : undefined
3637 }
3738 })
38- console.log(ary)
3939 cb(null, ary)
4040 })
4141 )
42-}
42+})
4343
44-
modules/tabs.jsView
@@ -9,29 +9,30 @@
99 if(el.tagName !== 'A') return ancestor(el.parentElement)
1010 return el
1111 }
1212
13+var plugs = require('../plugs')
14+var screen_view = plugs.first(exports.screen_view = [])
15+
16+exports.message_render = []
17+
18+
1319 exports.app = function (_, sbot) {
14- function screen (path) {
15- return u.firstPlug(exports.screen_view, path, sbot)
16- }
17-
1820 var tabs = Tabs()
1921 tabs.classList.add('screen')
20- var main = screen('/')
22+
23+ var main = screen_view('/')
2124 if(main) tabs.add('main', main, true)
2225
23- var private = screen('/private')
26+ var private = screen_view('/private')
2427 if(private) tabs.add('private', private, true)
2528
2629
2730 tabs.onclick = function (ev) {
2831 var link = ancestor(ev.target)
2932 if(!link) return
3033 var path = link.hash.substring(1)
3134
32- console.log(link)
33-
3435 ev.preventDefault()
3536 ev.stopPropagation()
3637
3738 //open external links.
@@ -40,18 +41,15 @@
4041 return require('shell').openExternal(link.href)
4142
4243 if(tabs.has(path)) return tabs.select(path)
4344
44- var el = screen(path)
45+ var el = screen_view(path)
4546 if(el) tabs.add(path, el, !ev.ctrlKey)
4647
4748 }
4849
4950 return tabs
5051 }
5152
52-exports.message_render = []
53-exports.screen_view = []
5453
5554
5655
57-
modules/thread.jsView
@@ -20,26 +20,31 @@
2020 })
2121 }
2222 }
2323
24+var plugs = require('../plugs')
25+
26+var message_render = plugs.first(exports.message_render = [])
27+var message_compose = plugs.first(exports.message_compose = [])
28+var message_unbox = plugs.first(exports.message_unbox = [])
29+
30+var sbot_get = plugs.first(exports.sbot_get = [])
31+var sbot_links = plugs.first(exports.sbot_links = [])
32+
2433 function getThread (root, sbot, cb) {
2534 //in this case, it's inconvienent that panel only takes
2635 //a stream. maybe it would be better to accept an array?
2736
2837 return pull(Cat([
2938 once(function (cb) {
30- sbot.get(root, function (err, value) {
39+ sbot_get(root, function (err, value) {
3140 cb(err, {key: root, value: value})
3241 })
3342 }),
34- sbot.links({rel: 'root', dest: root, values: true, keys: true})
43+ sbot_links({rel: 'root', dest: root, values: true, keys: true})
3544 ]), pull.collect(cb))
3645 }
3746
38-function unbox(msg) {
39- return u.firstPlug(exports.message_unbox, msg)
40-}
41-
4247 exports.screen_view = function (id, sbot) {
4348 if(ref.isMsg(id)) {
4449 var meta = {
4550 type: 'post',
@@ -50,38 +55,33 @@
5055 var content = h('div')
5156 var div = h('div.column',
5257 {style: {'overflow-y': 'auto'}},
5358 content,
54- h('div.editor', u.firstPlug(exports.message_compose, meta, sbot))
59+ h('div.editor', message_compose(meta))
5560 )
5661
57- var render = ui.createRenderers(exports.message_render, sbot)
58-
5962 pull(
60- sbot.links({
63+ sbot_links({
6164 rel: 'root', dest: id, keys: true, old: false
6265 }),
6366 pull.drain(function (msg) {
64- console.log('new message in thread', msg)
65- //redraw thread
66- loadThread()
67+ loadThread() //redraw thread
6768 }, function () {} )
6869 )
6970
7071
7172 function loadThread () {
72- console.log("LOAD THREAD", id)
7373 getThread(id, sbot, function (err, thread) {
7474 //would probably be better keep an id for each message element
7575 //(i.e. message key) and then update it if necessary.
7676 //also, it may have moved (say, if you received a missing message)
7777 content.innerHTML = ''
7878 thread = thread.map(function (msg) {
79- return 'string' === typeof msg.value.content ? unbox(msg) : msg
79+ return 'string' === typeof msg.value.content ? message_unbox(msg) : msg
8080 })
8181
8282 if(err) return content.appendChild(h('pre', err.stack))
83- sort(thread).map(render).forEach(function (el) {
83+ sort(thread).map(message_render).forEach(function (el) {
8484 content.appendChild(el)
8585 })
8686
8787 var branches = sort.heads(thread)
@@ -90,35 +90,12 @@
9090 var recps = thread[0].value.content.recps
9191 if(recps && thread[0].value.private)
9292 meta.recps = recps
9393 })
94-
9594 }
9695
9796 loadThread()
98-
9997 return div
10098 }
101-
10299 }
103100
104-exports.message_render = []
105-exports.message_compose = []
106-exports.message_unbox = []
107101
108-
109-
110-
111-
112-
113-
114-
115-
116-
117-
118-
119-
120-
121-
122-
123-
124-
sbot-api.jsView
@@ -27,13 +27,27 @@
2727 },
2828 sbot_links: function (query) {
2929 return sbot.links(query)
3030 },
31+ sbot_links2: function (query) {
32+ return sbot.links2.read(query)
33+ },
34+ sbot_log: function (opts) {
35+ return sbot.createLogStream(opts)
36+ },
37+ sbot_user_feed: function (opts) {
38+ return sbot.createUserStream(opts)
39+ },
3140 sbot_get: function (key, cb) {
3241 sbot.get(key, cb)
3342 },
3443 sbot_publish: function (msg, cb) {
3544 sbot.publish(msg, cb)
45+ },
46+ sbot_whoami: function (cb) {
47+ sbot.whoami(cb)
3648 }
3749 }
3850 }
3951
52+
53+
plugs.jsView
@@ -1,0 +1,20 @@
1+var u = require('./util')
2+
3+exports.first = function first(plug) {
4+ return function () {
5+ var args = [].slice.call(arguments)
6+ args.unshift(plug)
7+ return u.firstPlug.apply(null, args)
8+ }
9+}
10+
11+exports.map = function (plug) {
12+ return function () {
13+ var args = [].slice.call(arguments)
14+ return plug.map(function (fn) {
15+ if(fn) return fn.apply(null, args)
16+ }).filter(Boolean)
17+ }
18+}
19+
20+

Built with git-ssb-web