From 49ce1635474ea331521d9d39215d72bfe3643084 Mon Sep 17 00:00:00 2001 From: Darius Kazemi Date: Tue, 26 Mar 2019 00:01:34 -0700 Subject: [PATCH] Fixing remaining better-sqlite bugs, fixing pleroma messagin --- routes/api.js | 8 +++++--- routes/inbox.js | 2 +- routes/message.js | 15 +++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/routes/api.js b/routes/api.js index b9a48c4..d80a474 100644 --- a/routes/api.js +++ b/routes/api.js @@ -60,7 +60,7 @@ function signAndSend(message, name, domain, req, res, targetDomain, inbox) { } } -function createMessage(text, name, domain, req, res) { +function createMessage(text, name, domain, req, res, follower) { const guidCreate = crypto.randomBytes(16).toString('hex'); const guidNote = crypto.randomBytes(16).toString('hex'); let db = req.app.get('db'); @@ -72,7 +72,7 @@ function createMessage(text, name, domain, req, res) { 'published': d.toISOString(), 'attributedTo': `https://${domain}/u/${name}`, 'content': text, - 'to': 'https://www.w3.org/ns/activitystreams#Public' + 'to': ['https://www.w3.org/ns/activitystreams#Public'], }; let createMessage = { @@ -81,6 +81,8 @@ function createMessage(text, name, domain, req, res) { 'id': `https://${domain}/m/${guidCreate}`, 'type': 'Create', 'actor': `https://${domain}/u/${name}`, + 'to': ['https://www.w3.org/ns/activitystreams#Public'], + 'cc': [follower], 'object': noteMessage }; @@ -92,7 +94,6 @@ function createMessage(text, name, domain, req, res) { } function sendCreateMessage(text, name, domain, req, res) { - let message = createMessage(text, name, domain, req, res); let db = req.app.get('db'); let result = db.prepare('select followers from accounts where name = ?').get(`${name}@${domain}`); @@ -108,6 +109,7 @@ function sendCreateMessage(text, name, domain, req, res) { let inbox = follower+'/inbox'; let myURL = new URL(follower); let targetDomain = myURL.hostname; + let message = createMessage(text, name, domain, req, res, follower); signAndSend(message, name, domain, req, res, targetDomain, inbox); } res.status(200).json({msg: 'ok'}); diff --git a/routes/inbox.js b/routes/inbox.js index 359931a..424f1ee 100644 --- a/routes/inbox.js +++ b/routes/inbox.js @@ -10,7 +10,7 @@ function signAndSend(message, name, domain, req, res, targetDomain) { let inboxFragment = inbox.replace('https://'+targetDomain,''); // get the private key let db = req.app.get('db'); - let result = db.prepare('select privkey from accounts where name = ?').get(name); + let result = db.prepare('select privkey from accounts where name = ?').get(`${name}@${domain}`); if (result === undefined) { return res.status(404).send(`No record found for ${name}.`); } diff --git a/routes/message.js b/routes/message.js index 3b819ac..f002277 100644 --- a/routes/message.js +++ b/routes/message.js @@ -9,14 +9,13 @@ router.get('/:guid', function (req, res) { } else { let db = req.app.get('db'); - db.get('select message from messages where guid = $guid', {$guid: guid}, (err, result) => { - if (result === undefined) { - return res.status(404).send(`No record found for ${guid}.`); - } - else { - res.json(JSON.parse(result.message)); - } - }); + let result = db.prepare('select message from messages where guid = ?').get(guid); + if (result === undefined) { + return res.status(404).send(`No record found for ${guid}.`); + } + else { + res.json(JSON.parse(result.message)); + } } });