Sharkey/src/remote/activitypub/act/like.ts

21 lines
581 B
TypeScript
Raw Normal View History

2018-04-07 20:30:37 +03:00
import Note from '../../../models/note';
2018-04-07 11:05:14 +03:00
import { IRemoteUser } from '../../../models/user';
import { ILike } from '../type';
2018-04-07 20:30:37 +03:00
import create from '../../../services/note/reaction/create';
2018-04-04 13:29:06 +03:00
2018-04-07 11:05:14 +03:00
export default async (actor: IRemoteUser, activity: ILike) => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
2018-04-04 13:29:06 +03:00
// Transform:
// https://misskey.ex/@syuilo/xxxx to
// xxxx
2018-04-07 20:30:37 +03:00
const noteId = id.split('/').pop();
2018-04-04 13:29:06 +03:00
2018-04-07 20:30:37 +03:00
const note = await Note.findOne({ _id: noteId });
if (note === null) {
2018-04-04 13:29:06 +03:00
throw new Error();
}
2018-04-07 20:30:37 +03:00
await create(actor, note, 'pudding');
2018-04-04 13:29:06 +03:00
};