git ssb

2+

ev / mvd



Commit 31952859d7b23b701a4475eb2318ef61010b7213

render stars with ssb-backlinks

Ev Bogue committed on 5/1/2018, 2:01:04 AM
Parent: 75a88ef69dff48f8857d5a63d03c413d76c52ce1

Files changed

bin.jschanged
manifest.jsonchanged
package-lock.jsonchanged
package.jsonchanged
render.jschanged
scuttlebot.jschanged
style.csschanged
tools.jschanged
bin.jsView
@@ -32,8 +32,9 @@
3232 .use(require('scuttlebot/plugins/replicate'))
3333 .use(require('ssb-friends'))
3434 .use(require('ssb-blobs'))
3535 .use(require('ssb-query'))
36 + .use(require('ssb-backlinks'))
3637 .use(require('ssb-links'))
3738 .use(require('ssb-ebt'))
3839 .use(require('ssb-ooo'))
3940 .use(require('scuttlebot/plugins/invite'))
manifest.jsonView
@@ -62,8 +62,12 @@
6262 "links2": {
6363 "read": "source",
6464 "dump": "source"
6565 },
66 + "backlinks": {
67 + "read": "source",
68 + "dump": "source"
69 + },
6670 "query": {
6771 "read": "source",
6872 "dump": "source"
6973 },
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 216329 bytes
New file size: 217442 bytes
package.jsonView
@@ -28,8 +28,9 @@
2828 "pull-reconnect": "0.0.3",
2929 "pull-stream": "^3.6.7",
3030 "pull-stringify": "^2.0.0",
3131 "scuttlebot": "^11.2.1",
32 + "ssb-backlinks": "^0.6.1",
3233 "ssb-blobs": "^1.1.4",
3334 "ssb-client": "^4.5.7",
3435 "ssb-ebt": "^5.1.5",
3536 "ssb-friends": "^2.4.0",
render.jsView
@@ -1,7 +1,9 @@
11 var h = require('hyperscript')
22 var config = require('./config')()
33
4 +var pull = require('pull-stream')
5 +
46 var sbot = require('./scuttlebot')
57 var composer = require('./compose')
68
79 var tools = require('./tools')
@@ -9,19 +11,28 @@
911 module.exports = function (msg) {
1012 var opts = {}
1113 opts.root = null
1214 var message = h('div.message')
15 +
16 +
1317 if (msg.value.content.type == 'post') {
14- message.appendChild(tools.header(msg))
18 +
19 +
1520 opts.type = 'post'
1621 opts.branch = msg.key
22 +
23 + message.appendChild(tools.header(msg))
24 +
1725 if (msg.value.content.root) {
1826 message.appendChild(h('span', 're: ', tools.messageLink(msg.value.content.root)))
1927 opts.root = msg.value.content.root
20- } else { opts.root = msg.key}
28 + } else { opts.root = msg.key }
29 +
30 +
2131 message.appendChild(
2232 h('div.message__body', tools.markdown(msg.value.content.text))
2333 )
34 +
2435 message.appendChild(h('button.btn', 'Reply', {
2536 onclick: function () {
2637 var compose = composer(opts)
2738 message.replaceChild(compose, message.lastElementChild)
@@ -49,10 +60,10 @@
4960 }
5061 })
5162 return message
5263 } else {
53- message.appendChild(tools.header(msg))
54- message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
55- return message
56- //return
64 + //message.appendChild(tools.header(msg))
65 + //message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
66 + //return message
67 + return
5768 }
5869 }
scuttlebot.jsView
@@ -64,8 +64,11 @@
6464 }),
6565 query: rec.source(function (query) {
6666 return sbot.query.read(query)
6767 }),
68 + backlinks: rec.source(function (query) {
69 + return sbot.backlinks.read(query)
70 + }),
6871 get: rec.async(function (key, cb) {
6972 if('function' !== typeof cb)
7073 throw new Error('cb must be function')
7174 if(CACHE[key]) cb(null, CACHE[key])
style.cssView
@@ -34,9 +34,9 @@
3434 .message img {
3535 max-width: 100%;
3636 }
3737
38-.timestamp {
38 +.timestamp, .votes {
3939 float: right;
4040 }
4141
4242 .avatar--small img {
@@ -55,9 +55,9 @@
5555 }
5656
5757 .emoji {
5858 float: left;
59- width: 1.4em;
59 + width: 1em;
6060 vertical-align: top;
6161 }
6262
6363 pre {
tools.jsView
@@ -2,8 +2,30 @@
22 var human = require('human-time')
33 var avatar = require('./avatar')
44 var ref = require('ssb-ref')
55
6 +var pull = require('pull-stream')
7 +
8 +var sbot = require('./scuttlebot')
9 +
10 +var config = require('./config')()
11 +
12 +function votes (msg) {
13 + var votes = h('div.votes')
14 +
15 + pull(
16 + sbot.backlinks({query: [{$filter: {dest: msg.key, value: { content: { type: 'vote' }}}}], live: true}),
17 + pull.drain(function (data) {
18 + console.log(data)
19 + if (data.value) {
20 + votes.appendChild(h('a', {href:'#' + data.key}, h('img.emoji', {src: config.emojiUrl + 'star.png'})))
21 + console.log(data)
22 + } else {console.log(data)}
23 + })
24 + )
25 + return votes
26 +}
27 +
628 module.exports.header = function (msg) {
729 return h('div.header',
830 h('span.avatar',
931 h('a', {href: '#' + msg.value.author},
@@ -11,8 +33,9 @@
1133 avatar.name(msg.value.author)
1234 )
1335 ),
1436 h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))),
37 + votes(msg)
1538 )
1639 }
1740
1841 module.exports.messageLink = function (msglink) {

Built with git-ssb-web