Skip to content

Node.js based forum software built for the modern web

feat: Create Activity Intent handler landing page controller + view

Julian Lam43e383a085f1
diff --git a/public/src/client/intents/create.js b/public/src/client/intents/create.js
new file mode 100644
index 0000000000..285426c82d
--- /dev/null
+++ b/public/src/client/intents/create.js
@@ -0,0 +1,5 @@
+'use strict';
+
+export function init() {
+ console.log('here');
+}
\ No newline at end of file
diff --git a/src/controllers/intents.js b/src/controllers/intents.js
new file mode 100644
index 0000000000..c45e89016f
--- /dev/null
+++ b/src/controllers/intents.js
@@ -0,0 +1,71 @@
+'use strict';
+
+const posts = require('../posts');
+const categories = require('../categories');
+const helpers = require('./helpers');
+const activitypub = require('../activitypub');
+const utils = require('../utils');
+
+const Intents = module.exports;
+
+Intents.create = async (req, res, next) => {
+ if (!req.uid) {
+ req.session.returnTo = req.originalUrl;
+ helpers.redirect(res, '/login');
+ }
+
+ const payload = {};
+
+ if (req.query?.toPid) {
+ let { toPid } = req.query;
+
+ if (!utils.isNumber(toPid)) {
+ const resolved = await activitypub.helpers.resolveLocalId(toPid);
+ const { type, id: localId } = resolved || {};
+ if (type === 'post') {
+ toPid = localId || toPid;
+ }
+ }
+
+ if (utils.isNumber(toPid)) {
+ console.log(toPid);
+ // Local post ID — verify it exists
+ const exists = await posts.exists(toPid);
+ if (exists) {
+ const tid = await posts.getPostField(toPid, 'tid');
+ if (tid) {
+ payload.tid = tid;
+ }
+ }
+ } else {
+ // Not a valid local post — assert as ActivityPub note
+ const result = await activitypub.notes.assert(0, toPid);
+ if (result && result.tid) {
+ payload.tid = result.tid;
+ }
+ }
+ } else if (req.query?.cid) {
+ let { cid } = req.query;
+
+ if (!utils.isNumber(cid)) {
+ const resolved = await activitypub.helpers.resolveLocalId(cid);
+ const { type, id: localId } = resolved || {};
+ if (type === 'category') {
+ cid = localId || cid;
+ }
+ }
+
+ // Verify category exists
+ const exists = await categories.exists(cid);
+ if (!exists) {
+ return next();
+ }
+ payload.cid = cid;
+ }
+
+ if (!['tid', 'cid'].some(prop => payload.hasOwnProperty(prop))) {
+ return next();
+ }
+
+ res.render('intents/create', payload);
+};
\ No newline at end of file
diff --git a/src/views/intents/create.tpl b/src/views/intents/create.tpl
new file mode 100644
index 0000000000..72dc7194b8
--- /dev/null
+++ b/src/views/intents/create.tpl
@@ -0,0 +1,3 @@
+<div class="text-center mt-5">
+ <p class="text-muted">Please wait&hellip;</p>
+</div>