Shun Miyazawa hace 3 años
padre
commit
41c6088d1b
Se han modificado 1 ficheros con 7 adiciones y 4 borrados
  1. 7 4
      packages/app/src/server/service/activity.ts

+ 7 - 4
packages/app/src/server/service/activity.ts

@@ -1,4 +1,5 @@
 import { getModelSafely } from '@growi/core';
+import { NavItem } from 'reactstrap';
 
 import { IActivity, AllSupportedActionToNotifiedType } from '~/interfaces/activity';
 import { IPage } from '~/interfaces/page';
@@ -35,11 +36,13 @@ class ActivityService {
   updateByParameters = async function(activityId: string, parameters: ParameterType, target?: IPage): Promise<void> {
     const activity = await Activity.findOneAndUpdate({ _id: activityId }, parameters, { new: true });
 
-    // eslint-disable-next-line
-    const shouldNotification = activity != null && target !== null && target !== undefined && (AllSupportedActionToNotifiedType as ReadonlyArray<string>).includes(activity.action);
+    const shouldNotification = activity != null && target != null && (AllSupportedActionToNotifiedType as ReadonlyArray<string>).includes(activity.action);
     if (shouldNotification) {
-      const notificationTargetUsers = await activity.getNotificationTargetUsers();
-      const snapshotForInAppNotification = stringifySnapshot(target);
+      const notificationTargetUsers = await activity?.getNotificationTargetUsers();
+      let snapshotForInAppNotification: string;
+      if (target != null) {
+        snapshotForInAppNotification = stringifySnapshot(target);
+      }
       await this.inAppNotificationService.upsertByActivity(notificationTargetUsers, activity, snapshotForInAppNotification);
       await this.inAppNotificationService.emitSocketIo(notificationTargetUsers);
     }