git ssb

16+

Dominic / patchbay



Tree: ab55d44678ee1d8dd109f6663adcc9f5568d91a5

Files: ab55d44678ee1d8dd109f6663adcc9f5568d91a5 / modules_basic / private.js

2625 bytesRaw
1var h = require('hyperscript')
2var u = require('../util')
3var pull = require('pull-stream')
4var Scroller = require('pull-scroll')
5var ref = require('ssb-ref')
6
7var plugs = require('../plugs')
8
9var message_render = plugs.first(exports.message_render = [])
10var message_compose = plugs.first(exports.message_compose = [])
11var message_unbox = plugs.first(exports.message_unbox = [])
12var sbot_log = plugs.first(exports.sbot_log = [])
13var sbot_whoami = plugs.first(exports.sbot_whoami = [])
14var avatar_image_link = plugs.first(exports.avatar_image_link = [])
15
16function 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
28exports.screen_view = function (path) {
29 if(path !== '/private') return
30
31 var div = h('div.column.scroller',
32 {style: {'overflow':'auto'}})
33
34 // if local id is different from sbot id, sbot won't have indexes of
35 // private threads
36 var id = require('../keys').id
37 sbot_whoami(function (err, feed) {
38 if (err) return console.error(err)
39 if(id !== feed.id)
40 return div.appendChild(h('h4',
41 'Private messages are not supported in the lite client.'))
42
43 var compose = message_compose(
44 {type: 'post', recps: [], private: true},
45 {
46 prepublish: function (msg) {
47 msg.recps = [id].concat(msg.mentions).filter(function (e) {
48 return ref.isFeed('string' === typeof e ? e : e.link)
49 })
50 if(!msg.recps.length)
51 throw new Error('cannot make private message without recipients - just mention the user in an at reply in the message you send')
52 return msg
53 },
54 placeholder: 'Write a private message'
55 }
56 )
57
58 var content = h('div.column.scroller__content')
59 div.appendChild(h('div.scroller__wrapper', compose, content))
60
61 pull(
62 u.next(sbot_log, {old: false, limit: 100}),
63 unbox(),
64 Scroller(div, content, message_render, true, false)
65 )
66
67 pull(
68 u.next(sbot_log, {reverse: true, limit: 1000}),
69 unbox(),
70 Scroller(div, content, message_render, false, false, function (err) {
71 if(err) throw err
72 })
73 )
74 })
75
76 return div
77}
78
79function map(ary, iter) {
80 if(Array.isArray(ary)) return ary.map(iter)
81}
82
83exports.message_meta = function (msg) {
84 if(msg.value.content.recps || msg.value.private)
85 return h('span.row', 'PRIVATE', map(msg.value.content.recps, function (id) {
86 return avatar_image_link('string' == typeof id ? id : id.link, 'thumbnail')
87 }))
88}
89
90
91
92
93

Built with git-ssb-web