Try to handle Deletes (not currently working)
This commit is contained in:
parent
3ddb8ad28f
commit
81e2fca2aa
|
@ -35,6 +35,10 @@ export interface Note extends Activity {
|
||||||
conversation: string;
|
conversation: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Delete extends Activity {
|
||||||
|
object: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Actor {
|
export interface Actor {
|
||||||
id: string;
|
id: string;
|
||||||
inbox: string;
|
inbox: string;
|
||||||
|
|
|
@ -14,6 +14,7 @@ export default function conversation(router: Router) {
|
||||||
} else {
|
} else {
|
||||||
const notes = rows.map(row => {
|
const notes = rows.map(row => {
|
||||||
return {
|
return {
|
||||||
|
id: row.id,
|
||||||
attributedTo: row.attributed_to,
|
attributedTo: row.attributed_to,
|
||||||
content: row.content,
|
content: row.content,
|
||||||
published: row.published,
|
published: row.published,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Router, Request, Response } from "express";
|
import { Router, Request, Response } from "express";
|
||||||
import uuidv4 from "uuid/v4";
|
import uuidv4 from "uuid/v4";
|
||||||
import { fetchActor, signAndSend } from "./federate";
|
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 { Database } from "sqlite3";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
import sanitizeHtml from "sanitize-html";
|
import sanitizeHtml from "sanitize-html";
|
||||||
|
@ -22,6 +22,8 @@ async function handleInbox(req: Request, res: Response) {
|
||||||
handleCreate(activity, req, res);
|
handleCreate(activity, req, res);
|
||||||
} else if (activity.type === "Undo") {
|
} else if (activity.type === "Undo") {
|
||||||
handleUndo(activity, req, res);
|
handleUndo(activity, req, res);
|
||||||
|
} else if (activity.type === "Delete") {
|
||||||
|
handleDelete(activity, req, res);
|
||||||
} else {
|
} else {
|
||||||
res.end(); // TODO: handle this better
|
res.end(); // TODO: handle this better
|
||||||
}
|
}
|
||||||
|
@ -95,9 +97,22 @@ async function handleCreateNote(create: Create, req: Request, res: Response) {
|
||||||
$published: note.published
|
$published: note.published
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
if (err) console.error(`Encountered error storing reply ${note.id}`, 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) {
|
async function handleUndo(activity: Activity, req: Request, res: Response) {
|
||||||
const undo = activity as Undo;
|
const undo = activity as Undo;
|
||||||
if (undo.object.type === "Follow") {
|
if (undo.object.type === "Follow") {
|
||||||
|
|
Loading…
Reference in New Issue