egirlskey/src/services/note/delete.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-05-28 05:39:46 +00:00
import Note, { INote } from '../../models/note';
import { IUser, isLocalUser } from '../../models/user';
2018-07-07 10:19:00 +00:00
import { publishNoteStream } from '../../stream';
2018-05-28 05:39:46 +00:00
import renderDelete from '../../remote/activitypub/renderer/delete';
import pack from '../../remote/activitypub/renderer';
import { deliver } from '../../queue';
import Following from '../../models/following';
import renderNote from '../../remote/activitypub/renderer/note';
/**
* 稿
* @param user 稿
* @param note 稿
*/
export default async function(user: IUser, note: INote) {
await Note.update({
_id: note._id,
userId: user._id
}, {
$set: {
deletedAt: new Date(),
text: null,
2018-06-12 20:24:44 +00:00
tags: [],
2018-05-28 05:39:46 +00:00
mediaIds: [],
2018-07-26 18:46:12 +00:00
poll: null,
geo: null
2018-05-28 05:39:46 +00:00
}
});
publishNoteStream(note._id, 'deleted');
//#region ローカルの投稿なら削除アクティビティを配送
if (isLocalUser(user)) {
const content = pack(renderDelete(await renderNote(note)));
const followings = await Following.find({
followeeId: user._id,
'_follower.host': { $ne: null }
});
followings.forEach(following => {
deliver(user, content, following._follower.inbox);
});
}
//#endregion
}