Add better reply-all view showing root message
This commit is contained in:
parent
92cf6f04ce
commit
ba51ed3e1d
|
@ -81,6 +81,7 @@ module.exports = (config) => {
|
|||
const { style } = ctx.params
|
||||
ctx.type = 'text/css'
|
||||
ctx.body = highlight(style)
|
||||
ctx.set('Cache-Control', 'max-age=31536000')
|
||||
})
|
||||
.get('/profile/', async (ctx) => {
|
||||
ctx.body = await profile()
|
||||
|
@ -96,11 +97,13 @@ module.exports = (config) => {
|
|||
|
||||
// This prevents an auto-download when visiting the URL.
|
||||
ctx.attachment(blobId, { type: 'inline' })
|
||||
ctx.set('Cache-Control', 'max-age=31536000')
|
||||
})
|
||||
.get('/image/:imageSize/:blobId', async (ctx) => {
|
||||
const { blobId, imageSize } = ctx.params
|
||||
ctx.type = 'image/png'
|
||||
ctx.body = await image({ blobId, imageSize: Number(imageSize) })
|
||||
ctx.set('Cache-Control', 'max-age=31536000')
|
||||
})
|
||||
.get('/status/', async (ctx) => {
|
||||
ctx.body = await status()
|
||||
|
|
|
@ -8,6 +8,7 @@ const debug = require('debug')('oasis:model-post')
|
|||
const cooler = require('./lib/cooler')
|
||||
const configure = require('./lib/configure')
|
||||
const markdown = require('./lib/markdown')
|
||||
const { isMsg } = require('ssb-ref')
|
||||
|
||||
const getMessages = async ({ myFeedId, customOptions, ssb, query }) => {
|
||||
const options = configure({ query, index: 'DTA' }, customOptions)
|
||||
|
@ -271,7 +272,7 @@ const post = {
|
|||
resolve(parents)
|
||||
}
|
||||
|
||||
if (typeof msg.value.content.fork === 'string') {
|
||||
if (typeof msg.value.content.fork === 'string' && isMsg(msg.value.content.fork)) {
|
||||
debug('fork, get the parent')
|
||||
try {
|
||||
// It's a message reply, get the parent!
|
||||
|
@ -286,7 +287,7 @@ const post = {
|
|||
debug(e)
|
||||
resolve(msg)
|
||||
}
|
||||
} else if (typeof msg.value.content.root === 'string') {
|
||||
} else if (typeof msg.value.content.root === 'string' && isMsg(msg.value.content.root)) {
|
||||
debug('thread reply: %s', msg.value.content.root)
|
||||
try {
|
||||
// It's a thread reply, get the parent!
|
||||
|
@ -430,14 +431,19 @@ const post = {
|
|||
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
|
||||
message.root = lodash.get(parent, 'value.content.root', parent.key)
|
||||
message.branch = await post.branch({ root: parent.key })
|
||||
|
||||
return post.publish(message)
|
||||
},
|
||||
branch: async ({ root }) => {
|
||||
const ssb = await cooler.connect()
|
||||
const keys = await cooler.get(ssb.tangle.branch, root)
|
||||
|
||||
return Promise.all(keys
|
||||
.map((key) => post.get(key))
|
||||
.filter((message) => lodash.get(message, 'value.content.type') === 'post')
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
const ssbMentions = require('ssb-mentions')
|
||||
const post = require('./models/post')
|
||||
const meta = require('./models/post')
|
||||
|
||||
module.exports = async function publishReplyAllPage ({ message, text }) {
|
||||
// TODO: rename `message` to `parent` or `ancestor` or similar
|
||||
const mentions = ssbMentions(text) || undefined
|
||||
const parent = await meta.get(message)
|
||||
|
||||
return post.replyAll({
|
||||
parent: message,
|
||||
parent,
|
||||
message: { text, mentions }
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
'use strict'
|
||||
|
||||
const debug = require('debug')('oasis')
|
||||
const post = require('./models/post')
|
||||
const replyAllView = require('./views/reply-all')
|
||||
const ssbRef = require('ssb-ref')
|
||||
|
||||
module.exports = async function replyPage (parentId) {
|
||||
const message = await post.get(parentId)
|
||||
debug('%O', message)
|
||||
const parentMessage = await post.get(parentId)
|
||||
|
||||
return replyAllView({ message })
|
||||
const messages = [parentMessage]
|
||||
|
||||
const hasRoot = typeof parentMessage.value.content.root === 'string' && ssbRef.isMsg(parentMessage.value.content.root)
|
||||
console.log('got root ', parentMessage.value.content)
|
||||
if (hasRoot) {
|
||||
messages.push(await post.get(parentMessage.value.content.root))
|
||||
}
|
||||
|
||||
return replyAllView({ messages })
|
||||
}
|
||||
|
|
|
@ -38,8 +38,6 @@ module.exports = ({ msg }) => {
|
|||
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,
|
||||
|
@ -134,7 +132,7 @@ module.exports = ({ msg }) => {
|
|||
},
|
||||
`❤ ${likeCount}`)),
|
||||
isPrivate ? null : a({ href: url.reply }, 'reply'),
|
||||
isPrivate || isRoot ? null : a({ href: url.replyAll }, 'reply all'),
|
||||
isPrivate ? null : a({ href: url.replyAll }, 'reply all'),
|
||||
a({ href: url.context }, 'context'),
|
||||
parentLink,
|
||||
a({ href: url.raw }, 'raw')
|
||||
|
|
|
@ -1,24 +1,36 @@
|
|||
'use strict'
|
||||
|
||||
const {
|
||||
p,
|
||||
button,
|
||||
form,
|
||||
textarea
|
||||
} = require('hyperaxe')
|
||||
|
||||
const debug = require('debug')('oasis:views:reply-all')
|
||||
const template = require('./components/template')
|
||||
const post = require('./components/post')
|
||||
|
||||
module.exports = ({ message }) => {
|
||||
const likeForm = `/reply-all/${encodeURIComponent(message.key)}`
|
||||
module.exports = async ({ messages }) => {
|
||||
let markdownMention
|
||||
|
||||
const authorName = message.value.meta.author.name
|
||||
const authorFeedId = message.value.author
|
||||
const markdownMention = `[@${authorName}](${authorFeedId})\n\n`
|
||||
const messageElements = await Promise.all(messages.reverse().map((message) => {
|
||||
debug('%O', message)
|
||||
const authorName = message.value.meta.author.name
|
||||
const authorFeedId = message.value.author
|
||||
markdownMention = `[@${authorName}](${authorFeedId})\n\n`
|
||||
return post({ msg: message })
|
||||
}))
|
||||
|
||||
const action = `/reply-all/${encodeURIComponent(messages[0].key)}`
|
||||
const method = 'post'
|
||||
|
||||
const warning = p({ style: 'text-align: center;' }, '[showing maximum of two posts from thread, others may exist]')
|
||||
|
||||
return template(
|
||||
post({ msg: message }),
|
||||
form({ action: likeForm, method: 'post' },
|
||||
messageElements,
|
||||
warning,
|
||||
form({ action, method },
|
||||
textarea({
|
||||
autofocus: true,
|
||||
required: true,
|
||||
|
|
Loading…
Reference in New Issue