From 28e5c64ad103ed53a14ac2ee284a12b260c52215 Mon Sep 17 00:00:00 2001 From: insert Date: Sat, 19 Aug 2023 20:08:20 -0400 Subject: [PATCH] More options in the mod ui --- index.js | 69 +++++++++++++++++++++++++++++++++- web/src/views/Moderation.vue | 72 ++++++++++++++++++++++++++++++------ 2 files changed, 127 insertions(+), 14 deletions(-) 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 @@

Moderation for {{name}}

@@ -26,13 +34,17 @@ export default { type: String, required: true, } + }, data () { return { queue: [], + posts: [], error: null, name: this.name, userdata: this.userdata, + userdescription: this.userdescription, + username: this.username, domain: window.location.host } }, @@ -85,8 +97,8 @@ export default { }) .catch(err => (this.error = err.message)) }, - save: function (name, description, username) { - window.fetch(`/mod/changedata?name=${name}&description=${description}&username=${username}`, { + deletepost: function (name, id) { + window.fetch(`/mod/delete?name=${name}&id=${id}`, { method: 'get', headers: { accept: 'application/json' @@ -96,8 +108,6 @@ export default { console.log("test3") console.log(json) }) - }, - created () { window.fetch(`/mod/data?name=${this.name}`, { method: 'get', headers: { @@ -110,6 +120,48 @@ export default { this.queue = json }) .catch(err => (this.error = err.message)) + }, + save: function (name, description, username) { + window.fetch(`/mod/changedata?name=${name}&description=${description}&username=${username}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test3") + console.log(json) + }) + }, + previewFiles(event) { + console.log(event.target.files); + } + }, + created () { + window.fetch(`/mod/data/queue?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test2") + console.log(json) + this.queue = json + }) + .catch(err => (this.error = err.message)) + window.fetch(`/mod/data/posts?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test2") + console.log(json) + this.posts = json + }) + .catch(err => (this.error = err.message)) window.fetch(`/mod/userinfo?name=${this.name}`, { method: 'get', headers: { @@ -120,18 +172,14 @@ export default { console.log("test4") console.log(json) this.userdata = json + this.userdescription = json.summary[0] + this.username = json.name[0] }) .catch(err => (this.error = err.message)) } } -