Commit 0317853c50ffacda585e8b019f18d3b8ff32329a
tidy up plugin pattern with firstPlug method, and implement message confirmation screen
Dominic Tarr committed on 5/17/2016, 9:40:27 PMParent: b37724d400c1859d22e995622281817db4d79249
Files changed
modules/avatar.js | changed |
modules/compose.js | changed |
modules/crypto.js | changed |
modules/follow.js | changed |
modules/like.js | changed |
modules/main.js | changed |
modules/message.js | changed |
modules/private.js | changed |
modules/tabs.js | changed |
modules/thread.js | changed |
modules/avatar.js | ||
---|---|---|
@@ -2,11 +2,13 @@ | ||
2 | 2 | var h = require('hyperscript') |
3 | 3 | var u = require('../util') |
4 | 4 | |
5 | 5 | 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 | + ) | |
9 | 10 | } |
10 | 11 | |
11 | 12 | exports.avatar_name = [] |
12 | 13 | |
14 | + |
modules/compose.js | ||
---|---|---|
@@ -1,15 +1,21 @@ | ||
1 | 1 | var h = require('hyperscript') |
2 | +var u = require('../util') | |
2 | 3 | var suggest = require('suggest-box') |
3 | 4 | var cont = require('cont') |
4 | 5 | var mentions = require('ssb-mentions') |
6 | +var lightbox = require('hyperlightbox') | |
7 | + | |
5 | 8 | exports.suggest = [] |
9 | +exports.publish = [] | |
10 | +exports.message_content = [] | |
6 | 11 | |
7 | 12 | //this decorator expects to be the first |
8 | 13 | exports.message_compose = function (el, meta, sbot) { |
9 | 14 | if(el) return el |
10 | 15 | |
11 | 16 | meta = meta || {} |
17 | + if(!meta.type) throw new Error('message must have type') | |
12 | 18 | var ta = h('textarea') |
13 | 19 | //h('pre.editable.fixed', 'HELLO') |
14 | 20 | //ta.setAttribute('contenteditable', '') |
15 | 21 | |
@@ -31,9 +37,9 @@ | ||
31 | 37 | h('div', h('div.column', ta, |
32 | 38 | h('button', 'publish', {onclick: function () { |
33 | 39 | meta.text = ta.value |
34 | 40 | meta.mentions = mentions(ta.value) |
35 | - alert(JSON.stringify(meta, null, 2)) | |
41 | + u.firstPlug(exports.message_confirm, meta, sbot) | |
36 | 42 | }}))) |
37 | 43 | |
38 | 44 | suggest(ta, function (word, cb) { |
39 | 45 | cont.para(exports.suggest.map(function (fn) { |
@@ -46,9 +52,8 @@ | ||
46 | 52 | }, []).sort(function (a, b) { |
47 | 53 | return b.rank - a.rank |
48 | 54 | }).filter(Boolean) |
49 | 55 | |
50 | - console.log('RESULTS', results) | |
51 | 56 | cb(null, results) |
52 | 57 | }) |
53 | 58 | }, {}) |
54 | 59 | |
@@ -56,4 +61,5 @@ | ||
56 | 61 | |
57 | 62 | } |
58 | 63 | |
59 | 64 | |
65 | + |
modules/crypto.js | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | - | |
2 | 1 | var path = require('path') |
3 | 2 | var ssbKeys = require('ssb-keys') |
3 | +var ref = require('ssb-ref') | |
4 | 4 | var config = require('ssb-config/inject')(process.env.ssb_appname) |
5 | 5 | var keys = ssbKeys |
6 | 6 | .loadSync(path.join(config.path, 'secret')) |
7 | 7 | |
@@ -30,8 +30,25 @@ | ||
30 | 30 | else |
31 | 31 | return unbox_value(msg) |
32 | 32 | } |
33 | 33 | |
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 | + | |
34 | 40 | exports.message_meta = function (msg) { |
35 | 41 | if(msg.value.private) |
36 | 42 | return "PRIVATE" |
37 | 43 | } |
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.js | ||
---|---|---|
@@ -8,11 +8,9 @@ | ||
8 | 8 | |
9 | 9 | if(msg.value.content.type == 'contact') { |
10 | 10 | return h('div.contact', |
11 | 11 | '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) | |
15 | 13 | ) |
16 | 14 | } |
17 | 15 | } |
18 | 16 | |
@@ -20,4 +18,6 @@ | ||
20 | 18 | |
21 | 19 | |
22 | 20 | |
23 | 21 | |
22 | + | |
23 | + |
modules/like.js | ||
---|---|---|
@@ -2,8 +2,9 @@ | ||
2 | 2 | var h = require('hyperscript') |
3 | 3 | var u = require('../util') |
4 | 4 | var pull = require('pull-stream') |
5 | 5 | |
6 | +exports.message_confirm = [] | |
6 | 7 | exports.message_link = [] |
7 | 8 | |
8 | 9 | exports.message_content = function (msg, sbot) { |
9 | 10 | if(msg.value.content.type !== 'vote') return |
@@ -26,9 +27,8 @@ | ||
26 | 27 | yupps.textContent = ' ' + votes.length + ' yupps' |
27 | 28 | }) |
28 | 29 | ) |
29 | 30 | |
30 | - | |
31 | 31 | return yupps |
32 | 32 | } |
33 | 33 | |
34 | 34 | exports.message_action = function (msg, sbot) { |
@@ -45,9 +45,9 @@ | ||
45 | 45 | yup.private = true |
46 | 46 | } |
47 | 47 | //TODO: actually publish... |
48 | 48 | |
49 | - alert(JSON.stringify(yup, null, 2)) | |
49 | + u.firstPlug(exports.message_confirm, yup, sbot) | |
50 | 50 | }}, 'yup') |
51 | 51 | |
52 | 52 | } |
53 | 53 |
modules/main.js | ||
---|---|---|
@@ -7,9 +7,9 @@ | ||
7 | 7 | exports.screen_view = function (path, sbot) { |
8 | 8 | if(path === '/') { |
9 | 9 | var content = h('div.column') |
10 | 10 | 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) { | |
12 | 12 | return d(e, v, sbot) |
13 | 13 | }), |
14 | 14 | content |
15 | 15 | ) |
modules/message.js | ||
---|---|---|
@@ -2,11 +2,9 @@ | ||
2 | 2 | var u = require('../util') |
3 | 3 | var pull = require('pull-stream') |
4 | 4 | |
5 | 5 | 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) | |
9 | 7 | |
10 | 8 | function map (plugs, value) { |
11 | 9 | return plugs.map(function (plug) { |
12 | 10 | return plug(value, sbot) |
modules/private.js | ||
---|---|---|
@@ -4,11 +4,9 @@ | ||
4 | 4 | var pull = require('pull-stream') |
5 | 5 | var Scroller = require('pull-scroll') |
6 | 6 | |
7 | 7 | 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) | |
11 | 9 | } |
12 | 10 | |
13 | 11 | exports.screen_view = function (path, sbot) { |
14 | 12 | if(path === '/private') { |
@@ -46,4 +44,5 @@ | ||
46 | 44 | exports.message_compose = [] |
47 | 45 | exports.message_unbox = [] |
48 | 46 | |
49 | 47 | |
48 | + |
modules/tabs.js | ||
---|---|---|
@@ -11,11 +11,9 @@ | ||
11 | 11 | } |
12 | 12 | |
13 | 13 | exports.app = function (_, sbot) { |
14 | 14 | 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) | |
18 | 16 | } |
19 | 17 | |
20 | 18 | var tabs = Tabs() |
21 | 19 | tabs.classList.add('screen') |
@@ -47,4 +45,5 @@ | ||
47 | 45 | exports.message_render = [] |
48 | 46 | exports.screen_view = [] |
49 | 47 | |
50 | 48 | |
49 | + |
modules/thread.js | ||
---|---|---|
@@ -35,11 +35,9 @@ | ||
35 | 35 | ]), pull.collect(cb)) |
36 | 36 | } |
37 | 37 | |
38 | 38 | 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) | |
42 | 40 | } |
43 | 41 | |
44 | 42 | exports.screen_view = function (id, sbot) { |
45 | 43 | if(ref.isMsg(id)) { |
@@ -57,17 +55,16 @@ | ||
57 | 55 | }) |
58 | 56 | |
59 | 57 | var branches = sort.heads(thread) |
60 | 58 | var meta = { |
59 | + type: 'post', | |
61 | 60 | root: id, |
62 | 61 | branch: branches.length > 1 ? branches : branches[0] |
63 | 62 | } |
64 | 63 | var recps = thread[0].value.content.recps |
65 | 64 | if(recps && thread[0].value.private) |
66 | 65 | meta.recps = recps |
67 | 66 | |
68 | - console.log('recipients', thread[0].value.content.recps) | |
69 | - | |
70 | 67 | div.appendChild( |
71 | 68 | h('div', |
72 | 69 | u.decorate(exports.message_compose, meta, function (d, e, v) { |
73 | 70 | return d(e, v, sbot) |
@@ -85,4 +82,6 @@ | ||
85 | 82 | exports.message_unbox = [] |
86 | 83 | |
87 | 84 | |
88 | 85 | |
86 | + | |
87 | + |
Built with git-ssb-web