mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
chore: remove now-unused notes.assert
This commit is contained in:
@@ -15,75 +15,6 @@ const utils = require('../utils');
|
||||
const activitypub = module.parent.exports;
|
||||
const Notes = module.exports;
|
||||
|
||||
// todo: when asserted, notes aren't added to a global sorted set
|
||||
// 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;
|
||||
let key = `post:${id}`;
|
||||
let exists = await db.exists(key);
|
||||
winston.verbose(`[activitypub/notes.assert] Asserting note id ${id}`);
|
||||
|
||||
if (id && (!exists || options.update === true)) {
|
||||
// Dereference only if a url is received
|
||||
if (activitypub.helpers.isUri(item)) {
|
||||
winston.verbose(`[activitypub/notes.assert] Dereference check for ${id}`);
|
||||
const resolvedId = await activitypub.resolveId(uid, item);
|
||||
if (!resolvedId) {
|
||||
winston.warn(`[activitypub/notes.assert] Not asserting ${item}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (resolvedId !== id) {
|
||||
id = resolvedId;
|
||||
key = `post:${id}`;
|
||||
exists = await db.exists(key);
|
||||
winston.verbose(`[activitypub/notes.assert] Re-asserting note id ${id}`);
|
||||
|
||||
if (exists && options.update !== true) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let postData;
|
||||
winston.verbose(`[activitypub/notes.assert] Not found, retrieving note for persistence...`);
|
||||
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 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;
|
||||
// should call internal method here to create/edit post
|
||||
await db.setObject(key, hash);
|
||||
const post = await posts.getPostData(id);
|
||||
post._activitypub = postData._activitypub;
|
||||
plugins.hooks.fire(`action:post.${(exists && options.update) ? 'edit' : 'save'}`, { post });
|
||||
winston.verbose(`[activitypub/notes.assert] Note ${id} saved.`);
|
||||
}
|
||||
}));
|
||||
|
||||
if (actors.size) {
|
||||
activitypub.actors.assert(Array.from(actors));
|
||||
}
|
||||
};
|
||||
|
||||
Notes.updateLocalRecipients = async (id, { to, cc }) => {
|
||||
const recipients = new Set([...(to || []), ...(cc || [])]);
|
||||
const uids = new Set();
|
||||
|
||||
Reference in New Issue
Block a user