Add reply-all feature for non-forky replies

This commit is contained in:
Christian Bundy 2019-09-26 17:19:18 -07:00
parent bccae0449a
commit c349a29601
No known key found for this signature in database
GPG Key ID: EB541AAEF4366237
13 changed files with 348 additions and 604 deletions

View File

@ -2,6 +2,7 @@
"version": "0.1",
"language": "en",
"words": [
"AGPL",
"backlinks",
"hyperaxe",
"msgs",

View File

@ -52,4 +52,4 @@ yarn global add @fraction/oasis
## License
ISC
AGPL-3.0

View File

@ -3,7 +3,7 @@
"version": "2.1.3",
"main": "index.js",
"author": "Christian Bundy <christianbundy@fraction.io>",
"license": "ISC",
"license": "AGPL-3.0",
"dependencies": {
"@fraction/flotilla": "^1.0.1",
"debug": "^4.1.1",

View File

@ -21,7 +21,9 @@ const status = require('./pages/status')
const highlight = require('./pages/highlight')
const mentions = require('./pages/mentions')
const reply = require('./pages/reply')
const replyAll = require('./pages/reply-all')
const publishReply = require('./pages/publish-reply')
const publishReplyAll = require('./pages/publish-reply-all')
const image = require('./pages/image')
const blob = require('./pages/blob')
const publish = require('./pages/publish')
@ -117,12 +119,22 @@ module.exports = (config) => {
const { message } = ctx.params
ctx.body = await reply(message, false)
})
.get('/reply-all/:message', async (ctx) => {
const { message } = ctx.params
ctx.body = await replyAll(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('/reply-all/:message', koaBody(), async (ctx) => {
const { message } = ctx.params
const text = String(ctx.request.body.text)
ctx.body = await publishReplyAll({ message, text })
ctx.redirect('/')
})
.post('/publish/', koaBody(), async (ctx) => {
const text = String(ctx.request.body.text)
ctx.body = await publish({ text })

View File

@ -19,7 +19,8 @@ const rawConnect = () => new Promise((resolve, reject) => {
messagesByType: 'source',
publish: 'async',
status: 'async',
whoami: 'sync'
whoami: 'sync',
tangle: { branch: 'async' }
}
}, (err, api) => {
if (err) {

View File

@ -148,7 +148,7 @@ const transform = (ssb, messages, myFeedId) =>
return msg
}))
module.exports = {
const post = {
fromFeed: async (feedId, customOptions = {}) => {
const ssb = await cooler.connect()
@ -419,5 +419,23 @@ module.exports = {
debug('Published: %O', body)
return cooler.get(ssb.publish, body)
},
reply: async ({ parent, message }) => {
message.root = parent
message.branch = parent
return post.publish(message)
},
replyAll: async ({ parent, message }) => {
const ssb = await cooler.connect()
const parentMsg = await cooler.get(ssb.get, parent)
const branch = await cooler.get(ssb.tangle.branch, parent)
message.root = parentMsg.content.root
message.branch = branch
return post.publish(message)
}
}
module.exports = post

View File

@ -0,0 +1,14 @@
'use strict'
const ssbMentions = require('ssb-mentions')
const post = require('./models/post')
module.exports = async function publishReplyAllPage ({ message, text }) {
// TODO: rename `message` to `parent` or `ancestor` or similar
const mentions = ssbMentions(text) || undefined
return post.replyAll({
parent: message,
message: { text, mentions }
})
}

View File

@ -4,11 +4,11 @@ const ssbMentions = require('ssb-mentions')
const post = require('./models/post')
module.exports = async function publishReplyPage ({ message, text }) {
// TODO: rename `message` to `parent` or `ancestor` or similar
const mentions = ssbMentions(text) || undefined
return post.publish({
root: message,
branch: message,
text,
mentions
return post.reply({
parent: message,
message: { text, mentions }
})
}

12
src/pages/reply-all.js Normal file
View File

@ -0,0 +1,12 @@
'use strict'
const debug = require('debug')('oasis')
const post = require('./models/post')
const replyAllView = require('./views/reply-all')
module.exports = async function replyPage (parentId) {
const message = await post.get(parentId)
debug('%O', message)
return replyAllView({ message })
}

View File

@ -34,9 +34,12 @@ module.exports = ({ msg }) => {
parent: `/thread/${encoded.parent}#${encoded.parent}`,
avatar: msg.value.meta.author.avatar.url,
raw: `/raw/${encoded.key}`,
reply: `/reply/${encoded.key}`
reply: `/reply/${encoded.key}`,
replyAll: `/reply-all/${encoded.key}`
}
const isRoot = msg.value.content.root == null
const isPrivate = Boolean(msg.value.meta.private)
const isThreadTarget = Boolean(lodash.get(
msg,
@ -131,6 +134,7 @@ module.exports = ({ msg }) => {
},
`${likeCount}`)),
isPrivate ? null : a({ href: url.reply }, 'reply'),
isPrivate || isRoot ? null : a({ href: url.replyAll }, 'reply all'),
a({ href: url.context }, 'context'),
parentLink,
a({ href: url.raw }, 'raw')

View File

@ -13,7 +13,7 @@ module.exports = ({ messages }) => {
return template(
form({ action: publishForm, method: 'post' },
textarea({ autofocus: true, required: true, name: 'text' }),
textarea({ required: true, name: 'text' }),
button({
type: 'submit'
}, 'submit')),

View File

@ -0,0 +1,31 @@
'use strict'
const {
button,
form,
textarea
} = require('hyperaxe')
const template = require('./components/template')
const post = require('./components/post')
module.exports = ({ message }) => {
const likeForm = `/reply-all/${encodeURIComponent(message.key)}`
const authorName = message.value.meta.author.name
const authorFeedId = message.value.author
const markdownMention = `[@${authorName}](${authorFeedId})\n\n`
return template(
post({ msg: message }),
form({ action: likeForm, method: 'post' },
textarea({
autofocus: true,
required: true,
name: 'text'
}, markdownMention),
button({
type: 'submit'
}, 'reply all'))
)
}

837
yarn.lock

File diff suppressed because it is too large Load Diff