git ssb

16+

Dominic / patchbay



Tree: f2e0672ea2122a0681f222b03f03d0e227303352

Files: f2e0672ea2122a0681f222b03f03d0e227303352 / modules_basic / private.js

2392 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 avatar_image_link = plugs.first(exports.avatar_image_link = [])
14
15function unbox () {
16 return pull(
17 pull.filter(function (msg) {
18 return 'string' == typeof msg.value.content
19 }),
20 pull.map(function (msg) {
21 return message_unbox(msg)
22 }),
23 pull.filter(Boolean)
24 )
25}
26
27exports.screen_view = function (path) {
28
29 if(path === '/private') {
30 //if(process.title === 'browser')
31 //return h('div', h('h4', 'Private messages are not supported in the lite client.'))
32
33
34 var id = require('../keys').id
35 var compose = message_compose(
36 {type: 'post', recps: [], private: true},
37 {
38 prepublish: 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 placeholder: 'Write a private message'
47 }
48 )
49
50 var content = h('div.column.scroller__content')
51 var div = h('div.column.scroller',
52 {style: {'overflow':'auto'}},
53 h('div.scroller__wrapper', compose, content)
54 )
55
56 pull(
57 u.next(sbot_log, {old: false, limit: 100}),
58 unbox(),
59 Scroller(div, content, message_render, true, false)
60 )
61
62 pull(
63 u.next(sbot_log, {reverse: true, limit: 1000}),
64 unbox(),
65 Scroller(div, content, message_render, false, false, function (err) {
66 if(err) throw err
67 })
68 )
69
70 return div
71 }
72}
73
74function map(ary, iter) {
75 if(Array.isArray(ary)) return ary.map(iter)
76}
77
78exports.message_meta = function (msg) {
79 if(msg.value.content.recps || msg.value.private)
80 return h('span.row', 'PRIVATE', map(msg.value.content.recps, function (id) {
81 return avatar_image_link('string' == typeof id ? id : id.link, 'thumbnail')
82 }))
83}
84
85
86

Built with git-ssb-web