Merge branch 'reply'
This commit is contained in:
commit
855cd5a90d
|
@ -4,4 +4,5 @@ coverage/
|
|||
dist/
|
||||
tmp/
|
||||
npm-debug.log*
|
||||
.DS_Store
|
||||
package-lock.json
|
||||
.DS_Store
|
||||
|
|
File diff suppressed because it is too large
Load Diff
16
src/app.js
16
src/app.js
|
@ -1,4 +1,5 @@
|
|||
'use strict'
|
||||
|
||||
module.exports = (config) => {
|
||||
if (config.debug) {
|
||||
process.env.DEBUG = '*'
|
||||
|
@ -24,6 +25,8 @@ module.exports = (config) => {
|
|||
const status = require('./pages/status')
|
||||
const highlight = require('./pages/highlight')
|
||||
const mentions = require('./pages/mentions')
|
||||
const reply = require('./pages/reply')
|
||||
const publishReply = require('./pages/publish-reply')
|
||||
|
||||
const assets = new Koa()
|
||||
assets.use(koaStatic(path.join(__dirname, 'assets')))
|
||||
|
@ -75,18 +78,27 @@ module.exports = (config) => {
|
|||
const { message } = ctx.params
|
||||
ctx.body = await thread(message)
|
||||
})
|
||||
.get('/reply/:message', async (ctx) => {
|
||||
const { message } = ctx.params
|
||||
ctx.body = await reply(message, false)
|
||||
})
|
||||
.post('/reply/:message', koaBody(), async (ctx) => {
|
||||
const { message } = ctx.params
|
||||
const text = String(ctx.request.body.text)
|
||||
ctx.body = await publishReply({ message, text })
|
||||
ctx.redirect('/')
|
||||
})
|
||||
.post('/like/:message', koaBody(), async (ctx) => {
|
||||
const { message } = ctx.params
|
||||
|
||||
const voteValue = Number(ctx.request.body.voteValue)
|
||||
const referer = new URL(ctx.request.header.referer)
|
||||
|
||||
const referer = new URL(ctx.request.header.referer)
|
||||
const encoded = {
|
||||
message: encodeURIComponent(message)
|
||||
}
|
||||
|
||||
referer.hash = `centered-footer-${encoded.message}`
|
||||
|
||||
ctx.body = await like({ message, voteValue })
|
||||
ctx.redirect(referer)
|
||||
})
|
||||
|
|
|
@ -142,8 +142,12 @@ pre {
|
|||
pointer-events: none;
|
||||
}
|
||||
|
||||
.message > footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.message > footer > * {
|
||||
margin-right: 1rem;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
|
@ -221,3 +225,9 @@ progress {
|
|||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
textarea {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 8rem;
|
||||
}
|
||||
|
|
|
@ -377,5 +377,27 @@ module.exports = {
|
|||
|
||||
const transformed = await transform(ssb, allMessages, myFeedId)
|
||||
return transformed
|
||||
},
|
||||
get: async (msgId, customOptions) => {
|
||||
debug('get: %s', msgId)
|
||||
const ssb = await cooler.connect()
|
||||
|
||||
const whoami = await cooler.get(ssb.whoami)
|
||||
const myFeedId = whoami.id
|
||||
|
||||
const options = configure({ id: msgId }, customOptions)
|
||||
const rawMsg = await cooler.get(ssb.get, options)
|
||||
debug('got raw message')
|
||||
|
||||
const transformed = await transform(ssb, [rawMsg], myFeedId)
|
||||
debug('transformed: %O', transformed)
|
||||
return transformed[0]
|
||||
},
|
||||
publish: async (options) => {
|
||||
const ssb = await cooler.connect()
|
||||
const body = { type: 'post', ...options }
|
||||
|
||||
console.log(body)
|
||||
return cooler.get(ssb.publish, body)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
'use strict'
|
||||
|
||||
const post = require('./models/post')
|
||||
|
||||
module.exports = async function ({ message, text }) {
|
||||
return post.publish({
|
||||
root: message,
|
||||
branch: message,
|
||||
text
|
||||
})
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
'use strict'
|
||||
|
||||
const debug = require('debug')('oasis')
|
||||
const post = require('./models/post')
|
||||
const replyView = require('./views/reply')
|
||||
|
||||
module.exports = async function (parentId) {
|
||||
const message = await post.get(parentId)
|
||||
debug('%O', message)
|
||||
|
||||
return replyView({ message })
|
||||
}
|
|
@ -28,7 +28,8 @@ module.exports = ({ msg }) => {
|
|||
context: `/thread/${encoded.key}#${encoded.key}`,
|
||||
parent: `/thread/${encoded.parent}#${encoded.parent}`,
|
||||
avatar: msg.value.meta.author.avatar.url,
|
||||
raw: `/raw/${encoded.key}`
|
||||
raw: `/raw/${encoded.key}`,
|
||||
reply: `/reply/${encoded.key}`
|
||||
}
|
||||
|
||||
const isPrivate = Boolean(msg.value.meta.private)
|
||||
|
@ -107,6 +108,7 @@ module.exports = ({ msg }) => {
|
|||
`❤ ${likeCount}`
|
||||
)
|
||||
),
|
||||
a({ href: url.reply }, 'reply'),
|
||||
a({ href: url.context }, 'context'),
|
||||
parentLink,
|
||||
a({ href: url.raw }, 'raw')
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
'use strict'
|
||||
|
||||
const {
|
||||
button,
|
||||
form,
|
||||
textarea
|
||||
} = require('hyperaxe')
|
||||
|
||||
const template = require('./components/template')
|
||||
const post = require('./components/post')
|
||||
|
||||
const apology = `sorry this sucks right now, it's just plaintext and won't even
|
||||
create a mention to the person you're talking to -- soon it will be better!
|
||||
`
|
||||
|
||||
module.exports = ({ message }) => {
|
||||
const likeForm = `/reply/${encodeURIComponent(message.key)}`
|
||||
|
||||
return template(
|
||||
post({ msg: message }),
|
||||
form({ action: likeForm, method: 'post' },
|
||||
textarea({ name: 'text', placeholder: apology }),
|
||||
button({
|
||||
type: 'submit'
|
||||
}, 'reply (public!!!)')
|
||||
)
|
||||
)
|
||||
}
|
|
@ -24,11 +24,11 @@ module.exports = ({ status }) => {
|
|||
]
|
||||
})
|
||||
|
||||
const localPeers = Object.keys(status.local).map(key => {
|
||||
const localPeers = Object.keys(status.local || []).map(key => {
|
||||
return li(key)
|
||||
})
|
||||
|
||||
const remotePeers = Object.keys(status.gossip).map(key => {
|
||||
const remotePeers = Object.keys(status.gossip || []).map(key => {
|
||||
return li(key)
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue