Files: c4e6d69c2cdcc875fc3ac222471b3c5d55810b77 / modules / helpers-private.js
1518 bytesRaw
1 | var ref = require('ssb-ref') |
2 | var keys = require('../keys') |
3 | var ssbKeys = require('ssb-keys') |
4 | var publish = require('./scuttlebot').publish |
5 | |
6 | function 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 | |
20 | module.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 | |
33 | module.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 | |
39 | module.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 | |
49 | var h = require('hyperscript') |
50 | |
51 | module.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