git ssb

2+

mixmix / ticktack



Commit 42429c62406fd68f3e1e166a77c05433cf34801e

new blogs content are stored as blobs

Dominic Tarr committed on 12/6/2017, 11:37:24 PM
Parent: 2b1e0cfa2f8ffcddd87d0ea71797a535a1352003

Files changed

app/page/blogNew.jschanged
message/html/compose.jschanged
app/page/blogNew.jsView
@@ -1,7 +1,8 @@
11 const nest = require('depnest')
22 const { h, Struct, Value } = require('mutant')
33 const addSuggest = require('suggest-box')
4+const pull = require('pull-stream')
45
56 exports.gives = nest('app.page.blogNew')
67
78 exports.needs = nest({
@@ -9,15 +10,16 @@
910 'channel.async.suggest': 'first',
1011 'history.sync.push': 'first',
1112 'message.html.compose': 'first',
1213 'translations.sync.strings': 'first',
14+ 'sbot.async.addBlob': 'first'
1315 })
1416
1517 exports.create = (api) => {
1618 var contentHtmlObs
1719
1820 return nest('app.page.blogNew', blogNew)
19-
21+
2022 function blogNew (location) {
2123 const strings = api.translations.sync.strings()
2224 const getChannelSuggestions = api.channel.async.suggest()
2325
@@ -27,16 +29,31 @@
2729 title: Value(),
2830 })
2931
3032 const composer = api.message.html.compose(
31- { meta, placeholder: strings.blogNew.actions.writeBlog, shrink: false },
33+ {
34+ meta,
35+ placeholder: strings.blogNew.actions.writeBlog,
36+ shrink: false,
37+ prepublish: function (content, cb) {
38+ var stream = pull.values([content.text])
39+ delete content.text
40+ api.sbot.async.addBlob(stream, function (err, hash) {
41+ if(err) return cb(err)
42+ if(!hash) throw new Error('missing hash')
43+ content.blog = hash
44+ cb(null, content)
45+ })
46+ }
47+ },
3248 (err, msg) => api.history.sync.push(err ? err : msg)
3349 )
3450
3551 const channelInput = h('input', {
3652 'ev-input': e => meta.channel.set(e.target.value),
3753 placeholder: strings.channel
3854 })
55+
3956 var page = h('Page -blogNew', [
4057 api.app.html.context(location),
4158 h('div.content', [
4259 h('div.container', [
@@ -84,4 +101,5 @@
84101
85102 return page
86103 }
87104 }
105+
message/html/compose.jsView
@@ -22,9 +22,9 @@
2222 exports.create = function (api) {
2323 return nest('message.html.compose', compose)
2424
2525 function compose (options, cb) {
26- var {
26+ var {
2727 meta, // required
2828 placeholder,
2929 shrink = true,
3030 canAttach = true, canPreview = true,
@@ -151,21 +151,17 @@
151151 if (!content.channel) delete content.channel
152152 if (!mentions.length) delete content.mentions
153153 if (content.recps && content.recps.length === 0) delete content.recps
154154
155- try {
156- if (typeof prepublish === 'function') {
157- content = prepublish(content)
158- }
159- } catch (err) {
160- publishBtn.disabled = false
161- handleErr(err)
155+ if (typeof prepublish === 'function') {
156+ prepublish(content, function (err, content) {
157+ if(err) handleErr(err)
158+ else api.message.async.publish(content, done)
159+ })
162160 }
161+ else
162+ api.message.async.publish(content, done)
163163
164- // debugger
165- return api.message.async.publish(content, done)
166- // return api.message.html.confirm(content, done)
167-
168164 function done (err, msg) {
169165 publishBtn.disabled = false
170166 if (err) handleErr(err)
171167 else if (msg) {
@@ -175,11 +171,16 @@
175171 if (cb) cb(err, msg)
176172 }
177173
178174 function handleErr (err) {
175+ publishBtn.disabled = false
179176 if (cb) cb(err)
180177 else throw err
181178 }
182179 }
183180 }
184181 }
185182
183+
184+
185+
186+

Built with git-ssb-web