Files: 1695b03758638d03b6a1920872fefb8315120b24 / modules / private.js
2395 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 avatar_image_link = plugs.first(exports.avatar_image_link = []) |
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 | |
30 | if(path === '/private') { |
31 | if(process.title === 'browser') |
32 | return h('div', h('h4', 'Private messages are not supported in the lite client.')) |
33 | |
34 | |
35 | var id = require('../keys').id |
36 | var compose = message_compose( |
37 | {type: 'post', recps: [], private: true}, |
38 | { |
39 | prepublish: function (msg) { |
40 | msg.recps = [id].concat(msg.mentions).filter(function (e) { |
41 | return ref.isFeed('string' === typeof e ? e : e.link) |
42 | }) |
43 | if(!msg.recps.length) |
44 | throw new Error('cannot make private message without recipients - just mention the user in an at reply in the message you send') |
45 | return msg |
46 | }, |
47 | placeholder: 'Write a private message' |
48 | } |
49 | ) |
50 | |
51 | var content = h('div.column.scroller__content') |
52 | var div = h('div.column.scroller', |
53 | {style: {'overflow':'auto'}}, |
54 | h('div.scroller__wrapper', compose, content) |
55 | ) |
56 | |
57 | pull( |
58 | sbot_log({old: false}), |
59 | unbox(), |
60 | Scroller(div, content, message_render, true, false) |
61 | ) |
62 | |
63 | pull( |
64 | u.next(sbot_log, {reverse: true, limit: 1000}), |
65 | unbox(), |
66 | Scroller(div, content, message_render, false, false, function (err) { |
67 | if(err) throw err |
68 | }) |
69 | ) |
70 | |
71 | return div |
72 | } |
73 | } |
74 | |
75 | function map(ary, iter) { |
76 | if(Array.isArray(ary)) return ary.map(iter) |
77 | } |
78 | |
79 | exports.message_meta = function (msg) { |
80 | if(msg.value.content.recps || msg.value.private) |
81 | return h('span.row', 'PRIVATE', map(msg.value.content.recps, function (id) { |
82 | return avatar_image_link('string' == typeof id ? id : id.link, 'thumbnail') |
83 | })) |
84 | } |
85 | |
86 | |
87 | |
88 |
Built with git-ssb-web