Files: 72483d41ff0fbb76209ef40a0cdcf91409b6db7f / modules / private.js
2118 bytesRaw
1 | var h = require('hyperscript') |
2 | var ui = require('../ui') |
3 | var u = require('../util') |
4 | var pull = require('pull-stream') |
5 | var Scroller = require('pull-scroll') |
6 | var ref = require('ssb-ref') |
7 | |
8 | var plugs = require('../plugs') |
9 | |
10 | var message_render = plugs.first(exports.message_render = []) |
11 | var message_compose = plugs.first(exports.message_compose = []) |
12 | var message_unbox = plugs.first(exports.message_unbox = []) |
13 | var sbot_log = plugs.first(exports.sbot_log = []) |
14 | var sbot_whoami = plugs.first(exports.sbot_whoami = []) |
15 | |
16 | function unbox () { |
17 | return pull( |
18 | pull.filter(function (msg) { |
19 | return 'string' == typeof msg.value.content |
20 | }), |
21 | pull.map(function (msg) { |
22 | return message_unbox(msg) |
23 | }), |
24 | pull.filter(Boolean) |
25 | ) |
26 | } |
27 | |
28 | exports.screen_view = function (path) { |
29 | if(path === '/private') { |
30 | var id = null |
31 | sbot_whoami(function (err, me) { |
32 | id = me.id |
33 | }) |
34 | |
35 | var div = h('div.column.scroller', |
36 | {style: {'overflow':'auto'}}, |
37 | h('div.scroller__wrapper', |
38 | message_compose({type: 'post'}), //header |
39 | content |
40 | ) |
41 | ) |
42 | |
43 | var compose = message_compose( |
44 | {type: 'post', recps: [], private: true}, |
45 | function (msg) { |
46 | msg.recps = [id].concat(msg.mentions).filter(function (e) { |
47 | return ref.isFeed('string' === typeof e ? e : e.link) |
48 | }) |
49 | if(!msg.recps.length) |
50 | throw new Error('cannot make private message without recipients - just mention them in the message') |
51 | return msg |
52 | }) |
53 | |
54 | var content = h('div.column.scroller__content') |
55 | var div = h('div.column.scroller', |
56 | {style: {'overflow':'auto'}}, |
57 | h('div.scroller__wrapper', compose, content) |
58 | ) |
59 | |
60 | pull( |
61 | sbot_log({old: false}), |
62 | unbox(), |
63 | Scroller(div, content, message_render, true, false) |
64 | ) |
65 | |
66 | pull( |
67 | u.next(sbot_log, {reverse: true, limit: 1000}), |
68 | unbox(), |
69 | Scroller(div, content, message_render, false, false, function (err) { |
70 | if(err) throw err |
71 | }) |
72 | ) |
73 | |
74 | return div |
75 | } |
76 | } |
77 | |
78 | exports.message_meta = function (msg) { |
79 | if(msg.value.private) |
80 | return "PRIVATE" |
81 | } |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 |
Built with git-ssb-web