git ssb

2+

ev / mvd



Commit 49ecefe8720bc3af7ddca1a70870bdbadceae6da

add avatar and render names in messages

Ev Bogue committed on 4/20/2018, 5:22:43 PM
Parent: 0e8e68d5d7edfdd09971641b1a78d06fa733a06c

Files changed

package.jsonchanged
render.jschanged
avatar.jsadded
package.jsonView
@@ -36,7 +36,8 @@
3636 "ssb-keys": "^7.0.14",
3737 "ssb-links": "^3.0.3",
3838 "ssb-markdown": "^3.6.0",
3939 "ssb-query": "^2.0.1",
40- "ssb-ref": "^2.9.1"
40 + "ssb-ref": "^2.9.1",
41 + "visualize-buffer": "0.0.1"
4142 }
4243 }
render.jsView
@@ -1,15 +1,15 @@
11 var h = require('hyperscript')
22
33 var human = require('human-time')
44
5-var markdown = require('ssb-markdown')
5 +var avatar = require('./avatar')
66
77 module.exports = function (msg) {
88 if (msg.value.content.type == 'post') {
99 return h('div.message__content',
1010 h('span.timestamp', h('a', {href: msg.key}, human(new Date(msg.value.timestamp)))),
11- msg.value.author,
11 + avatar.name(msg.value.author),
1212 msg.value.content.text
1313 )
1414 } else { return }
1515 }
avatar.jsView
@@ -1,0 +1,50 @@
1 +var pull = require('pull-stream')
2 +var query = require('./scuttlebot').query
3 +var h = require('hyperscript')
4 +var visualize = require('visualize-buffer')
5 +
6 +var config = require('./config')()
7 +
8 +module.exports.name = function (id) {
9 +
10 + var name = h('span', id.substring(0, 10))
11 + if (localStorage[id + 'name'])
12 + name.textContent = localStorage[id + 'name']
13 + else
14 + pull(query({query: [{$filter: { value: { author: id, content: {type: 'about', about: id, name: {'$truthy': true}}}}}], reverse: true}),
15 + pull.collect(function (err, data){
16 + if(data[0]) {
17 + localStorage[id + 'name'] = '@' + data[0].value.content.name
18 + name.textContent = localStorage[id + 'name']
19 + }
20 + }))
21 + return name
22 +}
23 +
24 +var ref = require('ssb-ref')
25 +
26 +module.exports.image = function (id) {
27 + var img = visualize(new Buffer(id.substring(1), 'base64'), 256)
28 +
29 + if (localStorage[id + 'image'])
30 + img.src = localStorage[id + 'image']
31 + else
32 + pull(query({query: [{$filter: { value: { author: id, content: {type: 'about', about: id, image: {'$truthy': true}}}}}], reverse: true}),
33 + pull.collect(function (err, data){
34 + if(data[0]) {
35 + if (ref.isBlob(data[0].value.content.image.link)) {
36 + var data = config.blobsUrl + data[0].value.content.image.link
37 + localStorage[id + 'image'] = data
38 + img.src = data
39 + } else if (ref.isBlob(data[0].value.content.image)) {
40 + var data = config.blobsUrl + data[0].value.content.image
41 + localStorage[id + 'image'] = data
42 + img.src = data
43 + }
44 + }
45 + })
46 + )
47 +
48 + return img
49 +}
50 +

Built with git-ssb-web