git ssb

2+

ev / mvd



Commit 46a1ae94efd979ea889ed8c809555d8d68af371f

add ability to compose messages and reply to posts

Ev Bogue committed on 4/29/2018, 7:52:26 PM
Parent: 7b050a701daa2eec7d77454ac88684a4addac641

Files changed

compose.jschanged
index.jschanged
render.jschanged
rendertools.jschanged
scuttlebot.jschanged
views.jschanged
compose.jsView
@@ -1,8 +1,11 @@
11 var h = require('hyperscript')
22 var pull = require('pull-stream')
33 var sbot = require('./scuttlebot')
44
5 +var header = require('./rendertools').header
6 +var id = require('./keys').id
7 +
58 var mime = require('simple-mime')('application/octect-stream')
69 var split = require('split-buffer')
710
811 function file_input (onAdded) {
@@ -33,20 +36,58 @@
3336
3437 module.exports = function (opts) {
3538 var files = []
3639 var filesById = {}
40 +
41 + var composer = h('div.composer')
42 +
43 + var container = h('div.container')
3744
38- var textarea = h('textarea.compose', {placeholder: 'Reply to this post'})
39-
40- var composer = h('div',
41- textarea,
42- h('button.btn', 'Preview'),
45 + var textarea = h('textarea.compose', {placeholder: 'Write a message' || opts.placeholder})
46 +
47 + var initialButtons = h('span',
48 + h('button.btn', 'Preview', {
49 + onclick: function () {
50 +
51 + var msg = {}
52 + msg.value = {
53 + "author": id,
54 + "content": {
55 + "type": opts.type,
56 + "root": opts.root
57 + }
58 + }
59 + msg.value.content.text = textarea.value
60 + console.log(msg)
61 +
62 + var preview = h('div',
63 + header(msg),
64 + h('div.message__content', msg.value.content.text),
65 + h('button.btn', 'Publish', {
66 + onclick: function () {
67 + sbot.publish(msg.value.content, function (err, msg) {
68 + if(err) throw err
69 + console.log('Published!', msg)
70 + window.location.reload()
71 + if(cb) cb(err, msg)
72 + })
73 + }
74 + })
75 + )
76 + composer.replaceChild(preview, composer.firstChild)
77 + }
78 + }),
4379 file_input(function (file) {
4480 files.push(file)
4581 filesById[file.link] = file
4682 var embed = file.type.indexOf('image/') === 0 ? '!' : ''
4783 textarea.value += embed + '['+file.name+']('+file.link+')'
4884 })
4985 )
86 +
87 + composer.appendChild(container)
88 + container.appendChild(textarea)
89 + container.appendChild(initialButtons)
90 +
5091 return composer
5192 }
5293
index.jsView
@@ -17,7 +17,9 @@
1717 } else if (ref.isFeed(src)) {
1818 views.userstream(src)
1919 } else if (ref.isMsg(src)) {
2020 views.get(src)
21 +} else if (src == 'compose') {
22 + views.compose()
2123 } else {
2224 views.logstream()
2325 }
render.jsView
@@ -7,15 +7,18 @@
77
88 var tools = require('./rendertools')
99
1010 module.exports = function (msg) {
11-
11 + var opts = {}
12 + opts.root = null
1213 var message = h('div.message')
1314 if (msg.value.content.type == 'post') {
1415 message.appendChild(tools.header(msg))
16 + opts.type = 'post'
1517 if (msg.value.content.root) {
1618 message.appendChild(h('span', 're: ', tools.messageLink(msg.value.content.root)))
17- }
19 + opts.root = msg.value.content.root
20 + } else { opts.root = msg.key}
1821 message.appendChild(h('div.message__body',
1922 {innerHTML: markdown.block(msg.value.content.text, {toUrl: function (url, image) {
2023 if(url[0] == '%' || url[0] == '@') return '#' + url
2124 if(!image) return url
@@ -25,9 +28,9 @@
2528 )
2629 )
2730 message.appendChild(h('button.btn', 'Reply', {
2831 onclick: function () {
29- var compose = composer()
32 + var compose = composer(opts)
3033 message.replaceChild(compose, message.lastElementChild)
3134 }
3235 }))
3336 return message
rendertools.jsView
@@ -2,9 +2,8 @@
22 var human = require('human-time')
33 var avatar = require('./avatar')
44 var ref = require('ssb-ref')
55
6-
76 module.exports.header = function (msg) {
87 return h('div.header',
98 h('span.avatar',
109 h('a', {href: '#' + msg.value.author},
scuttlebot.jsView
@@ -4,8 +4,10 @@
44 var reconnect = require('pull-reconnect')
55
66 var config = require('./config')()
77 var createClient = require('ssb-client')
8 +var createFeed = require('ssb-feed')
9 +
810 var keys = require('./keys')
911
1012 var CACHE = {}
1113
@@ -31,8 +33,19 @@
3133 notify()
3234 })
3335 })
3436
37 +var internal = {
38 + getLatest: rec.async(function (id, cb) {
39 + sbot.getLatest(id, cb)
40 + }),
41 + add: rec.async(function (msg, cb) {
42 + sbot.add(msg, cb)
43 + })
44 +}
45 +
46 +var feed = createFeed(internal, keys, {remote: true})
47 +
3548 module.exports = {
3649 createLogStream: rec.source(function (opts) {
3750 return pull(
3851 sbot.createLogStream(opts),
views.jsView
@@ -5,16 +5,21 @@
55 var stream = require('hyperloadmore/stream')
66 var h = require('hyperscript')
77 var render = require('./render')
88
9-module.exports.logstream = function () {
10- var content = h('div.content')
9 +var compose = require('./compose')
1110
11 +var content = h('div.content')
12 +function screen () {
1213 document.body.appendChild(h('div.screen',
1314 {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}},
1415 hyperscroll(content)
1516 ))
17 +}
1618
19 +module.exports.logstream = function () {
20 + screen()
21 +
1722 function createStream (opts) {
1823 return pull(
1924 More(sbot.createLogStream, opts),
2025 pull.map(function (msg) {
@@ -36,15 +41,10 @@
3641
3742 var rawJSON = require('patchapp-raw/json')
3843
3944 module.exports.rawstream = function () {
40- var content = h('div.content')
45 + screen()
4146
42- document.body.appendChild(h('div.screen',
43- {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}},
44- hyperscroll(content)
45- ))
46-
4747 function createStream (opts) {
4848 return pull(
4949 More(sbot.createLogStream, opts),
5050 pull.filter(function (data) {
@@ -67,15 +67,10 @@
6767 )
6868 }
6969
7070 module.exports.userstream = function (src) {
71- var content = h('div.content')
71 + screen()
7272
73- document.body.appendChild(h('div.screen',
74- {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}},
75- hyperscroll(content)
76- ))
77-
7873 function createStream (opts) {
7974 return pull(
8075 More(sbot.userStream, opts, ['value', 'sequence']),
8176 pull.map(function (msg) {
@@ -96,15 +91,10 @@
9691
9792 }
9893
9994 module.exports.get = function (src) {
100- var content = h('div.content')
95 + screen()
10196
102- document.body.appendChild(h('div.screen',
103- {style: {position: 'absolute', top: '0px', bottom: '0px', left: '0px', right: '0px'}},
104- hyperscroll(content)
105- ))
106-
10797 sbot.get(src, function (err, data) {
10898 if (err) {console.log('could not find message') }
10999 data.value = data
110100 console.log(data)
@@ -126,4 +116,10 @@
126116 )
127117 })
128118 })
129119 }
120 +
121 +module.exports.compose = function () {
122 + screen()
123 +
124 + content.appendChild(h('div.message', compose))
125 +}

Built with git-ssb-web