mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-27 17:16:14 +01:00 
			
		
		
		
	chore: move assertNote to separate file in preparation for additional note-based methods
This commit is contained in:
		| @@ -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; | ||||
|  | ||||
|   | ||||
| @@ -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 }); | ||||
|   | ||||
| @@ -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']); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user