summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/kernel/like.ts
blob: 17ec73f12b35ea70ef59670f467ba0ef6f2c69d4 (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
27
28
29
30
31
import * as mongo from 'mongodb';
import Note from '../../../models/note';
import { IRemoteUser } from '../../../models/user';
import { ILike } from '../type';
import create from '../../../services/note/reaction/create';
import { validateReaction } from '../../../models/note-reaction';

export default async (actor: IRemoteUser, activity: ILike) => {
	const id = typeof activity.object == 'string' ? activity.object : activity.object.id;

	// Transform:
	// https://misskey.ex/notes/xxxx to
	// xxxx
	const noteId = new mongo.ObjectID(id.split('/').pop());

	const note = await Note.findOne({ _id: noteId });
	if (note === null) {
		throw new Error();
	}

	let reaction = 'pudding';

	// 他のMisskeyインスタンスからのリアクション
	if (activity._misskey_reaction) {
		if (validateReaction.ok(activity._misskey_reaction)) {
			reaction = activity._misskey_reaction;
		}
	}

	await create(actor, note, reaction);
};