summaryrefslogtreecommitdiff
path: root/src/services/note/create.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-04-25 04:17:03 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-04-25 04:17:03 +0900
commitf5091d524b1f6faef1ecdd774882c0df05753ae8 (patch)
tree52704bc0e5102dfc5463a6e8579f3e3f4a9373a7 /src/services/note/create.ts
parentFix #4704 (#4797) (diff)
downloadsharkey-f5091d524b1f6faef1ecdd774882c0df05753ae8.tar.gz
sharkey-f5091d524b1f6faef1ecdd774882c0df05753ae8.tar.bz2
sharkey-f5091d524b1f6faef1ecdd774882c0df05753ae8.zip
Refactorgin
Diffstat (limited to 'src/services/note/create.ts')
-rw-r--r--src/services/note/create.ts131
1 files changed, 64 insertions, 67 deletions
diff --git a/src/services/note/create.ts b/src/services/note/create.ts
index 2195ecc55f..53e77b4ef2 100644
--- a/src/services/note/create.ts
+++ b/src/services/note/create.ts
@@ -106,8 +106,6 @@ type Option = {
};
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.visibility == null) data.visibility = 'public';
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);
perUserNotesChart.update(user, note, true);
- // ローカルユーザーのチャートはタイムライン取得時に更新しているのでリモートユーザーの場合だけでよい
- if (Users.isRemoteUser(user)) activeUsersChart.update(user);
// Register host
if (Users.isRemoteUser(user)) {
@@ -212,19 +208,6 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
// Increment notes count (user)
incNotesCountOfUser(user);
- // 未読通知を作成
- if (data.visibility == 'specified') {
- if (data.visibleUsers == null) throw new Error('invalid param');
-
- for (const u of data.visibleUsers) {
- insertNoteUnread(u, note, true);
- }
- } else {
- for (const u of mentionedUsers) {
- insertNoteUnread(u, note, false);
- }
- }
-
if (data.reply) {
saveReply(data.reply, note);
}
@@ -233,77 +216,91 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
incRenoteCount(data.renote);
}
- // Pack the note
- const noteObj = await Notes.pack(note);
+ if (!silent) {
+ // ローカルユーザーのチャートはタイムライン取得時に更新しているのでリモートユーザーの場合だけでよい
+ if (Users.isRemoteUser(user)) activeUsersChart.update(user);
- if (isFirstNote) {
- (noteObj as any).isFirstNote = true;
- }
+ // 未読通知を作成
+ if (data.visibility == 'specified') {
+ if (data.visibleUsers == null) throw new Error('invalid param');
- if (!silent) {
- publishNotesStream(noteObj);
- }
+ for (const u of data.visibleUsers) {
+ insertNoteUnread(u, note, true);
+ }
+ } else {
+ for (const u of mentionedUsers) {
+ insertNoteUnread(u, note, false);
+ }
+ }
- const nm = new NotificationManager(user, note);
- const nmRelatedPromises = [];
+ // Pack the note
+ const noteObj = await Notes.pack(note);
- createMentionedEvents(mentionedUsers, note, nm);
+ if (user.notesCount === 0) {
+ (noteObj as any).isFirstNote = true;
+ }
- const noteActivity = await renderNoteOrRenoteActivity(data, note);
+ publishNotesStream(noteObj);
- if (Users.isLocalUser(user)) {
- deliverNoteToMentionedRemoteUsers(mentionedUsers, user, noteActivity);
- }
+ const nm = new NotificationManager(user, note);
+ const nmRelatedPromises = [];
- const profile = await UserProfiles.findOne(user.id).then(ensure);
+ createMentionedEvents(mentionedUsers, note, nm);
- // If has in reply to note
- if (data.reply) {
- // Fetch watchers
- nmRelatedPromises.push(notifyToWatchersOfReplyee(data.reply, user, nm));
+ const noteActivity = await renderNoteOrRenoteActivity(data, note);
- // この投稿をWatchする
- if (Users.isLocalUser(user) && profile.autoWatch) {
- watch(user.id, data.reply);
+ if (Users.isLocalUser(user)) {
+ deliverNoteToMentionedRemoteUsers(mentionedUsers, user, noteActivity);
}
- // 通知
- if (data.reply.userHost === null) {
- nm.push(data.reply.userId, 'reply');
- publishMainStream(data.reply.userId, 'reply', noteObj);
- }
- }
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
- // If it is renote
- if (data.renote) {
- const type = data.text ? 'quote' : 'renote';
+ // If has in reply to note
+ if (data.reply) {
+ // Fetch watchers
+ nmRelatedPromises.push(notifyToWatchersOfReplyee(data.reply, user, nm));
- // Notify
- if (data.renote.userHost === null) {
- nm.push(data.renote.userId, type);
+ // この投稿をWatchする
+ if (Users.isLocalUser(user) && profile.autoWatch) {
+ watch(user.id, data.reply);
+ }
+
+ // 通知
+ if (data.reply.userHost === null) {
+ nm.push(data.reply.userId, 'reply');
+ publishMainStream(data.reply.userId, 'reply', noteObj);
+ }
}
- // Fetch watchers
- nmRelatedPromises.push(notifyToWatchersOfRenotee(data.renote, user, nm, type));
+ // If it is renote
+ if (data.renote) {
+ const type = data.text ? 'quote' : 'renote';
- // この投稿をWatchする
- if (Users.isLocalUser(user) && profile.autoWatch) {
- watch(user.id, data.renote);
- }
+ // Notify
+ if (data.renote.userHost === null) {
+ nm.push(data.renote.userId, type);
+ }
- // Publish event
- if ((user.id !== data.renote.userId) && data.renote.userHost === null) {
- publishMainStream(data.renote.userId, 'renote', noteObj);
+ // Fetch watchers
+ nmRelatedPromises.push(notifyToWatchersOfRenotee(data.renote, user, nm, type));
+
+ // この投稿をWatchする
+ if (Users.isLocalUser(user) && profile.autoWatch) {
+ watch(user.id, data.renote);
+ }
+
+ // Publish event
+ if ((user.id !== data.renote.userId) && data.renote.userHost === null) {
+ publishMainStream(data.renote.userId, 'renote', noteObj);
+ }
}
- }
- if (!silent) {
publish(user, note, data.reply, data.renote, noteActivity);
- }
- Promise.all(nmRelatedPromises).then(() => {
- nm.deliver();
- });
+ Promise.all(nmRelatedPromises).then(() => {
+ nm.deliver();
+ });
+ }
// Register to search database
index(note);