Add likes page

This commit is contained in:
Christian Bundy 2019-09-30 17:37:30 -07:00
parent f350cd6f6f
commit f5e2fda069
No known key found for this signature in database
GPG Key ID: EB541AAEF4366237
5 changed files with 72 additions and 1 deletions

View File

@ -18,6 +18,7 @@ const profile = require('./pages/profile')
const json = require('./pages/json')
const thread = require('./pages/thread')
const like = require('./pages/like')
const likesPage = require('./pages/likes')
const status = require('./pages/status')
const mentions = require('./pages/mentions')
const reply = require('./pages/reply')
@ -110,6 +111,9 @@ module.exports = (config) => {
const theme = ctx.cookies.get('theme') || defaultTheme
ctx.body = await status({ theme })
})
.get('/likes/', async (ctx) => {
ctx.body = await likesPage()
})
.get('/readme/', async (ctx) => {
ctx.body = await markdown(config.readme)
})

10
src/pages/likes.js Normal file
View File

@ -0,0 +1,10 @@
'use strict'
const post = require('./models/post')
const listView = require('./views/list')
module.exports = async function likesPage () {
console.log('starting likes')
const messages = await post.likes()
return listView({ messages })
}

View File

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

View File

@ -212,6 +212,61 @@ const post = {
return messages
},
likes: async (customOptions = {}) => {
const ssb = await cooler.connect()
const whoami = await cooler.get(ssb.whoami)
const myFeedId = whoami.id
const query = {
$filter: {
value: {
author: myFeedId, // for some reason this `author` isn't being respected
content: {
type: 'vote'
}
}
}
}
const options = configure({
query,
index: 'DTA',
reverse: true
}, customOptions)
const source = await cooler.read(
ssb.query.read, options
)
const messages = await new Promise((resolve, reject) => {
pull(
source,
pull.filter((msg) => {
return typeof msg.value.content === 'object' &&
msg.value.author === myFeedId &&
typeof msg.value.content.vote === 'object' &&
typeof msg.value.content.vote.link === 'string'
}),
pull.asyncMap(async (val, cb) => {
const msg = await post.get(val.value.content.vote.link)
cb(null, msg)
}),
pull.take(60),
pull.collect((err, collectedMessages) => {
if (err) {
reject(err)
} else {
resolve(collectedMessages)
}
})
)
})
console.log(messages)
return messages
},
latest: async (customOptions = {}) => {
const ssb = await cooler.connect()

View File

@ -42,6 +42,7 @@ module.exports = (...elements) => {
li(a({ href: '/' }, 'public')),
li(a({ href: '/mentions' }, 'mentions')),
li(a({ href: '/profile' }, 'profile')),
li(a({ href: '/likes' }, 'likes')),
li(a({ href: '/status' }, 'status')),
li(a({ href: '/readme' }, 'readme'))
)