Added function for replying to a Quiz request from any platform
* The reply format is just regular HTML (text) which will help the originating user to choose if we can be it's crush
This commit is contained in:
parent
f00aa6d9d8
commit
73bdac849f
|
@ -51,6 +51,20 @@ function quizParse(html, check) {
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function quizResponseBuild(quiz) {
|
||||||
|
var responses = quiz
|
||||||
|
if (quiz.id !== undefined)
|
||||||
|
responses = quiz.responses
|
||||||
|
if (responses === undefined ||
|
||||||
|
responses === null)
|
||||||
|
return false
|
||||||
|
html = '<p>'
|
||||||
|
for (var i = 0; i < responses.length; i++)
|
||||||
|
html += `${i+1}: ${responses[i]}<br>`
|
||||||
|
html += '</p>'
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
async function quizCreate(content, from, to, replyTo) {
|
async function quizCreate(content, from, to, replyTo) {
|
||||||
var quiz = quizParse(content)
|
var quiz = quizParse(content)
|
||||||
if (quiz === false)
|
if (quiz === false)
|
||||||
|
@ -117,8 +131,58 @@ module.exports = {
|
||||||
return res.json(data)
|
return res.json(data)
|
||||||
}],
|
}],
|
||||||
post: [auth.enforceSession, async (req, res) => {
|
post: [auth.enforceSession, async (req, res) => {
|
||||||
console.log(req.body)
|
if (req.body.quiz_id === undefined)
|
||||||
return res.json({})
|
return res.json({ error: 'invalid_params' })
|
||||||
|
|
||||||
|
const quiz = await getQuizs(apID(res.locals.user.username),
|
||||||
|
{ id: req.body.quiz_id })
|
||||||
|
if ([false, undefined, null].includes(quiz))
|
||||||
|
return res.json({ error: 'invalid_params' })
|
||||||
|
|
||||||
|
if (quiz.responses !== undefined)
|
||||||
|
return res.json({ error: 'already_sent_quiz' })
|
||||||
|
|
||||||
|
var responses = []
|
||||||
|
for (var i = 0; i < quiz.content.length; i++) {
|
||||||
|
const q = quiz.content[i]
|
||||||
|
if (q.options.length > 0)
|
||||||
|
if (!q.options.includes(req.body['question_'+i]))
|
||||||
|
return res.json({ error: 'invalid_params' })
|
||||||
|
responses.push(req.body['question_'+i])
|
||||||
|
}
|
||||||
|
if (responses.length !== quiz.content.length)
|
||||||
|
return res.json({ error: 'invalid_params' })
|
||||||
|
|
||||||
|
await db.table.quizs().updateOne({ _id: quiz._id }, { $set: { responses } })
|
||||||
|
html = quizResponseBuild(responses)
|
||||||
|
if (html === false)
|
||||||
|
return res.json({ error: 'invalid_params' })
|
||||||
|
|
||||||
|
const id = utils.apRandomURL()
|
||||||
|
const actor = await apex.store.getObject(
|
||||||
|
apID(res.locals.user.username), true)
|
||||||
|
const payload = {
|
||||||
|
id: id+'#activity',
|
||||||
|
type: 'Create',
|
||||||
|
actor: actor.id,
|
||||||
|
to: quiz.from.url,
|
||||||
|
object: {
|
||||||
|
id,
|
||||||
|
type: 'Note',
|
||||||
|
content: html,
|
||||||
|
to: quiz.from.url,
|
||||||
|
attributedTo: actor.id,
|
||||||
|
inReplyTo: quiz.replyTo,
|
||||||
|
tag: [{
|
||||||
|
type: 'Mention',
|
||||||
|
href: quiz.from.url,
|
||||||
|
name: quiz.from.acct,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
await apex.addToOutbox(actor, payload)
|
||||||
|
await apex.store.saveObject(payload.object)
|
||||||
|
return res.json({ result: 1 })
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
pending_follows: {
|
pending_follows: {
|
||||||
|
|
|
@ -52,6 +52,7 @@ $strings = [
|
||||||
'follow_pending' => 'This person has not yet accepted to be your crush',
|
'follow_pending' => 'This person has not yet accepted to be your crush',
|
||||||
'follow_rejected_max' => 'You have reached the limit of crush requests on this person',
|
'follow_rejected_max' => 'You have reached the limit of crush requests on this person',
|
||||||
'user_blocked_you' => 'We are sorry, this person rejected to be your crush. You will find another love soon!',
|
'user_blocked_you' => 'We are sorry, this person rejected to be your crush. You will find another love soon!',
|
||||||
|
'already_sent_quiz' => 'Sorry, you can\'t send the Quiz again. It was already sent.',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -52,6 +52,7 @@ $strings = [
|
||||||
'follow_pending' => 'Esta persona todavía no ha aceptado ser tu crush',
|
'follow_pending' => 'Esta persona todavía no ha aceptado ser tu crush',
|
||||||
'follow_rejected_max' => 'Has alcanzado el límite de peticiones de crush para esta persona',
|
'follow_rejected_max' => 'Has alcanzado el límite de peticiones de crush para esta persona',
|
||||||
'user_blocked_you' => 'Lo sentimos, esta persona ha rechazado ser su crush. ¡Encontrarás a otra persona pronto!',
|
'user_blocked_you' => 'Lo sentimos, esta persona ha rechazado ser su crush. ¡Encontrarás a otra persona pronto!',
|
||||||
|
'already_sent_quiz' => 'Lo siento, no puedes enviar este Quiz de nuevo. Ya ha sido enviado antes.',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue