git ssb

0+

ev / minbase



Tree: a82d9b053001af225a6db818036079f377f481d0

Files: a82d9b053001af225a6db818036079f377f481d0 / modules / helpers-private.js

1518 bytesRaw
1var ref = require('ssb-ref')
2var keys = require('../keys')
3var ssbKeys = require('ssb-keys')
4var publish = require('./scuttlebot').publish
5
6function unbox_value(msg) {
7 var plaintext = ssbKeys.unbox(msg.content, keys)
8 if(!plaintext) return null
9 return {
10 previous: msg.previous,
11 author: msg.author,
12 sequence: msg.sequence,
13 timestamp: msg.timestamp,
14 hash: msg.hash,
15 content: plaintext,
16 private: true
17 }
18}
19
20module.exports.unbox = function (msg) {
21 if(msg.value) {
22 var value = unbox_value(msg.value)
23 if(value) {
24 return {
25 key: msg.key, value: value, timestamp: msg.timestamp
26 }
27 }
28 } else {
29 return unbox_value(msg)
30 }
31}
32
33module.exports.box = function (content) {
34 return ssbKeys.box(content, content.recps.map(function (e) {
35 return ref.isFeed(e) ? e : e.link
36 }))
37}
38
39module.exports.publish = function (content, cb) {
40 if(content.recps)
41 content = exports.box(content)
42 publish(content, function (err, msg) {
43 if(err) throw err
44 console.log('Published!', msg)
45 if(cb) cb(err, msg)
46 })
47}
48
49var h = require('hyperscript')
50
51module.exports.getrecps = function (msg) {
52
53 function map(ary, iter) {
54 if(Array.isArray(ary)) return ary.map(iter)
55 }
56
57 if(msg.value.content.recps || msg.value.private) {
58 return h('span.row', 'PRIVATE', map(msg.value.content.recps, function (id) {
59 return h('div.avatar--thumbnail', avatar.image(id))
60 //api.avatar_image_link('string' == typeof id ? id : id.link, 'thumbnail')
61 }))
62 }
63}
64

Built with git-ssb-web