Refactorgin

This commit is contained in:
syuilo 2019-04-25 04:17:03 +09:00
parent ee5720df2c
commit f5091d524b
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69

View File

@ -106,8 +106,6 @@ type Option = {
}; };
export default async (user: User, data: Option, silent = false) => new Promise<Note>(async (res, rej) => { export default async (user: User, data: Option, silent = false) => new Promise<Note>(async (res, rej) => {
const isFirstNote = user.notesCount === 0;
if (data.createdAt == null) data.createdAt = new Date(); if (data.createdAt == null) data.createdAt = new Date();
if (data.visibility == null) data.visibility = 'public'; if (data.visibility == null) data.visibility = 'public';
if (data.viaMobile == null) data.viaMobile = false; if (data.viaMobile == null) data.viaMobile = false;
@ -195,8 +193,6 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
// 統計を更新 // 統計を更新
notesChart.update(note, true); notesChart.update(note, true);
perUserNotesChart.update(user, note, true); perUserNotesChart.update(user, note, true);
// ローカルユーザーのチャートはタイムライン取得時に更新しているのでリモートユーザーの場合だけでよい
if (Users.isRemoteUser(user)) activeUsersChart.update(user);
// Register host // Register host
if (Users.isRemoteUser(user)) { if (Users.isRemoteUser(user)) {
@ -212,6 +208,18 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
// Increment notes count (user) // Increment notes count (user)
incNotesCountOfUser(user); incNotesCountOfUser(user);
if (data.reply) {
saveReply(data.reply, note);
}
if (data.renote) {
incRenoteCount(data.renote);
}
if (!silent) {
// ローカルユーザーのチャートはタイムライン取得時に更新しているのでリモートユーザーの場合だけでよい
if (Users.isRemoteUser(user)) activeUsersChart.update(user);
// 未読通知を作成 // 未読通知を作成
if (data.visibility == 'specified') { if (data.visibility == 'specified') {
if (data.visibleUsers == null) throw new Error('invalid param'); if (data.visibleUsers == null) throw new Error('invalid param');
@ -225,24 +233,14 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
} }
} }
if (data.reply) {
saveReply(data.reply, note);
}
if (data.renote) {
incRenoteCount(data.renote);
}
// Pack the note // Pack the note
const noteObj = await Notes.pack(note); const noteObj = await Notes.pack(note);
if (isFirstNote) { if (user.notesCount === 0) {
(noteObj as any).isFirstNote = true; (noteObj as any).isFirstNote = true;
} }
if (!silent) {
publishNotesStream(noteObj); publishNotesStream(noteObj);
}
const nm = new NotificationManager(user, note); const nm = new NotificationManager(user, note);
const nmRelatedPromises = []; const nmRelatedPromises = [];
@ -297,13 +295,12 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
} }
} }
if (!silent) {
publish(user, note, data.reply, data.renote, noteActivity); publish(user, note, data.reply, data.renote, noteActivity);
}
Promise.all(nmRelatedPromises).then(() => { Promise.all(nmRelatedPromises).then(() => {
nm.deliver(); nm.deliver();
}); });
}
// Register to search database // Register to search database
index(note); index(note);