2019-02-05 05:14:23 +00:00
|
|
|
import { publishNoteStream } from '../stream';
|
2018-05-28 05:39:46 +00:00
|
|
|
import renderDelete from '../../remote/activitypub/renderer/delete';
|
2019-01-30 17:29:36 +00:00
|
|
|
import { renderActivity } from '../../remote/activitypub/renderer';
|
2018-05-28 05:39:46 +00:00
|
|
|
import { deliver } from '../../queue';
|
2018-09-01 17:57:34 +00:00
|
|
|
import renderTombstone from '../../remote/activitypub/renderer/tombstone';
|
|
|
|
import config from '../../config';
|
2019-02-08 07:58:57 +00:00
|
|
|
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc';
|
2019-04-07 12:50:36 +00:00
|
|
|
import { User } from '../../models/entities/user';
|
|
|
|
import { Note } from '../../models/entities/note';
|
|
|
|
import { Notes, Users, Followings, Instances } from '../../models';
|
|
|
|
import { Not } from 'typeorm';
|
|
|
|
import { notesChart, perUserNotesChart, instanceChart } from '../chart';
|
2018-05-28 05:39:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 投稿を削除します。
|
|
|
|
* @param user 投稿者
|
|
|
|
* @param note 投稿
|
|
|
|
*/
|
2019-04-07 12:50:36 +00:00
|
|
|
export default async function(user: User, note: Note, quiet = false) {
|
2018-10-07 11:08:42 +00:00
|
|
|
const deletedAt = new Date();
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
await Notes.delete({
|
|
|
|
id: note.id,
|
|
|
|
userId: user.id
|
2018-05-28 05:39:46 +00:00
|
|
|
});
|
|
|
|
|
2019-01-26 08:47:56 +00:00
|
|
|
if (note.renoteId) {
|
2019-04-07 12:50:36 +00:00
|
|
|
Notes.decrement({ id: note.renoteId }, 'renoteCount', 1);
|
|
|
|
Notes.decrement({ id: note.renoteId }, 'score', 1);
|
2018-10-22 22:04:00 +00:00
|
|
|
}
|
|
|
|
|
2019-02-20 16:30:21 +00:00
|
|
|
if (!quiet) {
|
2019-04-07 12:50:36 +00:00
|
|
|
publishNoteStream(note.id, 'deleted', {
|
2019-02-20 16:30:21 +00:00
|
|
|
deletedAt: deletedAt
|
2018-05-28 05:39:46 +00:00
|
|
|
});
|
|
|
|
|
2019-02-20 16:30:21 +00:00
|
|
|
//#region ローカルの投稿なら削除アクティビティを配送
|
2019-04-07 12:50:36 +00:00
|
|
|
if (Users.isLocalUser(user)) {
|
|
|
|
const content = renderActivity(renderDelete(renderTombstone(`${config.url}/notes/${note.id}`), user));
|
2019-02-20 16:30:21 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
const followings = await Followings.find({
|
|
|
|
followeeId: user.id,
|
|
|
|
followerHost: Not(null)
|
2019-02-20 16:30:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
for (const following of followings) {
|
2019-04-07 12:50:36 +00:00
|
|
|
deliver(user, content, following.followerInbox);
|
2019-02-20 16:30:21 +00:00
|
|
|
}
|
2018-12-11 11:36:55 +00:00
|
|
|
}
|
2019-02-20 16:30:21 +00:00
|
|
|
//#endregion
|
2018-08-18 14:56:44 +00:00
|
|
|
|
2019-02-20 16:30:21 +00:00
|
|
|
// 統計を更新
|
|
|
|
notesChart.update(note, false);
|
|
|
|
perUserNotesChart.update(user, note, false);
|
2019-02-08 07:58:57 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
if (Users.isRemoteUser(user)) {
|
2019-02-20 16:30:21 +00:00
|
|
|
registerOrFetchInstanceDoc(user.host).then(i => {
|
2019-04-07 12:50:36 +00:00
|
|
|
Instances.decrement({ id: i.id }, 'notesCount', 1);
|
2019-02-20 16:30:21 +00:00
|
|
|
instanceChart.updateNote(i.host, false);
|
|
|
|
});
|
|
|
|
}
|
2019-02-08 07:58:57 +00:00
|
|
|
}
|
2018-05-28 05:39:46 +00:00
|
|
|
}
|