Add support for viewing mentions

This commit is contained in:
Christian Bundy 2019-07-26 10:06:47 -07:00
parent 833275013e
commit 136df89836
No known key found for this signature in database
GPG Key ID: EB541AAEF4366237
5 changed files with 11395 additions and 0 deletions

11347
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@ module.exports = (config) => {
const like = require('./pages/like')
const status = require('./pages/status')
const highlight = require('./pages/highlight')
const mentions = require('./pages/mentions')
const assets = new Koa()
assets.use(koaStatic(path.join(__dirname, 'assets')))
@ -66,6 +67,9 @@ module.exports = (config) => {
.get('/status/', async (ctx) => {
ctx.body = await status()
})
.get('/mentions/', async (ctx) => {
ctx.body = await mentions()
})
.get('/thread/:message', async (ctx) => {
const { message } = ctx.params
ctx.body = await thread(message)

8
src/pages/mentions.js Normal file
View File

@ -0,0 +1,8 @@
const post = require('./models/post')
const listView = require('./views/list')
module.exports = async function hashtag (channel) {
const messages = await post.mentionsMe()
return listView({ messages })
}

View File

@ -129,6 +129,41 @@ module.exports = {
return messages
},
mentionsMe: async (customOptions = {}) => {
const ssb = await cooler.connect()
const whoami = await cooler.get(ssb.whoami)
const myFeedId = whoami.id
const query = [{
$filter: {
dest: myFeedId
}
}]
const options = configure({ query, index: 'DTA' }, customOptions)
const source = await cooler.read(
ssb.backlinks.read, options
)
const messages = await new Promise((resolve, reject) => {
pull(
source,
pull.filter(msg =>
typeof msg.value.content !== 'string' &&
msg.value.content.type === 'post'
),
pull.take(32),
pull.collect((err, messages) => {
if (err) return reject(err)
resolve(transform(ssb, messages, myFeedId))
})
)
})
return messages
},
fromHashtag: async (hashtag, customOptions = {}) => {
const ssb = await cooler.connect()

View File

@ -30,6 +30,7 @@ module.exports = (...elements) => {
body(
nav(
a({ href: '/' }, 'home'),
a({ href: '/mentions' }, 'mentions'),
a({ href: '/profile' }, 'profile'),
a({ href: '/status' }, 'status'),
a({ href: 'https://github.com/fraction/oasis' }, 'source'),