From 5d09b7e38b42f19530d51feeeae0e57ad4320351 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Fri, 20 Jul 2018 14:16:02 +0900 Subject: mark as read all -> mark all as read Close #855 --- .../app/mobile/views/pages/notifications.vue | 2 +- src/server/api/common/read-messaging-message.ts | 18 ++++----- src/server/api/common/read-notification.ts | 18 ++++----- src/server/api/endpoints/i/notifications.ts | 2 +- src/server/api/endpoints/messaging/messages.ts | 10 ++--- .../endpoints/notifications/mark_all_as_read.ts | 44 ++++++++++++++++++++++ .../endpoints/notifications/mark_as_read_all.ts | 44 ---------------------- 7 files changed, 69 insertions(+), 69 deletions(-) create mode 100644 src/server/api/endpoints/notifications/mark_all_as_read.ts delete mode 100644 src/server/api/endpoints/notifications/mark_as_read_all.ts (limited to 'src') diff --git a/src/client/app/mobile/views/pages/notifications.vue b/src/client/app/mobile/views/pages/notifications.vue index 64cfa60da0..fcd930997b 100644 --- a/src/client/app/mobile/views/pages/notifications.vue +++ b/src/client/app/mobile/views/pages/notifications.vue @@ -24,7 +24,7 @@ export default Vue.extend({ const ok = window.confirm('%i18n:@read-all%'); if (!ok) return; - (this as any).api('notifications/mark_as_read_all'); + (this as any).api('notifications/mark_all_as_read'); }, onFetched() { Progress.done(); diff --git a/src/server/api/common/read-messaging-message.ts b/src/server/api/common/read-messaging-message.ts index bd5a04f1b0..a34fd8a703 100644 --- a/src/server/api/common/read-messaging-message.ts +++ b/src/server/api/common/read-messaging-message.ts @@ -7,7 +7,7 @@ import { publishMessagingIndexStream } from '../../../stream'; import User from '../../../models/user'; /** - * Mark as read message(s) + * Mark messages as read */ export default ( user: string | mongo.ObjectID, @@ -42,12 +42,12 @@ export default ( recipientId: userId, isRead: false }, { - $set: { - isRead: true - } - }, { - multi: true - }); + $set: { + isRead: true + } + }, { + multi: true + }); // Publish event publishMessagingStream(otherpartyId, userId, 'read', ids.map(id => id.toString())); @@ -59,8 +59,8 @@ export default ( recipientId: userId, isRead: false }, { - limit: 1 - }); + limit: 1 + }); if (count == 0) { // Update flag diff --git a/src/server/api/common/read-notification.ts b/src/server/api/common/read-notification.ts index fcebad6baa..3a1f4cfbde 100644 --- a/src/server/api/common/read-notification.ts +++ b/src/server/api/common/read-notification.ts @@ -5,7 +5,7 @@ import Mute from '../../../models/mute'; import User from '../../../models/user'; /** - * Mark as read notification(s) + * Mark notifications as read */ export default ( user: string | mongo.ObjectID, @@ -38,12 +38,12 @@ export default ( _id: { $in: ids }, isRead: false }, { - $set: { - isRead: true - } - }, { - multi: true - }); + $set: { + isRead: true + } + }, { + multi: true + }); // Calc count of my unread notifications const count = await Notification @@ -54,8 +54,8 @@ export default ( }, isRead: false }, { - limit: 1 - }); + limit: 1 + }); if (count == 0) { // Update flag diff --git a/src/server/api/endpoints/i/notifications.ts b/src/server/api/endpoints/i/notifications.ts index 6a1ba07a3a..b6865fba52 100644 --- a/src/server/api/endpoints/i/notifications.ts +++ b/src/server/api/endpoints/i/notifications.ts @@ -96,7 +96,7 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) = // Serialize res(await Promise.all(notifications.map(notification => pack(notification)))); - // Mark as read all + // Mark all as read if (notifications.length > 0 && markAsRead) { read(user._id, notifications); } diff --git a/src/server/api/endpoints/messaging/messages.ts b/src/server/api/endpoints/messaging/messages.ts index 84c28dc0c1..ae26419bc6 100644 --- a/src/server/api/endpoints/messaging/messages.ts +++ b/src/server/api/endpoints/messaging/messages.ts @@ -24,10 +24,10 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) = const recipient = await User.findOne({ _id: recipientId }, { - fields: { - _id: true - } - }); + fields: { + _id: true + } + }); if (recipient === null) { return rej('user not found'); @@ -96,7 +96,7 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) = return; } - // Mark as read all + // Mark all as read if (markAsRead) { read(user._id, recipient._id, messages); } diff --git a/src/server/api/endpoints/notifications/mark_all_as_read.ts b/src/server/api/endpoints/notifications/mark_all_as_read.ts new file mode 100644 index 0000000000..91319d0553 --- /dev/null +++ b/src/server/api/endpoints/notifications/mark_all_as_read.ts @@ -0,0 +1,44 @@ +import Notification from '../../../../models/notification'; +import event from '../../../../stream'; +import User, { ILocalUser } from '../../../../models/user'; + +export const meta = { + desc: { + ja: '全ての通知を既読にします。', + en: 'Mark all notifications as read.' + }, + + requireCredential: true, + + kind: 'notification-write' +}; + +/** + * Mark all notifications as read + */ +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { + // Update documents + await Notification.update({ + notifieeId: user._id, + isRead: false + }, { + $set: { + isRead: true + } + }, { + multi: true + }); + + // Response + res(); + + // Update flag + User.update({ _id: user._id }, { + $set: { + hasUnreadNotification: false + } + }); + + // 全ての通知を読みましたよというイベントを発行 + event(user._id, 'read_all_notifications'); +}); diff --git a/src/server/api/endpoints/notifications/mark_as_read_all.ts b/src/server/api/endpoints/notifications/mark_as_read_all.ts deleted file mode 100644 index 7cf4cd16e9..0000000000 --- a/src/server/api/endpoints/notifications/mark_as_read_all.ts +++ /dev/null @@ -1,44 +0,0 @@ -import Notification from '../../../../models/notification'; -import event from '../../../../stream'; -import User, { ILocalUser } from '../../../../models/user'; - -export const meta = { - desc: { - ja: '全ての通知を既読にします。', - en: 'Mark as read all notifications.' - }, - - requireCredential: true, - - kind: 'notification-write' -}; - -/** - * Mark as read all notifications - */ -export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { - // Update documents - await Notification.update({ - notifieeId: user._id, - isRead: false - }, { - $set: { - isRead: true - } - }, { - multi: true - }); - - // Response - res(); - - // Update flag - User.update({ _id: user._id }, { - $set: { - hasUnreadNotification: false - } - }); - - // 全ての通知を読みましたよというイベントを発行 - event(user._id, 'read_all_notifications'); -}); -- cgit v1.2.3-freya