2018-05-28 07:39:46 +02:00
|
|
|
import Note, { INote } from '../../models/note';
|
|
|
|
import { IUser, isLocalUser } from '../../models/user';
|
2018-07-07 12:19:00 +02:00
|
|
|
import { publishNoteStream } from '../../stream';
|
2018-05-28 07:39:46 +02:00
|
|
|
import renderDelete from '../../remote/activitypub/renderer/delete';
|
|
|
|
import pack from '../../remote/activitypub/renderer';
|
|
|
|
import { deliver } from '../../queue';
|
|
|
|
import Following from '../../models/following';
|
2018-09-01 19:57:34 +02:00
|
|
|
import renderTombstone from '../../remote/activitypub/renderer/tombstone';
|
2018-08-18 16:56:44 +02:00
|
|
|
import { updateNoteStats } from '../update-chart';
|
2018-09-01 19:57:34 +02:00
|
|
|
import config from '../../config';
|
2018-05-28 07:39:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 投稿を削除します。
|
|
|
|
* @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 22:24:44 +02:00
|
|
|
tags: [],
|
2018-09-05 12:32:46 +02:00
|
|
|
fileIds: [],
|
2018-07-26 20:46:12 +02:00
|
|
|
poll: null,
|
2018-09-10 07:48:19 +02:00
|
|
|
geo: null,
|
|
|
|
cw: null
|
2018-05-28 07:39:46 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
publishNoteStream(note._id, 'deleted');
|
|
|
|
|
|
|
|
//#region ローカルの投稿なら削除アクティビティを配送
|
|
|
|
if (isLocalUser(user)) {
|
2018-09-01 19:57:34 +02:00
|
|
|
const content = pack(renderDelete(renderTombstone(`${config.url}/notes/${note._id}`), user));
|
2018-05-28 07:39:46 +02:00
|
|
|
|
|
|
|
const followings = await Following.find({
|
|
|
|
followeeId: user._id,
|
|
|
|
'_follower.host': { $ne: null }
|
|
|
|
});
|
|
|
|
|
|
|
|
followings.forEach(following => {
|
|
|
|
deliver(user, content, following._follower.inbox);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
//#endregion
|
2018-08-18 16:56:44 +02:00
|
|
|
|
|
|
|
// 統計を更新
|
|
|
|
updateNoteStats(note, false);
|
2018-05-28 07:39:46 +02:00
|
|
|
}
|