Try to handle Deletes (not currently working)

This commit is contained in:
Shadowfacts 2019-02-21 19:26:24 -05:00
parent 3ddb8ad28f
commit 81e2fca2aa
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 21 additions and 1 deletions

View File

@ -35,6 +35,10 @@ export interface Note extends Activity {
conversation: string;
}
export interface Delete extends Activity {
object: string;
}
export interface Actor {
id: string;
inbox: string;

View File

@ -14,6 +14,7 @@ export default function conversation(router: Router) {
} else {
const notes = rows.map(row => {
return {
id: row.id,
attributedTo: row.attributed_to,
content: row.content,
published: row.published,

View File

@ -1,7 +1,7 @@
import { Router, Request, Response } from "express";
import uuidv4 from "uuid/v4";
import { fetchActor, signAndSend } from "./federate";
import { Activity, Follow, Accept, Undo, Create, Note } from "./activity";
import { Activity, Follow, Accept, Undo, Create, Note, Delete } from "./activity";
import { Database } from "sqlite3";
import { URL } from "url";
import sanitizeHtml from "sanitize-html";
@ -22,6 +22,8 @@ async function handleInbox(req: Request, res: Response) {
handleCreate(activity, req, res);
} else if (activity.type === "Undo") {
handleUndo(activity, req, res);
} else if (activity.type === "Delete") {
handleDelete(activity, req, res);
} else {
res.end(); // TODO: handle this better
}
@ -95,9 +97,22 @@ async function handleCreateNote(create: Create, req: Request, res: Response) {
$published: note.published
}, (err) => {
if (err) console.error(`Encountered error storing reply ${note.id}`, err);
res.end();
});
}
async function handleDelete(activity: Activity, req: Request, res: Response) {
const deleteActivity = activity as Delete;
const db = req.app.get("db") as Database;
db.run("DELETE FROM notes WHERE id = $id, actor = $actor", {
$id: deleteActivity.object,
$actor: deleteActivity.actor
}, (err) => {
if (err) console.error(`Encountered error deleting ${deleteActivity.object}`, err);
res.end();
})
}
async function handleUndo(activity: Activity, req: Request, res: Response) {
const undo = activity as Undo;
if (undo.object.type === "Follow") {