Fix bug where private messages were liked publicly
This commit is contained in:
parent
f610c17168
commit
e87cbd37d0
|
@ -5,6 +5,7 @@
|
|||
"backlinks",
|
||||
"hyperaxe",
|
||||
"msgs",
|
||||
"whoami"
|
||||
"whoami",
|
||||
"recps"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -90,6 +90,8 @@ module.exports = (config) => {
|
|||
})
|
||||
.post('/like/:message', koaBody(), async (ctx) => {
|
||||
const { message } = ctx.params
|
||||
// TODO: convert all so `message` is full message and `messageKey` is key
|
||||
const messageKey = message
|
||||
|
||||
const voteValue = Number(ctx.request.body.voteValue)
|
||||
|
||||
|
@ -99,7 +101,7 @@ module.exports = (config) => {
|
|||
}
|
||||
|
||||
referer.hash = `centered-footer-${encoded.message}`
|
||||
ctx.body = await like({ message, voteValue })
|
||||
ctx.body = await like({ messageKey, voteValue })
|
||||
ctx.redirect(referer)
|
||||
})
|
||||
|
||||
|
|
|
@ -1,7 +1,25 @@
|
|||
'use strict'
|
||||
const vote = require('./models/vote')
|
||||
const post = require('./models/post')
|
||||
|
||||
module.exports = async function like ({ message, voteValue }) {
|
||||
module.exports = async function like ({ messageKey, voteValue }) {
|
||||
const value = Number(voteValue)
|
||||
return vote.publish(message, value)
|
||||
const message = await post.get(messageKey)
|
||||
|
||||
const isPrivate = message.value.meta.private === true
|
||||
const messageRecipients = isPrivate ? message.value.content.recps : []
|
||||
|
||||
const normalized = messageRecipients.map(recipient => {
|
||||
if (typeof recipient === 'string') {
|
||||
return recipient
|
||||
}
|
||||
|
||||
if (typeof recipient.link === 'string') {
|
||||
return recipient.link
|
||||
}
|
||||
})
|
||||
|
||||
const recipients = normalized.length > 0 ? normalized : undefined
|
||||
|
||||
return vote.publish({ messageKey, value, recps: recipients })
|
||||
}
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
const cooler = require('./lib/cooler')
|
||||
|
||||
module.exports = {
|
||||
publish: async (messageId, value) => {
|
||||
publish: async ({ messageKey, value, recps }) => {
|
||||
const ssb = await cooler.connect()
|
||||
await cooler.get(ssb.publish, {
|
||||
type: 'vote',
|
||||
vote: {
|
||||
link: messageId,
|
||||
link: messageKey,
|
||||
value: Number(value)
|
||||
}
|
||||
},
|
||||
recps
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue