mizzkey/src/remote/activitypub/kernel/delete/note.ts

31 lines
703 B
TypeScript
Raw Normal View History

2018-04-07 06:44:29 +09:00
import * as debug from 'debug';
2018-04-08 02:30:37 +09:00
import Note from '../../../../models/note';
2018-04-07 06:59:20 +09:00
import { IRemoteUser } from '../../../../models/user';
2018-04-06 19:35:23 +09:00
2018-04-07 06:44:29 +09:00
const log = debug('misskey:activitypub');
2018-04-07 06:59:20 +09:00
export default async function(actor: IRemoteUser, uri: string): Promise<void> {
2018-04-07 06:44:29 +09:00
log(`Deleting the Note: ${uri}`);
2018-04-08 02:30:37 +09:00
const note = await Note.findOne({ uri });
2018-04-07 06:51:35 +09:00
2018-04-08 02:30:37 +09:00
if (note == null) {
throw new Error('note not found');
2018-04-07 06:51:35 +09:00
}
2018-04-08 02:30:37 +09:00
if (!note.userId.equals(actor._id)) {
2018-04-07 06:51:35 +09:00
throw new Error('投稿を削除しようとしているユーザーは投稿の作成者ではありません');
}
2018-04-08 02:30:37 +09:00
Note.update({ _id: note._id }, {
$set: {
deletedAt: new Date(),
text: null,
textHtml: null,
mediaIds: [],
poll: null
}
});
2018-04-06 19:35:23 +09:00
}