rudeshark.net/src/remote/activitypub/kernel/like.ts

30 lines
920 B
TypeScript
Raw Normal View History

2018-04-18 07:09:55 +02:00
import * as mongo from 'mongodb';
2018-04-07 19:30:37 +02:00
import Note from '../../../models/note';
2018-04-07 10:05:14 +02:00
import { IRemoteUser } from '../../../models/user';
import { ILike } from '../type';
2018-04-07 19:30:37 +02:00
import create from '../../../services/note/reaction/create';
import { validateReaction } from '../../../models/note-reaction';
2018-04-04 12:29:06 +02:00
2018-04-07 10:05:14 +02:00
export default async (actor: IRemoteUser, activity: ILike) => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
2018-04-04 12:29:06 +02:00
// Transform:
2018-04-07 23:55:26 +02:00
// https://misskey.ex/notes/xxxx to
2018-04-04 12:29:06 +02:00
// xxxx
2018-04-18 07:09:55 +02:00
const noteId = new mongo.ObjectID(id.split('/').pop());
2018-04-04 12:29:06 +02:00
2018-04-07 19:30:37 +02:00
const note = await Note.findOne({ _id: noteId });
if (note === null) {
2018-04-04 12:29:06 +02:00
throw new Error();
}
let reaction = 'pudding';
// 他のMisskeyインスタンスからのリアクション
2018-12-02 14:32:09 +01:00
if (activity._misskey_reaction && validateReaction.ok(activity._misskey_reaction)) {
reaction = activity._misskey_reaction;
}
await create(actor, note, reaction);
2018-04-04 12:29:06 +02:00
};