mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	feat: handle Update(note)
This commit is contained in:
		| @@ -23,6 +23,18 @@ inbox.create = async (req) => { | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| inbox.update = async (req) => { | ||||
| 	const { object } = req.body; | ||||
| 	const postData = await activitypub.mocks.post(object); | ||||
|  | ||||
| 	if (postData) { | ||||
| 		await activitypub.notes.assert(1, [postData], { update: true }); | ||||
| 		winston.info(`[activitypub/inbox] Updating note ${postData.pid}`); | ||||
| 	} else { | ||||
| 		winston.warn('[activitypub/inbox] Received object was not a note'); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| inbox.follow = async (req) => { | ||||
| 	// Sanity checks | ||||
| 	const localUid = await helpers.resolveLocalUid(req.body.object); | ||||
|   | ||||
| @@ -15,14 +15,18 @@ Notes.resolveId = async (uid, id) => { | ||||
|  | ||||
| // todo: when asserted, notes aren't added to a global sorted set | ||||
| // also, db.exists call is probably expensive | ||||
| Notes.assert = async (uid, input) => { | ||||
| Notes.assert = async (uid, input, options = {}) => { | ||||
| 	// Ensures that each note has been saved to the database | ||||
| 	await Promise.all(input.map(async (item) => { | ||||
| 		const id = activitypub.helpers.isUri(item) ? item : item.pid; | ||||
| 		const key = `post:${id}`; | ||||
| 		const exists = await db.exists(key); | ||||
| 		let exists = await db.exists(key); | ||||
| 		winston.verbose(`[activitypub/notes.assert] Asserting note id ${id}`); | ||||
|  | ||||
| 		if (options.update === true) { | ||||
| 			exists = false; | ||||
| 		} | ||||
|  | ||||
| 		if (!exists) { | ||||
| 			let postData; | ||||
| 			winston.verbose(`[activitypub/notes.assert] Not found, saving note to database`); | ||||
|   | ||||
| @@ -110,6 +110,11 @@ Controller.postInbox = async (req, res) => { | ||||
| 			break; | ||||
| 		} | ||||
|  | ||||
| 		case 'Update': { | ||||
| 			await activitypub.inbox.update(req); | ||||
| 			break; | ||||
| 		} | ||||
|  | ||||
| 		case 'Follow': { | ||||
| 			await activitypub.inbox.follow(req); | ||||
| 			break; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user