diff --git a/index.js b/index.js index 345245f..1df95eb 100644 --- a/index.js +++ b/index.js @@ -179,6 +179,7 @@ app.on('apex-inbox', async ({ actor, activity, recipient, object }) => { switch (activity.type.toLowerCase()) { // automatically reshare incoming posts case 'create': { + console.log(activity.object[0].inReplyTo) const to = [ recipient.followers[0], apex.consts.publicAddress @@ -189,6 +190,7 @@ app.on('apex-inbox', async ({ actor, activity, recipient, object }) => { cc: actor.id }) //stop here, we can add the activity to the database, we'll handle it if it passes inspection, otherwise no + console.log(activity.object[0].id) console.log(share) await apex.store.db.collection(`${recipient.id}-queue`).insertOne(share) //console.log(apex.store.db.collection(`${recipient.id}-queue`) @@ -213,6 +215,16 @@ app.on('apex-inbox', async ({ actor, activity, recipient, object }) => { await apex.addToOutbox(recipient, accept) return publishUpdatedFollowers() } + case 'delete': { + const queuefind = await apex.store.db.collection(`${recipient.id}-queue`).findOne( {object: [activity.object[0].id]} ) + if (queuefind) { + await apex.store.db.collection(`${recipient.id}-queue`).remove( {object: [activity.object[0].id]} ) + } + const postfind = await apex.store.db.collection(`${recipient.id}-posts`).findOne( {object: [activity.object[0].id]} ) + if (postfind) { + await apex.store.db.collection(`${recipient.id}-posts`).remove( {object: [activity.object[0].id]} ) + } + } } }) @@ -269,14 +281,33 @@ app.get('/stats', async (req, res, next) => { app.get('/mod/userinfo', async (req, res, next) => { try { - object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) + const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) res.json(object) } catch (err) { next(err) } }) -app.get('/mod/data', async (req, res, next) => { +app.get('/mod/changedata', async (req, res, next) => { + try { + var oldobject = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name), true) + const newgroup = await createGuppeActor(req.query.name, req.query.username, req.query.description, icon, 'Group') + const to = [ + oldobject.followers[0], + apex.consts.publicAddress + ] + const share = await apex.buildActivity('Update', oldobject.id, to, { + object: newgroup + }) + apex.addToOutbox(oldobject, share) + await apex.store.updateObject(newgroup, oldobject.id, true) + res.json(newgroup) + } catch (err) { + next(err) + } +}) + +app.get('/mod/data/queue', async (req, res, next) => { try { const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) const queueSize = await apex.store.db.collection(`${object.id}-queue`).find().toArray() @@ -288,6 +319,18 @@ app.get('/mod/data', async (req, res, next) => { } }) +app.get('/mod/data/posts', async (req, res, next) => { + try { + const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) + const queueSize = await apex.store.db.collection(`${object.id}-posts`).find().toArray() + // console.log(res.json({queueSize})) + console.log(queueSize) + res.json(queueSize) + } catch (err) { + next(err) + } +}) + app.get('/mod/approve', async (req, res, next) => { try { console.log("recived") @@ -297,6 +340,7 @@ app.get('/mod/approve', async (req, res, next) => { //const keys = await apex.store.db.collection(`keys`).findOne( {id: object.id} ) const dbout = await apex.store.db.collection(`${object.id}-queue`).findOne( {object: [req.query.id]} ) //console.log(keys) + await apex.store.db.collection(`${object.id}-posts`).insertOne(dbout) apex.addToOutbox(object, dbout) await apex.store.db.collection(`${object.id}-queue`).remove( {object: [req.query.id]} ) res.json(dbout) @@ -318,6 +362,27 @@ app.get('/mod/deny', async (req, res, next) => { } }) +app.get('/mod/delete', async (req, res, next) => { + try { + console.log("recived") + const actor = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name), true) + var dbout = await apex.store.db.collection(`${actor.id}-posts`).findOne( {object: [req.query.id]} ) + const to = [ + actor.followers[0], + apex.consts.publicAddress + ] + const share = await apex.buildActivity('Undo', actor.id, to, { + object: dbout + }) + apex.addToOutbox(actor, share) + + await apex.store.db.collection(`${actor.id}-posts`).remove( {object: [req.query.id]} ) + res.json(share) + } catch (err) { + next(err) + } +}) + app.use(function (err, req, res, next) { console.error(err.message, req.body, err.stack) if (!res.headersSent) { diff --git a/web/src/views/Moderation.vue b/web/src/views/Moderation.vue index 2c56318..9afd5d9 100644 --- a/web/src/views/Moderation.vue +++ b/web/src/views/Moderation.vue @@ -3,15 +3,23 @@