Add inbox to see latest message from private threads
This commit is contained in:
parent
24c1ff79ee
commit
6eb229dfc1
|
@ -29,6 +29,7 @@ const image = require('./pages/image')
|
|||
const blob = require('./pages/blob')
|
||||
const publish = require('./pages/publish')
|
||||
const markdown = require('./pages/markdown')
|
||||
const inboxPage = require('./pages/inbox')
|
||||
|
||||
const defaultTheme = 'unikitty-light'
|
||||
|
||||
|
@ -76,6 +77,9 @@ module.exports = (config) => {
|
|||
const { feed } = ctx.params
|
||||
ctx.body = await author(feed)
|
||||
})
|
||||
.get('/inbox', async (ctx) => {
|
||||
ctx.body = await inboxPage()
|
||||
})
|
||||
.get('/hashtag/:channel', async (ctx) => {
|
||||
const { channel } = ctx.params
|
||||
ctx.body = await hashtag(channel)
|
||||
|
|
|
@ -149,7 +149,6 @@ pre {
|
|||
|
||||
.content > :last-child {
|
||||
margin-bottom: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.message code {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
module.exports = () => ''
|
||||
|
||||
const listView = require('./views/public')
|
||||
const post = require('./models/post')
|
||||
|
||||
module.exports = async function publicPage () {
|
||||
const messages = await post.inbox()
|
||||
|
||||
return listView({ messages })
|
||||
}
|
|
@ -526,6 +526,50 @@ const post = {
|
|||
.map((key) => post.get(key))
|
||||
.filter((message) => lodash.get(message, 'value.content.type') === 'post')
|
||||
)
|
||||
},
|
||||
inbox: async (customOptions = {}) => {
|
||||
const ssb = await cooler.connect()
|
||||
|
||||
const whoami = await cooler.get(ssb.whoami)
|
||||
const myFeedId = whoami.id
|
||||
|
||||
const options = configure({
|
||||
type: 'post',
|
||||
private: true
|
||||
}, customOptions)
|
||||
|
||||
const source = await cooler.read(
|
||||
ssb.messagesByType,
|
||||
options
|
||||
)
|
||||
|
||||
const messages = await new Promise((resolve, reject) => {
|
||||
pull(
|
||||
source,
|
||||
pull.filter((message) => // avoid private messages (!)
|
||||
typeof message.value.content !== 'string' &&
|
||||
lodash.get(message, 'value.meta.private')
|
||||
),
|
||||
pull.unique((message) => {
|
||||
const { root } = message.value.content
|
||||
if (root == null) {
|
||||
return message.key
|
||||
} else {
|
||||
return root
|
||||
}
|
||||
}),
|
||||
pull.take(maxMessages),
|
||||
pull.collect((err, collectedMessages) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve(transform(ssb, collectedMessages, myFeedId))
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
return messages
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ module.exports = (...elements) => {
|
|||
nav(
|
||||
ul(
|
||||
li(a({ href: '/' }, 'public')),
|
||||
li(a({ href: '/inbox' }, 'inbox')),
|
||||
li(a({ href: '/mentions' }, 'mentions')),
|
||||
li(a({ href: '/profile' }, 'profile')),
|
||||
li(a({ href: '/likes' }, 'likes')),
|
||||
|
|
Loading…
Reference in New Issue