Files: da116a36a6e34b4499633c0a896b9bf32d263383 / modules_basic / private.js
2388 bytesRaw
1 | var h = require('hyperscript') |
2 | var u = require('../util') |
3 | var pull = require('pull-stream') |
4 | var Scroller = require('pull-scroll') |
5 | var ref = require('ssb-ref') |
6 | |
7 | var plugs = require('../plugs') |
8 | |
9 | var message_render = plugs.first(exports.message_render = []) |
10 | var message_compose = plugs.first(exports.message_compose = []) |
11 | var message_unbox = plugs.first(exports.message_unbox = []) |
12 | var sbot_log = plugs.first(exports.sbot_log = []) |
13 | var avatar_image_link = plugs.first(exports.avatar_image_link = []) |
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 | { |
38 | prepublish: 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 the user in an at reply in the message you send') |
44 | return msg |
45 | }, |
46 | placeholder: 'Write a private message' |
47 | } |
48 | ) |
49 | |
50 | var content = h('div.column.scroller__content') |
51 | var div = h('div.column.scroller', |
52 | {style: {'overflow':'auto'}}, |
53 | h('div.scroller__wrapper', compose, content) |
54 | ) |
55 | |
56 | pull( |
57 | u.next(sbot_log, {old: false, limit: 100}), |
58 | unbox(), |
59 | Scroller(div, content, message_render, true, false) |
60 | ) |
61 | |
62 | pull( |
63 | u.next(sbot_log, {reverse: true, limit: 1000}), |
64 | unbox(), |
65 | Scroller(div, content, message_render, false, false, function (err) { |
66 | if(err) throw err |
67 | }) |
68 | ) |
69 | |
70 | return div |
71 | } |
72 | } |
73 | |
74 | function map(ary, iter) { |
75 | if(Array.isArray(ary)) return ary.map(iter) |
76 | } |
77 | |
78 | exports.message_meta = function (msg) { |
79 | if(msg.value.content.recps || msg.value.private) |
80 | return h('span.row', 'PRIVATE', map(msg.value.content.recps, function (id) { |
81 | return avatar_image_link('string' == typeof id ? id : id.link, 'thumbnail') |
82 | })) |
83 | } |
84 | |
85 | |
86 |
Built with git-ssb-web