git ssb

3+

dangerousbeans / scuttle-vue



Tree: 82418e8c0eab5c0b94532a1f8612097db1fc1bb4

Files: 82418e8c0eab5c0b94532a1f8612097db1fc1bb4 / modules / private.js

2751 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 screen_view: true,
24 message_meta: true,
25 message_content_mini: true
26}
27
28exports.create = function (api) {
29
30 function unbox () {
31 return pull(
32 pull.filter(function (msg) {
33 return 'string' == typeof msg.value.content
34 }),
35 pull.map(function (msg) {
36 return api.message_unbox(msg)
37 }),
38 pull.filter(Boolean)
39 )
40 }
41
42 return {
43 screen_view: function (path) {
44 if(path === 'Direct') {
45 var id = require('../keys').id
46 var compose = api.message_compose(
47 {type: 'post', recps: [], private: true},
48 {
49 prepublish: function (msg) {
50 msg.recps = [id].concat(msg.mentions).filter(function (e) {
51 return ref.isFeed('string' === typeof e ? e : e.link)
52 })
53 if(!msg.recps.length)
54 throw new Error('Please select at least one recipient. Use @person to select recipients in the message body.')
55 return msg
56 },
57 placeholder: 'Write a private message. Use @person to select recipients.'
58 }
59 )
60
61 var content = h('div.column.scroller__content')
62 var div = h('div.column.scroller',
63 {style: {'overflow':'auto'}},
64 h('div.scroller__wrapper', compose, content)
65 )
66
67 pull(
68 api.sbot_log({old: false}),
69 unbox(),
70 Scroller(div, content, api.message_render, true, false)
71 )
72
73 pull(
74 u.next(api.sbot_log, {reverse: true, limit: 1000}),
75 unbox(),
76 Scroller(div, content, api.message_render, false, false, function (err) {
77 if(err) throw err
78 })
79 )
80
81 return div
82 }
83 },
84
85 message_meta: function (msg) {
86 if(msg.value.content.recps || msg.value.private)
87 return h('span.row', 'PRIVATE', map(msg.value.content.recps, function (id) {
88 return api.avatar_image_link('string' == typeof id ? id : id.link, 'thumbnail')
89 }))
90 },
91
92 message_content_mini: function (msg, sbot) {
93 if (typeof msg.value.content === 'string') {
94 var icon = api.emoji_url('lock')
95 return icon
96 ? h('img', {className: 'emoji', src: icon})
97 : 'PRIVATE'
98 }
99 }
100 }
101
102}
103
104

Built with git-ssb-web