mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	fix: additional refactors and updates to follow/unfollow logic
This commit is contained in:
		| @@ -32,7 +32,7 @@ inbox.follow = async (req) => { | |||||||
| 		type: 'Accept', | 		type: 'Accept', | ||||||
| 		object: { | 		object: { | ||||||
| 			type: 'Follow', | 			type: 'Follow', | ||||||
| 			actor: from.actorUri, | 			actor: from.id, | ||||||
| 		}, | 		}, | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ ActivityPub.getActor = async (input) => { | |||||||
| 		require_host: true, | 		require_host: true, | ||||||
| 		protocols: ['https'], | 		protocols: ['https'], | ||||||
| 		require_valid_protocol: true, | 		require_valid_protocol: true, | ||||||
|  | 		require_tld: false, | ||||||
| 	})) { | 	})) { | ||||||
| 		uri = input; | 		uri = input; | ||||||
| 	} else if (input.indexOf('@') !== -1) { // Webfinger | 	} else if (input.indexOf('@') !== -1) { // Webfinger | ||||||
| @@ -177,15 +178,11 @@ ActivityPub.send = async (uid, targets, payload) => { | |||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	await Promise.all(inboxes.map(async (uri) => { | 	await Promise.all(inboxes.map(async (uri) => { | ||||||
| 		const { date, digest, signature } = await ActivityPub.sign(uid, uri, payload); | 		const headers = await ActivityPub.sign(uid, uri, payload); | ||||||
|  |  | ||||||
| 		const { response } = await request.post(uri, { | 		const { response } = await request.post(uri, { | ||||||
| 			headers: { | 			headers: { | ||||||
| 				date, | 				...headers, | ||||||
| 				digest, |  | ||||||
| 				signature, |  | ||||||
| 				'content-type': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', | 				'content-type': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', | ||||||
| 				accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', |  | ||||||
| 			}, | 			}, | ||||||
| 			body: payload, | 			body: payload, | ||||||
| 		}); | 		}); | ||||||
|   | |||||||
| @@ -8,20 +8,23 @@ | |||||||
|  * If you use api methods in this file, be prepared that they may be removed or modified with no warning. |  * If you use api methods in this file, be prepared that they may be removed or modified with no warning. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
|  | const nconf = require('nconf'); | ||||||
|  |  | ||||||
| const db = require('../database'); | const db = require('../database'); | ||||||
| const activitypub = require('../activitypub'); | const activitypub = require('../activitypub'); | ||||||
|  | const user = require('../user'); | ||||||
|  |  | ||||||
| const activitypubApi = module.exports; | const activitypubApi = module.exports; | ||||||
|  |  | ||||||
| activitypubApi.follow = async (caller, { actorId } = {}) => { | activitypubApi.follow = async (caller, { actorId } = {}) => { | ||||||
| 	const object = activitypub.getActor(actorId); | 	const object = await activitypub.getActor(actorId); | ||||||
| 	if (!object) { | 	if (!object) { | ||||||
| 		throw new Error('[[error:invalid-uid]]'); // should be activitypub-specific | 		throw new Error('[[error:invalid-uid]]'); // should be activitypub-specific | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	await activitypub.send(caller.uid, actorId, { | 	await activitypub.send(caller.uid, actorId, { | ||||||
| 		type: 'Follow', | 		type: 'Follow', | ||||||
| 		object: object.actorUri, | 		object: object.id, | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
| 	const now = Date.now(); | 	const now = Date.now(); | ||||||
| @@ -32,15 +35,18 @@ activitypubApi.follow = async (caller, { actorId } = {}) => { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| activitypubApi.unfollow = async (caller, { actorId }) => { | activitypubApi.unfollow = async (caller, { actorId }) => { | ||||||
| 	if (!actorId) { | 	const object = await activitypub.getActor(actorId); | ||||||
|  | 	const userslug = await user.getUserField(caller.uid, 'userslug'); | ||||||
|  | 	if (!object) { | ||||||
| 		throw new Error('[[error:invalid-uid]]'); // should be activitypub-specific | 		throw new Error('[[error:invalid-uid]]'); // should be activitypub-specific | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	await activitypub.send(caller.uid, actorId, { | 	await activitypub.send(caller.uid, actorId, { | ||||||
| 		type: 'Unfollow', | 		type: 'Undo', | ||||||
| 		object: { | 		object: { | ||||||
| 			type: 'Person', | 			type: 'Follow', | ||||||
| 			name: actorId, | 			actor: `${nconf.get('url')}/user/${userslug}`, | ||||||
|  | 			object: object.id, | ||||||
| 		}, | 		}, | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user