Files: fda7646d7f7350bad33616d4c754cb86951af6e7 / modules / private.js
1827 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 content = h('div.column') |
31 | var id = null |
32 | sbot_whoami(function (err, me) { |
33 | id = me.id |
34 | }) |
35 | |
36 | var div = h('div.column', {style: {'overflow':'auto'}}, |
37 | message_compose({type: 'post', recps: [], private: true}, |
38 | function (msg) { |
39 | msg.recps = [id].concat(msg.mentions).filter(function (e) { |
40 | return ref.isFeed('string' === typeof e ? e : e.link) |
41 | }) |
42 | if(!msg.recps.length) |
43 | throw new Error('cannot make private message without recipients - just mention them in the message') |
44 | return msg |
45 | }), |
46 | content) |
47 | |
48 | pull( |
49 | sbot_log({old: false}), |
50 | unbox(), |
51 | Scroller(div, content, message_render, true, false) |
52 | ) |
53 | |
54 | pull( |
55 | u.next(sbot_log, {reverse: true, limit: 1000}), |
56 | unbox(), |
57 | Scroller(div, content, message_render, false, false, function (err) { |
58 | if(err) throw err |
59 | }) |
60 | ) |
61 | |
62 | return div |
63 | } |
64 | } |
65 | |
66 | exports.message_meta = function (msg) { |
67 | if(msg.value.private) |
68 | return "PRIVATE" |
69 | } |
70 | |
71 | |
72 |
Built with git-ssb-web