mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: assert actors on note assertion, resolve crash if announcing something that's already been announced
This commit is contained in:
@@ -28,9 +28,12 @@ Actors.assert = async (ids, options = {}) => {
|
||||
return true;
|
||||
}
|
||||
|
||||
winston.verbose(`[activitypub/actors] Asserting ${ids.length} actor(s)`);
|
||||
|
||||
const followersUrlMap = new Map();
|
||||
const actors = await Promise.all(ids.map(async (id) => {
|
||||
try {
|
||||
winston.verbose(`[activitypub/actors] Processing ${id}`);
|
||||
const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? id : await activitypub.get('uid', 0, id);
|
||||
|
||||
// Follow counts
|
||||
|
||||
@@ -23,6 +23,8 @@ Notes.resolveId = async (uid, id) => {
|
||||
// also, db.exists call is probably expensive
|
||||
Notes.assert = async (uid, input, options = {}) => {
|
||||
// Ensures that each note has been saved to the database
|
||||
const actors = new Set();
|
||||
|
||||
await Promise.all(input.map(async (item) => {
|
||||
let id = activitypub.helpers.isUri(item) ? item : item.pid;
|
||||
id = await Notes.resolveId(uid, id);
|
||||
@@ -36,15 +38,19 @@ Notes.assert = async (uid, input, options = {}) => {
|
||||
if (activitypub.helpers.isUri(item)) {
|
||||
// get failure throws for now but should save intermediate object
|
||||
const object = await activitypub.get('uid', uid, item);
|
||||
actors.add(object.attributedTo);
|
||||
postData = await activitypub.mocks.post(object);
|
||||
} else {
|
||||
postData = item;
|
||||
actors.add(item.uid);
|
||||
}
|
||||
|
||||
// Parse ActivityPub-specific data
|
||||
const { to, cc, attachment } = postData._activitypub;
|
||||
await Notes.updateLocalRecipients(id, { to, cc });
|
||||
await Notes.saveAttachments(id, attachment);
|
||||
// Parse ActivityPub-specific data if exists (if not, was parsed already)
|
||||
if (postData.hasOwnProperty('_activityPub')) {
|
||||
const { to, cc, attachment } = postData._activitypub;
|
||||
await Notes.updateLocalRecipients(id, { to, cc });
|
||||
await Notes.saveAttachments(id, attachment);
|
||||
}
|
||||
|
||||
const hash = { ...postData };
|
||||
delete hash._activitypub;
|
||||
@@ -58,6 +64,10 @@ Notes.assert = async (uid, input, options = {}) => {
|
||||
// pubsub.publish('post:edit', String(id));
|
||||
// }
|
||||
}));
|
||||
|
||||
if (actors.size) {
|
||||
activitypub.actors.assert(Array.from(actors));
|
||||
}
|
||||
};
|
||||
|
||||
Notes.updateLocalRecipients = async (id, { to, cc }) => {
|
||||
@@ -98,7 +108,7 @@ Notes.saveAttachments = async (id, attachments) => {
|
||||
},
|
||||
};
|
||||
|
||||
attachments.filter(Boolean).map(({ mediaType, url, name, width, height }, idx) => {
|
||||
attachments.filter(Boolean).forEach(({ mediaType, url, name, width, height }, idx) => {
|
||||
if (!url) { // only required property
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user