git ssb

16+

Dominic / patchbay



Commit 0317853c50ffacda585e8b019f18d3b8ff32329a

tidy up plugin pattern with firstPlug method, and implement message confirmation screen

Dominic Tarr committed on 5/17/2016, 9:40:27 PM
Parent: b37724d400c1859d22e995622281817db4d79249

Files changed

modules/avatar.jschanged
modules/compose.jschanged
modules/crypto.jschanged
modules/follow.jschanged
modules/like.jschanged
modules/main.jschanged
modules/message.jschanged
modules/private.jschanged
modules/tabs.jschanged
modules/thread.jschanged
modules/avatar.jsView
@@ -2,11 +2,13 @@
22 var h = require('hyperscript')
33 var u = require('../util')
44
55 exports.avatar = function (author, sbot) {
6- return h('a', {href:'#'+author}, u.first(exports.avatar_name, function (plug) {
7- return plug(author, sbot)
8- }))
6+ return h('a',
7+ {href:'#'+author},
8+ u.firstPlug(exports.avatar_name, author, sbot)
9+ )
910 }
1011
1112 exports.avatar_name = []
1213
14+
modules/compose.jsView
@@ -1,15 +1,21 @@
11 var h = require('hyperscript')
2+var u = require('../util')
23 var suggest = require('suggest-box')
34 var cont = require('cont')
45 var mentions = require('ssb-mentions')
6+var lightbox = require('hyperlightbox')
7+
58 exports.suggest = []
9+exports.publish = []
10+exports.message_content = []
611
712 //this decorator expects to be the first
813 exports.message_compose = function (el, meta, sbot) {
914 if(el) return el
1015
1116 meta = meta || {}
17+ if(!meta.type) throw new Error('message must have type')
1218 var ta = h('textarea')
1319 //h('pre.editable.fixed', 'HELLO')
1420 //ta.setAttribute('contenteditable', '')
1521
@@ -31,9 +37,9 @@
3137 h('div', h('div.column', ta,
3238 h('button', 'publish', {onclick: function () {
3339 meta.text = ta.value
3440 meta.mentions = mentions(ta.value)
35- alert(JSON.stringify(meta, null, 2))
41+ u.firstPlug(exports.message_confirm, meta, sbot)
3642 }})))
3743
3844 suggest(ta, function (word, cb) {
3945 cont.para(exports.suggest.map(function (fn) {
@@ -46,9 +52,8 @@
4652 }, []).sort(function (a, b) {
4753 return b.rank - a.rank
4854 }).filter(Boolean)
4955
50- console.log('RESULTS', results)
5156 cb(null, results)
5257 })
5358 }, {})
5459
@@ -56,4 +61,5 @@
5661
5762 }
5863
5964
65+
modules/crypto.jsView
@@ -1,7 +1,7 @@
1-
21 var path = require('path')
32 var ssbKeys = require('ssb-keys')
3+var ref = require('ssb-ref')
44 var config = require('ssb-config/inject')(process.env.ssb_appname)
55 var keys = ssbKeys
66 .loadSync(path.join(config.path, 'secret'))
77
@@ -30,8 +30,25 @@
3030 else
3131 return unbox_value(msg)
3232 }
3333
34+exports.message_box = function (content) {
35+ return ssbKeys.box(content, content.recps.map(function (e) {
36+ return ref.isFeed(e) ? e : e.link
37+ }))
38+}
39+
3440 exports.message_meta = function (msg) {
3541 if(msg.value.private)
3642 return "PRIVATE"
3743 }
44+
45+exports.publish = function (content, id, sbot) {
46+ if(content.recps)
47+ content = exports.message_box(content)
48+ sbot.publish(content, function (err, msg) {
49+ if(err) throw err
50+ console.log('PUBLISHED', msg)
51+ })
52+}
53+
54+
modules/follow.jsView
@@ -8,11 +8,9 @@
88
99 if(msg.value.content.type == 'contact') {
1010 return h('div.contact',
1111 'follows',
12- u.first(exports.avatar, function (plug) {
13- return plug(msg.value.content.contact, sbot)
14- })
12+ u.firstPlug(exports.avatar, msg.value.content.contact, sbot)
1513 )
1614 }
1715 }
1816
@@ -20,4 +18,6 @@
2018
2119
2220
2321
22+
23+
modules/like.jsView
@@ -2,8 +2,9 @@
22 var h = require('hyperscript')
33 var u = require('../util')
44 var pull = require('pull-stream')
55
6+exports.message_confirm = []
67 exports.message_link = []
78
89 exports.message_content = function (msg, sbot) {
910 if(msg.value.content.type !== 'vote') return
@@ -26,9 +27,8 @@
2627 yupps.textContent = ' ' + votes.length + ' yupps'
2728 })
2829 )
2930
30-
3131 return yupps
3232 }
3333
3434 exports.message_action = function (msg, sbot) {
@@ -45,9 +45,9 @@
4545 yup.private = true
4646 }
4747 //TODO: actually publish...
4848
49- alert(JSON.stringify(yup, null, 2))
49+ u.firstPlug(exports.message_confirm, yup, sbot)
5050 }}, 'yup')
5151
5252 }
5353
modules/main.jsView
@@ -7,9 +7,9 @@
77 exports.screen_view = function (path, sbot) {
88 if(path === '/') {
99 var content = h('div.column')
1010 var div = h('div.column', {style: {'overflow':'auto'}},
11- u.decorate(exports.message_compose, {}, function (d, e, v) {
11+ u.decorate(exports.message_compose, {type: 'post'}, function (d, e, v) {
1212 return d(e, v, sbot)
1313 }),
1414 content
1515 )
modules/message.jsView
@@ -2,11 +2,9 @@
22 var u = require('../util')
33 var pull = require('pull-stream')
44
55 exports.message_render = function (msg, sbot) {
6- var el = u.first(exports.message_content, function (fn) {
7- return fn(msg, sbot)
8- })
6+ var el = u.firstPlug(exports.message_content, msg, sbot)
97
108 function map (plugs, value) {
119 return plugs.map(function (plug) {
1210 return plug(value, sbot)
modules/private.jsView
@@ -4,11 +4,9 @@
44 var pull = require('pull-stream')
55 var Scroller = require('pull-scroll')
66
77 function unbox(msg) {
8- return u.first(exports.message_unbox, function (fn) {
9- return fn(msg)
10- })
8+ return u.firstPlug(exports.message_unbox, msg)
119 }
1210
1311 exports.screen_view = function (path, sbot) {
1412 if(path === '/private') {
@@ -46,4 +44,5 @@
4644 exports.message_compose = []
4745 exports.message_unbox = []
4846
4947
48+
modules/tabs.jsView
@@ -11,11 +11,9 @@
1111 }
1212
1313 exports.app = function (_, sbot) {
1414 function screen (path) {
15- return u.first(exports.screen_view, function (fn) {
16- return fn(path, sbot)
17- })
15+ return u.firstPlug(exports.screen_view, path, sbot)
1816 }
1917
2018 var tabs = Tabs()
2119 tabs.classList.add('screen')
@@ -47,4 +45,5 @@
4745 exports.message_render = []
4846 exports.screen_view = []
4947
5048
49+
modules/thread.jsView
@@ -35,11 +35,9 @@
3535 ]), pull.collect(cb))
3636 }
3737
3838 function unbox(msg) {
39- return u.first(exports.message_unbox, function (fn) {
40- return fn(msg)
41- })
39+ return u.firstPlug(exports.message_unbox, msg)
4240 }
4341
4442 exports.screen_view = function (id, sbot) {
4543 if(ref.isMsg(id)) {
@@ -57,17 +55,16 @@
5755 })
5856
5957 var branches = sort.heads(thread)
6058 var meta = {
59+ type: 'post',
6160 root: id,
6261 branch: branches.length > 1 ? branches : branches[0]
6362 }
6463 var recps = thread[0].value.content.recps
6564 if(recps && thread[0].value.private)
6665 meta.recps = recps
6766
68- console.log('recipients', thread[0].value.content.recps)
69-
7067 div.appendChild(
7168 h('div',
7269 u.decorate(exports.message_compose, meta, function (d, e, v) {
7370 return d(e, v, sbot)
@@ -85,4 +82,6 @@
8582 exports.message_unbox = []
8683
8784
8885
86+
87+

Built with git-ssb-web