Add full thread view
This commit is contained in:
parent
fbb718cb49
commit
48e5173518
13
index.js
13
index.js
|
@ -4,6 +4,7 @@ const Koa = require('koa')
|
|||
const path = require('path')
|
||||
const router = require('koa-router')()
|
||||
const views = require('koa-views')
|
||||
const static = require('koa-static')
|
||||
|
||||
const author = require('./routes/author')
|
||||
const hashtag = require('./routes/hashtag')
|
||||
|
@ -13,12 +14,6 @@ const thread = require('./routes/thread')
|
|||
|
||||
const app = module.exports = new Koa()
|
||||
|
||||
app.use(views(path.join(__dirname, 'views'), {
|
||||
map: { html: 'ejs' }
|
||||
}))
|
||||
|
||||
app.use(require('koa-static')('public'))
|
||||
|
||||
router
|
||||
.get('/', home)
|
||||
.get('/author/:id', author)
|
||||
|
@ -26,6 +21,12 @@ router
|
|||
.get('/profile/', profile)
|
||||
.get('/thread/:id', thread)
|
||||
|
||||
app.use(views(path.join(__dirname, 'views'), {
|
||||
map: { html: 'ejs' }
|
||||
}))
|
||||
|
||||
app.use(static(path.join(__dirname, 'public')))
|
||||
|
||||
app.use(router.routes())
|
||||
|
||||
if (!module.parent) {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
const lodash = require('lodash')
|
||||
const pull = require('pull-stream')
|
||||
|
||||
const cooler = require('../lib/cooler')
|
||||
const renderMsg = require('../lib/render-message')
|
||||
|
||||
|
@ -9,6 +12,34 @@ module.exports = async function thread (ctx) {
|
|||
private: true
|
||||
})
|
||||
|
||||
const msg = await renderMsg(ssb)(rawMsg)
|
||||
await ctx.render('thread', { msg })
|
||||
const root = rawMsg.key // lodash.get(rawMsg, 'value.content.root', rawMsg.key)
|
||||
|
||||
var filterQuery = {
|
||||
$filter: {
|
||||
dest: root
|
||||
}
|
||||
}
|
||||
|
||||
const backlinkStream = await cooler.read(ssb.backlinks.read, {
|
||||
query: [filterQuery],
|
||||
index: 'DTA' // use asserted timestamps
|
||||
})
|
||||
|
||||
const rawMsgs = await new Promise((resolve, reject) =>
|
||||
pull(
|
||||
backlinkStream,
|
||||
pull.filter(msg =>
|
||||
lodash.get(msg, 'value.content.type') === 'post'
|
||||
),
|
||||
pull.collect((err, msgs) => {
|
||||
if (err) return reject(err)
|
||||
resolve(msgs)
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
const allMsgs = [rawMsg, ...rawMsgs]
|
||||
const msgs = await Promise.all(allMsgs.map(renderMsg(ssb)))
|
||||
|
||||
await ctx.render('home', { msgs })
|
||||
}
|
||||
|
|
|
@ -28,12 +28,15 @@
|
|||
|
||||
<footer>
|
||||
<a href="/thread/<%= encodeURIComponent(msg.key) %>">link</a>
|
||||
|
||||
<% if (msg.value.content.root != null) { %>
|
||||
<a href="/thread/<%= encodeURIComponent(msg.value.content.root) %>">root</a>
|
||||
<% if (msg.value.content.fork != null) { %>
|
||||
<a href="/thread/<%= encodeURIComponent(msg.value.content.fork) %>">parent</a>
|
||||
<a href="/thread/<%= encodeURIComponent(msg.value.content.root) %>">root</a>
|
||||
<% } else {%>
|
||||
<a href="/thread/<%= encodeURIComponent(msg.value.content.root) %>">parent</a>
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
<% if (msg.value.content.fork != null) { %>
|
||||
<a href="/thread/<%= encodeURIComponent(msg.value.content.fork) %>">fork</a>
|
||||
<% } %>
|
||||
</footer>
|
||||
</section>
|
||||
|
|
Loading…
Reference in New Issue