Fix bug where private messages were liked publicly
This commit is contained in:
@ -5,6 +5,7 @@
|
|||||||
"backlinks",
|
"backlinks",
|
||||||
"hyperaxe",
|
"hyperaxe",
|
||||||
"msgs",
|
"msgs",
|
||||||
"whoami"
|
"whoami",
|
||||||
|
"recps"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,8 @@ module.exports = (config) => {
|
|||||||
})
|
})
|
||||||
.post('/like/:message', koaBody(), async (ctx) => {
|
.post('/like/:message', koaBody(), async (ctx) => {
|
||||||
const { message } = ctx.params
|
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)
|
const voteValue = Number(ctx.request.body.voteValue)
|
||||||
|
|
||||||
@ -99,7 +101,7 @@ module.exports = (config) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
referer.hash = `centered-footer-${encoded.message}`
|
referer.hash = `centered-footer-${encoded.message}`
|
||||||
ctx.body = await like({ message, voteValue })
|
ctx.body = await like({ messageKey, voteValue })
|
||||||
ctx.redirect(referer)
|
ctx.redirect(referer)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,7 +1,25 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
const vote = require('./models/vote')
|
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)
|
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')
|
const cooler = require('./lib/cooler')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publish: async (messageId, value) => {
|
publish: async ({ messageKey, value, recps }) => {
|
||||||
const ssb = await cooler.connect()
|
const ssb = await cooler.connect()
|
||||||
await cooler.get(ssb.publish, {
|
await cooler.get(ssb.publish, {
|
||||||
type: 'vote',
|
type: 'vote',
|
||||||
vote: {
|
vote: {
|
||||||
link: messageId,
|
link: messageKey,
|
||||||
value: Number(value)
|
value: Number(value)
|
||||||
}
|
},
|
||||||
|
recps
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user