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