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