git ssb

16+

Dominic / patchbay



Tree: 560b4eeaebdc81616f23b3384a8c6ac9c0126e09

Files: 560b4eeaebdc81616f23b3384a8c6ac9c0126e09 / modules_basic / private.js

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

Built with git-ssb-web