Skip to content

Node.js based forum software built for the modern web

chore: move assertNote to separate file in preparation for additional note-based methods

Julian Lam2b3b6e56af3e
diff --git a/src/activitypub/index.js b/src/activitypub/index.js
index 7ea72e6703..2c6ca9d1c4 100644
--- a/src/activitypub/index.js
+++ b/src/activitypub/index.js
@@ -15,6 +15,7 @@ const ActivityPub = module.exports;
ActivityPub.helpers = require('./helpers');
ActivityPub.inbox = require('./inbox');
ActivityPub.mocks = require('./mocks');
+ActivityPub.notes = require('./notes');
ActivityPub.getActor = async (uid, input) => {
// Can be a webfinger id, uri, or object, handle as appropriate
@@ -61,25 +62,6 @@ ActivityPub.resolveInboxes = async (uid, ids) => await Promise.all(ids.map(async
return actor.inbox;
}));
-ActivityPub.assertNotes = async (uid, ids) => {
- // Ensures that each note has been saved to the database
- const keys = ids.map(id => `post:${id}`);
-
- await Promise.all(ids.map(async (id, idx) => {
- const key = keys[idx];
- const exists = await db.exists(key);
- winston.verbose(`[activitypub/assertNotes] Asserting note id ${id}`);
-
- let postData;
- if (!exists) {
- winston.verbose(`[activitypub/assertNotes] Not found, saving note to database`);
- const object = await ActivityPub.get(uid, id);
- postData = await ActivityPub.mocks.post(object);
- await db.setObject(key, postData);
- }
- }));
-};
-
ActivityPub.getPublicKey = async (uid) => {
let publicKey;
diff --git a/src/posts/index.js b/src/posts/index.js
index 3a5c59dd61..aaa520ed1f 100644
--- a/src/posts/index.js
+++ b/src/posts/index.js
@@ -47,7 +47,7 @@ Posts.getPostsByPids = async function (pids, uid) {
}
const remotePids = pids.filter(pid => !utils.isNumber(pid));
- await activitypub.assertNotes(uid, remotePids);
+ await activitypub.notes.assert(uid, remotePids);
let posts = await Posts.getPostsData(pids);
posts = await Promise.all(posts.map(Posts.parsePost));
const data = await plugins.hooks.fire('filter:post.getPosts', { posts: posts, uid: uid });
diff --git a/src/topics/posts.js b/src/topics/posts.js
index 47918530df..eb7b51bfc0 100644
--- a/src/topics/posts.js
+++ b/src/topics/posts.js
@@ -187,7 +187,7 @@ module.exports = function (Topics) {
return;
}
parentPids = _.uniq(parentPids);
- await activitypub.assertNotes(uid, parentPids.filter(pid => activitypub.helpers.isUri(pid)));
+ await activitypub.notes.assert(uid, parentPids.filter(pid => activitypub.helpers.isUri(pid)));
const parentPosts = await posts.getPostsFields(parentPids, ['uid']);
const parentUids = _.uniq(parentPosts.map(postObj => postObj && postObj.uid));
const userData = await user.getUsersFields(parentUids, ['username']);