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