Skip to content

Node.js based forum software built for the modern web

fix: if an unknown post is navigated to by a logged-in user, automatically assert the post and add it to their inbox

Julian Lam4e7b12b92575
diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js
index f3608e5c4f..d808f3abac 100644
--- a/src/activitypub/notes.js
+++ b/src/activitypub/notes.js
@@ -76,7 +76,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
mainPid = utils.isNumber(mainPid) ? parseInt(mainPid, 10) : mainPid;
// Relation & privilege check for local categories
- const hasRelation = options.skipChecks || options.cid || hasTid || await assertRelation(chain[0]);
+ const hasRelation = uid || options.skipChecks || options.cid || hasTid || await assertRelation(chain[0]);
const privilege = `topics:${tid ? 'reply' : 'create'}`;
const allowed = await privileges.categories.can(privilege, cid, activitypub._constants.uid);
if (!hasRelation || !allowed) {
@@ -168,7 +168,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
}
await Promise.all([
- Notes.syncUserInboxes(tid),
+ Notes.syncUserInboxes(tid, uid),
unlock(id),
]);
@@ -282,7 +282,7 @@ Notes.getParentChain = async (uid, input) => {
return chain;
};
-Notes.syncUserInboxes = async function (tid) {
+Notes.syncUserInboxes = async function (tid, uid) {
const [pids, { cid, mainPid }] = await Promise.all([
db.getSortedSetMembers(`tid:${tid}:posts`),
topics.getTopicFields(tid, ['tid', 'cid', 'mainPid']),
@@ -291,6 +291,10 @@ Notes.syncUserInboxes = async function (tid) {
const recipients = await db.getSetsMembers(pids.map(id => `post:${id}:recipients`));
const uids = recipients.reduce((set, uids) => new Set([...set, ...uids.map(u => parseInt(u, 10))]), new Set());
+ if (uid) {
+ uids.add(parseInt(uid, 10));
+ }
+
const keys = Array.from(uids).map(uid => `uid:${uid}:inbox`);
const score = await db.sortedSetScore(`cid:${cid}:tids`, tid);
diff --git a/src/controllers/posts.js b/src/controllers/posts.js
index 3b3d5b3b82..2b08558a9a 100644
--- a/src/controllers/posts.js
+++ b/src/controllers/posts.js
@@ -6,6 +6,7 @@ const querystring = require('querystring');
const meta = require('../meta');
const posts = require('../posts');
const privileges = require('../privileges');
+const activitypub = require('../activitypub');
const utils = require('../utils');
const helpers = require('./helpers');
@@ -18,6 +19,14 @@ postsController.redirectToPost = async function (req, res, next) {
return next();
}
+ // Kickstart note assertion if applicable
+ if (!utils.isNumber(pid) && req.uid) {
+ const exists = await posts.exists(pid);
+ if (!exists) {
+ await activitypub.notes.assert(req.uid, pid);
+ }
+ }
+
const [canRead, path] = await Promise.all([
privileges.posts.can('topics:read', pid, req.uid),
posts.generatePostPath(pid, req.uid),