git ssb

16+

Dominic / patchbay



Tree: cc06e263225583cc9a1c6958063f600fb97d8968

Files: cc06e263225583cc9a1c6958063f600fb97d8968 / modules_basic / private.js

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

Built with git-ssb-web