mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	feat: Like(Note) and Undo(Like); federating likes
This commit is contained in:
		| @@ -28,6 +28,7 @@ activitypubApi.follow = async (caller, { uid } = {}) => { | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| // should be .undo.follow | ||||
| activitypubApi.unfollow = async (caller, { uid }) => { | ||||
| 	const result = await activitypub.helpers.query(uid); | ||||
| 	if (!result) { | ||||
| @@ -112,3 +113,45 @@ activitypubApi.update.note = async (caller, { post }) => { | ||||
|  | ||||
| 	await activitypub.send(caller.uid, Array.from(targets), payload); | ||||
| }; | ||||
|  | ||||
| activitypubApi.like = {}; | ||||
|  | ||||
| activitypubApi.like.note = async (caller, { pid }) => { | ||||
| 	if (!activitypub.helpers.isUri(pid)) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	const uid = await posts.getPostField(pid, 'uid'); | ||||
| 	if (!activitypub.helpers.isUri(uid)) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	await activitypub.send(caller.uid, [uid], { | ||||
| 		type: 'Like', | ||||
| 		object: pid, | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| activitypubApi.undo = {}; | ||||
|  | ||||
| // activitypubApi.undo.follow = | ||||
|  | ||||
| activitypubApi.undo.like = async (caller, { pid }) => { | ||||
| 	if (!activitypub.helpers.isUri(pid)) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	const uid = await posts.getPostField(pid, 'uid'); | ||||
| 	if (!activitypub.helpers.isUri(uid)) { | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	await activitypub.send(caller.uid, [uid], { | ||||
| 		type: 'Undo', | ||||
| 		object: { | ||||
| 			actor: `${nconf.get('url')}/uid/${caller.uid}`, | ||||
| 			type: 'Like', | ||||
| 			object: pid, | ||||
| 		}, | ||||
| 	}); | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user