mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
fix: if an unknown post is navigated to by a logged-in user, automatically assert the post and add it to their inbox
This commit is contained in:
@@ -76,7 +76,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
mainPid = utils.isNumber(mainPid) ? parseInt(mainPid, 10) : mainPid;
|
mainPid = utils.isNumber(mainPid) ? parseInt(mainPid, 10) : mainPid;
|
||||||
|
|
||||||
// Relation & privilege check for local categories
|
// 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 privilege = `topics:${tid ? 'reply' : 'create'}`;
|
||||||
const allowed = await privileges.categories.can(privilege, cid, activitypub._constants.uid);
|
const allowed = await privileges.categories.can(privilege, cid, activitypub._constants.uid);
|
||||||
if (!hasRelation || !allowed) {
|
if (!hasRelation || !allowed) {
|
||||||
@@ -168,7 +168,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
Notes.syncUserInboxes(tid),
|
Notes.syncUserInboxes(tid, uid),
|
||||||
unlock(id),
|
unlock(id),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -282,7 +282,7 @@ Notes.getParentChain = async (uid, input) => {
|
|||||||
return chain;
|
return chain;
|
||||||
};
|
};
|
||||||
|
|
||||||
Notes.syncUserInboxes = async function (tid) {
|
Notes.syncUserInboxes = async function (tid, uid) {
|
||||||
const [pids, { cid, mainPid }] = await Promise.all([
|
const [pids, { cid, mainPid }] = await Promise.all([
|
||||||
db.getSortedSetMembers(`tid:${tid}:posts`),
|
db.getSortedSetMembers(`tid:${tid}:posts`),
|
||||||
topics.getTopicFields(tid, ['tid', 'cid', 'mainPid']),
|
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 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());
|
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 keys = Array.from(uids).map(uid => `uid:${uid}:inbox`);
|
||||||
const score = await db.sortedSetScore(`cid:${cid}:tids`, tid);
|
const score = await db.sortedSetScore(`cid:${cid}:tids`, tid);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const querystring = require('querystring');
|
|||||||
const meta = require('../meta');
|
const meta = require('../meta');
|
||||||
const posts = require('../posts');
|
const posts = require('../posts');
|
||||||
const privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
|
const activitypub = require('../activitypub');
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
|
|
||||||
const helpers = require('./helpers');
|
const helpers = require('./helpers');
|
||||||
@@ -18,6 +19,14 @@ postsController.redirectToPost = async function (req, res, next) {
|
|||||||
return 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([
|
const [canRead, path] = await Promise.all([
|
||||||
privileges.posts.can('topics:read', pid, req.uid),
|
privileges.posts.can('topics:read', pid, req.uid),
|
||||||
posts.generatePostPath(pid, req.uid),
|
posts.generatePostPath(pid, req.uid),
|
||||||
|
|||||||
Reference in New Issue
Block a user