mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
Update notes.js
This commit is contained in:
@@ -54,17 +54,16 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
if (!input) {
|
if (!input) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const start = Date.now();
|
|
||||||
const id = !activitypub.helpers.isUri(input) ? input.id : input;
|
const id = !activitypub.helpers.isUri(input) ? input.id : input;
|
||||||
const lockStatus = await lock(id);
|
const lockStatus = await lock(id);
|
||||||
if (!lockStatus) { // unable to achieve lock, stop processing.
|
if (!lockStatus) { // unable to achieve lock, stop processing.
|
||||||
winston.warn('[activitypub/notes.assert] Unable to acquire lock, skipping processing of', id);
|
winston.warn('[activitypub/notes.assert] Unable to acquire lock, skipping processing of', id);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
console.log(' 4b1', Date.now() - start);
|
|
||||||
let chain;
|
let chain;
|
||||||
let context = await activitypub.contexts.get(uid, id);
|
let context = await activitypub.contexts.get(uid, id);
|
||||||
console.log(' 4b2', Date.now() - start);
|
|
||||||
if (context.tid) {
|
if (context.tid) {
|
||||||
await unlock(id);
|
await unlock(id);
|
||||||
const { tid } = context;
|
const { tid } = context;
|
||||||
@@ -78,13 +77,13 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
} else {
|
} else {
|
||||||
context = undefined;
|
context = undefined;
|
||||||
}
|
}
|
||||||
console.log(' 4b3', Date.now() - start);
|
|
||||||
if (!chain || !chain.length) {
|
if (!chain || !chain.length) {
|
||||||
// Fall back to inReplyTo traversal on context retrieval failure
|
// Fall back to inReplyTo traversal on context retrieval failure
|
||||||
chain = Array.from(await Notes.getParentChain(uid, input));
|
chain = Array.from(await Notes.getParentChain(uid, input));
|
||||||
chain.reverse();
|
chain.reverse();
|
||||||
}
|
}
|
||||||
console.log(' 4b4', Date.now() - start);
|
|
||||||
// Can't resolve — give up.
|
// Can't resolve — give up.
|
||||||
if (!chain.length) {
|
if (!chain.length) {
|
||||||
await unlock(id);
|
await unlock(id);
|
||||||
@@ -99,12 +98,12 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
const hasTid = !!tid;
|
const hasTid = !!tid;
|
||||||
|
|
||||||
const cid = hasTid ? await topics.getTopicField(tid, 'cid') : options.cid || -1;
|
const cid = hasTid ? await topics.getTopicField(tid, 'cid') : options.cid || -1;
|
||||||
console.log(' 4b5', Date.now() - start);
|
|
||||||
if (options.cid && cid === -1) {
|
if (options.cid && cid === -1) {
|
||||||
// Move topic if currently uncategorized
|
// Move topic if currently uncategorized
|
||||||
await topics.tools.move(tid, { cid: options.cid, uid: 'system' });
|
await topics.tools.move(tid, { cid: options.cid, uid: 'system' });
|
||||||
}
|
}
|
||||||
console.log(' 4b6', Date.now() - start);
|
|
||||||
const members = await db.isSortedSetMembers(`tid:${tid}:posts`, chain.slice(1).map(p => p.pid));
|
const members = await db.isSortedSetMembers(`tid:${tid}:posts`, chain.slice(1).map(p => p.pid));
|
||||||
members.unshift(await posts.exists(mainPid));
|
members.unshift(await posts.exists(mainPid));
|
||||||
if (tid && members.every(Boolean)) {
|
if (tid && members.every(Boolean)) {
|
||||||
@@ -113,16 +112,14 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
|
|||||||
await unlock(id);
|
await unlock(id);
|
||||||
return { tid, count: 0 };
|
return { tid, count: 0 };
|
||||||
}
|
}
|
||||||
console.log(' 4b7', Date.now() - start);
|
|
||||||
if (hasTid) {
|
if (hasTid) {
|
||||||
mainPid = await topics.getTopicField(tid, 'mainPid');
|
mainPid = await topics.getTopicField(tid, 'mainPid');
|
||||||
} else {
|
} else {
|
||||||
// Check recipients/audience for category (local or remote)
|
// Check recipients/audience for category (local or remote)
|
||||||
console.log(' 4b8', Date.now() - start);
|
|
||||||
const set = activitypub.helpers.makeSet(_activitypub, ['to', 'cc', 'audience']);
|
const set = activitypub.helpers.makeSet(_activitypub, ['to', 'cc', 'audience']);
|
||||||
console.log(' 4b9', Date.now() - start, Array.from(set));
|
|
||||||
await activitypub.actors.assert(Array.from(set));
|
await activitypub.actors.assert(Array.from(set));
|
||||||
console.log(' 4b10', Date.now() - start);
|
|
||||||
// Local
|
// Local
|
||||||
const resolved = await Promise.all(Array.from(set).map(async id => await activitypub.helpers.resolveLocalId(id)));
|
const resolved = await Promise.all(Array.from(set).map(async id => await activitypub.helpers.resolveLocalId(id)));
|
||||||
const recipientCids = resolved
|
const recipientCids = resolved
|
||||||
@@ -273,7 +270,7 @@ Notes.assertPrivate = async (object) => {
|
|||||||
if (!object || !object.id || !activitypub.helpers.isUri(object.id)) {
|
if (!object || !object.id || !activitypub.helpers.isUri(object.id)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const localUids = [];
|
const localUids = [];
|
||||||
const recipients = new Set([...(object.to || []), ...(object.cc || [])]);
|
const recipients = new Set([...(object.to || []), ...(object.cc || [])]);
|
||||||
await Promise.all(Array.from(recipients).map(async (value) => {
|
await Promise.all(Array.from(recipients).map(async (value) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user