git ssb

16+

Dominic / patchbay



Tree: 9e65f9951f21778ee286834004367aa2b46bc882

Files: 9e65f9951f21778ee286834004367aa2b46bc882 / modules / private.js

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

Built with git-ssb-web