Просмотр исходного кода

Modified the code based off the FB

Shunm634-source 3 лет назад
Родитель
Сommit
321a0ee8a8

+ 1 - 1
packages/app/src/server/models/subscription.ts

@@ -82,7 +82,7 @@ subscriptionSchema.statics.getUnsubscription = async function(target: Ref<IPage>
 };
 
 subscriptionSchema.statics.getSubscriptions = async function(targets: Ref<IPage>[]) {
-  return this.find({ $in: targets, status: SubscriptionStatusType.SUBSCRIBE }).distinct('user');
+  return this.find({ target: { $in: targets }, status: SubscriptionStatusType.SUBSCRIBE }).distinct('user');
 };
 
 export default getOrCreateModel<SubscriptionDocument, SubscriptionModel>('Subscription', subscriptionSchema);

+ 0 - 1
packages/app/src/server/routes/page.js

@@ -1374,7 +1374,6 @@ module.exports = function(crowi, app) {
     let descendantPages;
     try {
       page = await Page.findByIdAndViewer(pageId, req.user);
-      const bPages = await Page.findListWithDescendants(page.path, req.user);
       if (page == null) {
         throw new Error(`Page '${pageId}' is not found or forbidden`, 'notfound_or_forbidden');
       }

+ 7 - 5
packages/app/src/server/service/in-app-notification.ts

@@ -203,24 +203,26 @@ export default class InAppNotificationService {
 
   createInAppNotification = async function(activity: ActivityDocument, target: IPage, descendantPages?: Ref<IPage>[]): Promise<void> {
     const shouldNotification = activity != null && target != null && (AllEssentialActions as ReadonlyArray<string>).includes(activity.action);
+    const snapshot = stringifySnapshot(target as IPage);
     if (shouldNotification) {
       let mentionedUsers: IUser[] = [];
       if (activity.action === SupportedAction.ACTION_COMMENT_CREATE) {
         mentionedUsers = await this.crowi.commentService.getMentionedUsers(activity.event);
       }
-      let notificationTargetUsers = await activity?.getNotificationTargetUsers();
+      const notificationTargetUsers = await activity?.getNotificationTargetUsers();
+      let notificationDescendantsUsers = [];
       if (descendantPages != null && descendantPages.length > 0) {
         const User = this.crowi.model('User');
         const targetDescendantsUsers = await Subscription.getSubscriptions(descendantPages);
         const descendantsUsers = targetDescendantsUsers.filter(item => (item.toString() !== activity.user._id.toString()));
-        notificationTargetUsers = notificationTargetUsers.concat(await User.find({
+        notificationDescendantsUsers = await User.find({
           _id: { $in: descendantsUsers },
           status: User.STATUS_ACTIVE,
-        }).distinct('_id'));
+        }).distinct('_id');
       }
-      const snapshot = stringifySnapshot(target as IPage);
-      await this.upsertByActivity([...notificationTargetUsers, ...mentionedUsers], activity, snapshot);
+      await this.upsertByActivity([...notificationTargetUsers, ...mentionedUsers, ...notificationDescendantsUsers], activity, snapshot);
       await this.emitSocketIo(notificationTargetUsers);
+      if (notificationDescendantsUsers != null && notificationDescendantsUsers.length > 0) await this.emitSocketIo(notificationDescendantsUsers);
     }
     else {
       throw Error('No activity to notify');

+ 0 - 1
packages/app/src/server/service/page.ts

@@ -25,7 +25,6 @@ import { createBatchStream } from '~/server/util/batch-stream';
 import loggerFactory from '~/utils/logger';
 import { prepareDeleteConfigValuesForCalc } from '~/utils/page-delete-config';
 
-import PageEvent from '../events/page';
 import { ObjectIdLike } from '../interfaces/mongoose-utils';
 import { PathAlreadyExistsError } from '../models/errors';
 import PageOperation, { PageActionStage, PageActionType, PageOperationDocument } from '../models/page-operation';