summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/act/undo/index.ts
blob: 38d5bfe2110cfefb7f2b111d5b2af4f9f5e280da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import act from '../../act';
import unfollow from './unfollow';
import Resolver from '../../resolver';

export default async (resolver: Resolver, actor, activity) => {
	if ('actor' in activity && actor.account.uri !== activity.actor) {
		throw new Error();
	}

	const results = await act(resolver, actor, activity.object);

	await Promise.all(results.map(async promisedResult => {
		const result = await promisedResult;

		if (result === null) {
			return;
		}

		switch (result.object.$ref) {
		case 'following':
			await unfollow(result.object);
		}
	}));

	return null;
};