From fb5f6fdc103e83652415a3f1379a01f1fb487585 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 19 Oct 2018 06:36:59 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E8=AA=AD=E3=81=AE=E6=8A=95=E7=A8=BF?= =?UTF-8?q?=E3=82=92=E3=81=99=E3=81=B9=E3=81=A6=E6=97=A2=E8=AA=AD=E3=81=AB?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/desktop/views/components/settings.vue | 6 ++++ .../api/endpoints/i/read_all_unread_notes.ts | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/server/api/endpoints/i/read_all_unread_notes.ts diff --git a/src/client/app/desktop/views/components/settings.vue b/src/client/app/desktop/views/components/settings.vue index 1a8cb6b0b..50582b352 100644 --- a/src/client/app/desktop/views/components/settings.vue +++ b/src/client/app/desktop/views/components/settings.vue @@ -169,6 +169,9 @@ %i18n:@auto-watch% %i18n:@auto-watch-desc% +
+ %i18n:@mark-as-read-all-unread-notes% +
@@ -488,6 +491,9 @@ export default Vue.extend({ }); }, methods: { + readAllUnreadNotes() { + (this as any).api('i/read_all_unread_notes'); + }, customizeHome() { this.$router.push('/i/customize-home'); this.$emit('done'); diff --git a/src/server/api/endpoints/i/read_all_unread_notes.ts b/src/server/api/endpoints/i/read_all_unread_notes.ts new file mode 100644 index 000000000..fae98b981 --- /dev/null +++ b/src/server/api/endpoints/i/read_all_unread_notes.ts @@ -0,0 +1,36 @@ +import User, { ILocalUser } from '../../../../models/user'; +import { publishMainStream } from '../../../../stream'; +import NoteUnread from '../../../../models/note-unread'; + +export const meta = { + desc: { + 'ja-JP': '未読の投稿をすべて既読にします。' + }, + + requireCredential: true, + + kind: 'account-write', + + params: { + } +}; + +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { + // Remove documents + await NoteUnread.remove({ + userId: user._id + }); + + User.update({ _id: user._id }, { + $set: { + hasUnreadMentions: false, + hasUnreadSpecifiedNotes: false + } + }); + + // 全て既読になったイベントを発行 + publishMainStream(user._id, 'readAllUnreadMentions'); + publishMainStream(user._id, 'readAllUnreadSpecifiedNotes'); + + res(); +});