mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	refactor: minor restructure to move logic out of main controller file to src/api
This commit is contained in:
		
							
								
								
									
										53
									
								
								src/api/activitypub.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/api/activitypub.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| /** | ||||
|  * DEVELOPMENT NOTE | ||||
|  * | ||||
|  * THIS FILE IS UNDER ACTIVE DEVELOPMENT AND IS EXPLICITLY EXCLUDED FROM IMMUTABILITY GUARANTEES | ||||
|  * | ||||
|  * If you use api methods in this file, be prepared that they may be removed or modified with no warning. | ||||
|  */ | ||||
|  | ||||
| const db = require('../database'); | ||||
| const activitypub = require('../activitypub'); | ||||
|  | ||||
| const activitypubApi = module.exports; | ||||
|  | ||||
| activitypubApi.follow = async (caller, { actorId } = {}) => { | ||||
| 	if (!actorId) { | ||||
| 		throw new Error('[[error:invalid-uid]]'); // should be activitypub-specific | ||||
| 	} | ||||
|  | ||||
| 	await activitypub.send(caller.uid, actorId, { | ||||
| 		type: 'Follow', | ||||
| 		object: { | ||||
| 			type: 'Person', | ||||
| 			name: actorId, | ||||
| 		}, | ||||
| 	}); | ||||
|  | ||||
| 	const now = Date.now(); | ||||
| 	await Promise.all([ | ||||
| 		db.sortedSetAdd(`followingRemote:${caller.uid}`, now, actorId), | ||||
| 		db.incrObjectField(`user:${caller.uid}`, 'followingRemoteCount'), | ||||
| 	]); | ||||
| }; | ||||
|  | ||||
| activitypubApi.unfollow = async (caller, { actorId }) => { | ||||
| 	if (!actorId) { | ||||
| 		throw new Error('[[error:invalid-uid]]'); // should be activitypub-specific | ||||
| 	} | ||||
|  | ||||
| 	await activitypub.send(caller.uid, actorId, { | ||||
| 		type: 'Unfollow', | ||||
| 		object: { | ||||
| 			type: 'Person', | ||||
| 			name: actorId, | ||||
| 		}, | ||||
| 	}); | ||||
|  | ||||
| 	await Promise.all([ | ||||
| 		db.sortedSetRemove(`followingRemote:${caller.uid}`, actorId), | ||||
| 		db.decrObjectField(`user:${caller.uid}`, 'followingRemoteCount'), | ||||
| 	]); | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user