Files: a75e10540025af11735b3a0b2d0b438eee09e20f / modules / private.js
1650 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 | exports.message_render = [] |
9 | exports.message_compose = [] |
10 | exports.message_unbox = [] |
11 | |
12 | function unbox () { |
13 | return pull( |
14 | pull.filter(function (msg) { |
15 | return 'string' == typeof msg.value.content |
16 | }), |
17 | pull.map(function (msg) { |
18 | return u.firstPlug(exports.message_unbox, msg) |
19 | }), |
20 | pull.filter(Boolean) |
21 | ) |
22 | } |
23 | |
24 | exports.screen_view = function (path, sbot) { |
25 | if(path === '/private') { |
26 | SBOT = sbot |
27 | var content = h('div.column') |
28 | var id = null |
29 | sbot.whoami(function (err, me) { |
30 | id = me.id |
31 | }) |
32 | |
33 | var div = h('div.column', {style: {'overflow':'auto'}}, |
34 | u.firstPlug(exports.message_compose, {type: 'post', recps: [], private: true}, |
35 | function (msg) { |
36 | msg.recps = [id].concat(msg.mentions).filter(function (e) { |
37 | return ref.isFeed('string' === typeof e ? e : e.link) |
38 | }) |
39 | if(!msg.recps.length) |
40 | throw new Error('cannot make private message without recipients - just mention them in the message') |
41 | return msg |
42 | }, |
43 | sbot), |
44 | content) |
45 | var render = ui.createRenderers(exports.message_render, sbot) |
46 | |
47 | pull( |
48 | sbot.createLogStream({old: false}), |
49 | unbox(), |
50 | Scroller(div, content, render, true, false) |
51 | ) |
52 | |
53 | pull( |
54 | u.next(sbot.createLogStream, {reverse: true, limit: 1000}), |
55 | unbox(), |
56 | Scroller(div, content, render, false, false, function (err) { |
57 | if(err) throw err |
58 | }) |
59 | ) |
60 | |
61 | return div |
62 | } |
63 | } |
64 | |
65 | |
66 | |
67 | |
68 |
Built with git-ssb-web