Files: 697e3e1780dfe42cdc94d4e26e2788489ddfb896 / modules_basic / private.js
2964 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 sbot_whoami = plugs.first(exports.sbot_whoami = []) |
14 | var avatar_image_link = plugs.first(exports.avatar_image_link = []) |
15 | var emoji_url = plugs.first(exports.emoji_url = []) |
16 | |
17 | function unbox () { |
18 | return pull( |
19 | pull.filter(function (msg) { |
20 | return 'string' == typeof msg.value.content |
21 | }), |
22 | pull.map(function (msg) { |
23 | return message_unbox(msg) |
24 | }), |
25 | pull.filter(Boolean) |
26 | ) |
27 | } |
28 | |
29 | exports.builtin_tabs = function () { |
30 | return ['/private'] |
31 | } |
32 | |
33 | exports.screen_view = function (path) { |
34 | if(path !== '/private') return |
35 | |
36 | var div = h('div.column.scroller', |
37 | {style: {'overflow':'auto'}}) |
38 | |
39 | // if local id is different from sbot id, sbot won't have indexes of |
40 | // private threads |
41 | var id = require('../keys').id |
42 | sbot_whoami(function (err, feed) { |
43 | if (err) return console.error(err) |
44 | if(id !== feed.id) |
45 | return div.appendChild(h('h4', |
46 | 'Private messages are not supported in the lite client.')) |
47 | |
48 | var compose = message_compose( |
49 | {type: 'post', recps: [], private: true}, |
50 | { |
51 | prepublish: function (msg) { |
52 | msg.recps = [id].concat(msg.mentions).filter(function (e) { |
53 | return ref.isFeed('string' === typeof e ? e : e.link) |
54 | }) |
55 | if(!msg.recps.length) |
56 | throw new Error('cannot make private message without recipients - just mention the user in an at reply in the message you send') |
57 | return msg |
58 | }, |
59 | placeholder: 'Write a private message' |
60 | } |
61 | ) |
62 | |
63 | var content = h('div.column.scroller__content') |
64 | div.appendChild(h('div.scroller__wrapper', compose, content)) |
65 | |
66 | pull( |
67 | u.next(sbot_log, {old: false, limit: 100}), |
68 | unbox(), |
69 | Scroller(div, content, message_render, true, false) |
70 | ) |
71 | |
72 | pull( |
73 | u.next(sbot_log, {reverse: true, limit: 1000}), |
74 | unbox(), |
75 | Scroller(div, content, message_render, false, false, function (err) { |
76 | if(err) throw err |
77 | }) |
78 | ) |
79 | }) |
80 | |
81 | return div |
82 | } |
83 | |
84 | function map(ary, iter) { |
85 | if(Array.isArray(ary)) return ary.map(iter) |
86 | } |
87 | |
88 | exports.message_meta = function (msg) { |
89 | if(msg.value.content.recps || msg.value.private) |
90 | return h('span.row', 'PRIVATE', map(msg.value.content.recps, function (id) { |
91 | return avatar_image_link('string' == typeof id ? id : id.link, 'thumbnail') |
92 | })) |
93 | } |
94 | |
95 | exports.message_content_mini = function (msg, sbot) { |
96 | if (typeof msg.value.content === 'string') { |
97 | var icon = emoji_url('lock') |
98 | return icon |
99 | ? h('img', {className: 'emoji', src: icon}) |
100 | : 'PRIVATE' |
101 | } |
102 | } |
103 | |
104 | |
105 | |
106 |
Built with git-ssb-web