Files: 9a90757d9b3b08602cfc1aaf8d1b507d15a23d94 / modules / private.js
1986 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 | |
15 | function unbox () { |
16 | return pull( |
17 | pull.filter(function (msg) { |
18 | return 'string' == typeof msg.value.content |
19 | }), |
20 | pull.map(function (msg) { |
21 | return message_unbox(msg) |
22 | }), |
23 | pull.filter(Boolean) |
24 | ) |
25 | } |
26 | |
27 | exports.screen_view = function (path) { |
28 | |
29 | if(path === '/private') { |
30 | if(process.title === 'browser') |
31 | return h('div', h('h4', 'Private messages are not supported in the lite client.')) |
32 | |
33 | |
34 | var id = require('../keys').id |
35 | var compose = message_compose( |
36 | {type: 'post', recps: [], private: true}, |
37 | function (msg) { |
38 | msg.recps = [id].concat(msg.mentions).filter(function (e) { |
39 | return ref.isFeed('string' === typeof e ? e : e.link) |
40 | }) |
41 | if(!msg.recps.length) |
42 | throw new Error('cannot make private message without recipients - just mention the user in an at reply in the message you send') |
43 | return msg |
44 | }) |
45 | |
46 | var content = h('div.column.scroller__content') |
47 | var div = h('div.column.scroller', |
48 | {style: {'overflow':'auto'}}, |
49 | h('div.scroller__wrapper', compose, content) |
50 | ) |
51 | |
52 | pull( |
53 | sbot_log({old: false}), |
54 | unbox(), |
55 | Scroller(div, content, message_render, true, false) |
56 | ) |
57 | |
58 | pull( |
59 | u.next(sbot_log, {reverse: true, limit: 1000}), |
60 | unbox(), |
61 | Scroller(div, content, message_render, false, false, function (err) { |
62 | if(err) throw err |
63 | }) |
64 | ) |
65 | |
66 | return div |
67 | } |
68 | } |
69 | |
70 | exports.message_meta = function (msg) { |
71 | if(msg.value.private) |
72 | return h('span', 'PRIVATE') |
73 | } |
74 | |
75 |
Built with git-ssb-web