git ssb

0+

ev / minbase



Tree: b62ecd6f843b26f37e70c7b6d65c71db35bbf922

Files: b62ecd6f843b26f37e70c7b6d65c71db35bbf922 / modules / private.js

2840 bytesRaw
1'use strict'
2var h = require('hyperscript')
3var u = require('../util')
4var pull = require('pull-stream')
5var Scroller = require('../pull-scroll')
6var ref = require('ssb-ref')
7
8function map(ary, iter) {
9 if(Array.isArray(ary)) return ary.map(iter)
10}
11
12exports.needs = {
13 message_render: 'first',
14 message_compose: 'first',
15 message_unbox: 'first',
16 sbot_log: 'first',
17 sbot_whoami: 'first',
18 avatar_image_link: 'first',
19 emoji_url: 'first'
20}
21
22exports.gives = {
23 builtin_tabs: true,
24 screen_view: true,
25 message_meta: true,
26 message_content_mini: true
27}
28
29exports.create = function (api) {
30
31 function unbox () {
32 return pull(
33 pull.filter(function (msg) {
34 return 'string' == typeof msg.value.content
35 }),
36 pull.map(function (msg) {
37 return api.message_unbox(msg)
38 }),
39 pull.filter(Boolean)
40 )
41 }
42
43 return {
44 builtin_tabs: function () {
45 return ['Direct']
46 },
47
48 screen_view: function (path) {
49 if(path === 'Direct') {
50 var id = require('../keys').id
51 var compose = api.message_compose(
52 {type: 'post', recps: [], private: true},
53 {
54 prepublish: function (msg) {
55 msg.recps = [id].concat(msg.mentions).filter(function (e) {
56 return ref.isFeed('string' === typeof e ? e : e.link)
57 })
58 if(!msg.recps.length)
59 throw new Error('Please select at least one recipient. Use @person to select recipients in the message body.')
60 return msg
61 },
62 placeholder: 'Write a private message. Use @person to select recipients.'
63 }
64 )
65
66 var content = h('div.column.scroller__content')
67 var div = h('div.column.scroller',
68 {style: {'overflow':'auto'}},
69 h('div.scroller__wrapper', compose, content)
70 )
71
72 pull(
73 api.sbot_log({old: false}),
74 unbox(),
75 Scroller(div, content, api.message_render, true, false)
76 )
77
78 pull(
79 u.next(api.sbot_log, {reverse: true, limit: 1000}),
80 unbox(),
81 Scroller(div, content, api.message_render, false, false, function (err) {
82 if(err) throw err
83 })
84 )
85
86 return div
87 }
88 },
89
90 message_meta: function (msg) {
91 if(msg.value.content.recps || msg.value.private)
92 return h('span.row', 'PRIVATE', map(msg.value.content.recps, function (id) {
93 return api.avatar_image_link('string' == typeof id ? id : id.link, 'thumbnail')
94 }))
95 },
96
97 message_content_mini: function (msg, sbot) {
98 if (typeof msg.value.content === 'string') {
99 var icon = api.emoji_url('lock')
100 return icon
101 ? h('img', {className: 'emoji', src: icon})
102 : 'PRIVATE'
103 }
104 }
105 }
106
107}
108
109

Built with git-ssb-web