Files: f1cc08ac986f18880000b780dae6fb2043e76948 / modules / private.js
2710 bytesRaw
1 | |
2 | var h = require('hyperscript') |
3 | var u = require('../util') |
4 | var pull = require('pull-stream') |
5 | var Scroller = require('pull-scroll') |
6 | var ref = require('ssb-ref') |
7 | var log = require('./scuttlebot').log |
8 | var Unbox = require('./helpers-private').unbox |
9 | |
10 | var config = require('../config')() |
11 | |
12 | function map(ary, iter) { |
13 | if(Array.isArray(ary)) return ary.map(iter) |
14 | } |
15 | |
16 | exports.needs = { |
17 | message_render: 'first', |
18 | message_compose: 'first' |
19 | } |
20 | |
21 | exports.gives = { |
22 | screen_view: true, |
23 | message_content_mini: true |
24 | } |
25 | |
26 | exports.create = function (api) { |
27 | |
28 | function unbox () { |
29 | return pull( |
30 | pull.filter(function (msg) { |
31 | return 'string' == typeof msg.value.content |
32 | }), |
33 | pull.map(function (msg) { |
34 | return Unbox(msg) |
35 | }), |
36 | pull.filter(Boolean) |
37 | ) |
38 | } |
39 | |
40 | return { |
41 | screen_view: function (path) { |
42 | if(path === 'Private') { |
43 | var id = require('../keys').id |
44 | var compose = api.message_compose( |
45 | {type: 'post', recps: [], private: true}, |
46 | { |
47 | prepublish: function (msg) { |
48 | msg.recps = [id].concat(msg.mentions).filter(function (e) { |
49 | return ref.isFeed('string' === typeof e ? e : e.link) |
50 | }) |
51 | if(!msg.recps.length) |
52 | throw new Error('Please select at least one recipient. Use @person to select recipients in the message body.') |
53 | return msg |
54 | }, |
55 | placeholder: 'Write a private message. Use @person to select recipients.' |
56 | } |
57 | ) |
58 | |
59 | var content = h('div.column.scroller__content') |
60 | var div = h('div.column.scroller', |
61 | {style: {'overflow':'auto'}}, |
62 | h('div.scroller__wrapper', compose, content) |
63 | ) |
64 | |
65 | pull( |
66 | log({old: false}), |
67 | unbox(), |
68 | Scroller(div, content, api.message_render, true, false) |
69 | ) |
70 | |
71 | pull( |
72 | u.next(log, {reverse: true, limit: 1000}), |
73 | unbox(), |
74 | Scroller(div, content, api.message_render, false, false, function (err) { |
75 | if(err) throw err |
76 | }) |
77 | ) |
78 | |
79 | return div |
80 | } |
81 | }, |
82 | |
83 | /*message_meta: function (msg) { |
84 | if(msg.value.content.recps || msg.value.private) |
85 | return h('span.row', 'PRIVATE', map(msg.value.content.recps, function (id) { |
86 | return api.avatar_image_link('string' == typeof id ? id : id.link, 'thumbnail') |
87 | })) |
88 | },*/ |
89 | |
90 | message_content_mini: function (msg, sbot) { |
91 | if (typeof msg.value.content === 'string') { |
92 | var icon = config.emojiUrl + 'lock.png' |
93 | return icon |
94 | ? h('img', {className: 'emoji', src: icon}) |
95 | : 'PRIVATE' |
96 | } |
97 | } |
98 | } |
99 | |
100 | } |
101 | |
102 |
Built with git-ssb-web