Commit 9d629c55b19f5dc728643731fffb36dac23c0eca
add follow messages, and "yup" button
Dominic Tarr committed on 5/16/2016, 9:32:07 AMParent: 00b7dc676f3599b4be16806c7ce93abbd9c724c5
Files changed
modules/like.js | changed |
modules/message-link.js | changed |
modules/message.js | changed |
modules/follow.js | added |
modules/like.js | ||
---|---|---|
@@ -1,15 +1,27 @@ | ||
1 | 1 | |
2 | 2 | var h = require('hyperscript') |
3 | 3 | var u = require('../util') |
4 | 4 | |
5 | +exports.message_link = [] | |
6 | + | |
5 | 7 | exports.message_content = function (msg, sbot) { |
6 | 8 | if(msg.value.content.type !== 'vote') return |
7 | 9 | var link = msg.value.content.vote.link |
8 | 10 | return h('div', msg.value.content.vote.value > 0 ? 'yup' : 'nah', |
9 | 11 | u.decorate(exports.message_link, link, function (d, e, v) { return d(e, v, sbot) }) |
10 | 12 | ) |
11 | 13 | } |
12 | 14 | |
13 | -exports.message_link = [] | |
15 | +exports.message_action = function (msg, sbot) { | |
16 | + if(msg.value.content.type !== 'vote') | |
17 | + return h('a', {href: '#', onclick: function () { | |
18 | + var yup = { | |
19 | + type: 'vote', | |
20 | + vote: { link: msg.key, value: 1, expression: 'yup' } | |
21 | + } | |
22 | + //TODO: actually publish... | |
14 | 23 | |
24 | + alert(JSON.stringify(yup, null, 2)) | |
25 | + }}, 'yup') | |
15 | 26 | |
27 | +} |
modules/message-link.js | ||
---|---|---|
@@ -1,19 +1,16 @@ | ||
1 | 1 | var h = require('hyperscript') |
2 | 2 | |
3 | 3 | exports.message_link = function (el, id, sbot) { |
4 | - console.log('MESSAGE_LINK', el, id) | |
5 | 4 | if(el) return el |
6 | 5 | |
7 | 6 | var link = h('a', {href: '#'+id}, id.substring(0, 10)+'...') |
8 | 7 | |
9 | 8 | sbot.get(id, function (err, value) { |
10 | 9 | if(err) return |
11 | - console.log('LINKED', value) | |
12 | 10 | if(value.content.text) |
13 | 11 | link.textContent = value.content.text.substring(0, 40)+'...' |
14 | 12 | }) |
15 | 13 | |
16 | 14 | return link |
17 | 15 | } |
18 | 16 | |
19 | - |
modules/message.js | ||
---|---|---|
@@ -6,10 +6,8 @@ | ||
6 | 6 | var el = u.first(exports.message_content, function (fn) { |
7 | 7 | return fn(msg, sbot) |
8 | 8 | }) |
9 | 9 | |
10 | - if(el) console.log(el) | |
11 | - | |
12 | 10 | function map (plugs, value) { |
13 | 11 | return plugs.map(function (plug) { |
14 | 12 | return plug(value, sbot) |
15 | 13 | }).filter(Boolean) |
@@ -36,9 +34,9 @@ | ||
36 | 34 | h('div.message_meta.row', map(exports.message_meta, msg)) |
37 | 35 | ), |
38 | 36 | h('div.message_content', el), |
39 | 37 | h('div.message_actions.row', |
40 | - h('div.actions', map(exports.message_action)) | |
38 | + h('div.actions', map(exports.message_action, msg)) | |
41 | 39 | ), |
42 | 40 | backlinks |
43 | 41 | ) |
44 | 42 | } |
@@ -47,4 +45,5 @@ | ||
47 | 45 | exports.avatar = [] |
48 | 46 | exports.message_meta = [] |
49 | 47 | exports.message_action = [] |
50 | 48 | exports.message_link = [] |
49 | + |
modules/follow.js | ||
---|---|---|
@@ -1,0 +1,23 @@ | ||
1 | +var h = require('hyperscript') | |
2 | +var u = require('../util') | |
3 | +exports.avatar = [] | |
4 | + | |
5 | +//render a message when someone follows someone, | |
6 | +//so you see new users | |
7 | +exports.message_content = function (msg, sbot) { | |
8 | + | |
9 | + if(msg.value.content.type == 'contact') { | |
10 | + return h('div.contact', | |
11 | + 'follows', | |
12 | + u.first(exports.avatar, function (plug) { | |
13 | + return plug(msg.value.content.contact, sbot) | |
14 | + }) | |
15 | + ) | |
16 | + } | |
17 | +} | |
18 | + | |
19 | + | |
20 | + | |
21 | + | |
22 | + | |
23 | + |
Built with git-ssb-web