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

moving initCommentEvent to activity service

kaori 4 лет назад
Родитель
Сommit
1ce4ab8222

+ 0 - 1
packages/app/src/components/PageEditor/InAppNotificationDropdown.tsx

@@ -9,7 +9,6 @@ import SocketIoContainer from '~/client/services/SocketIoContainer';
 
 
 const InAppNotificationDropdown: FC = (props) => {
-  console.log('propsHoge', props);
 
   const [count, setCount] = useState(0);
   const [isLoaded, setIsLoaded] = useState(false);

+ 11 - 1
packages/app/src/server/crowi/index.js

@@ -64,6 +64,7 @@ function Crowi() {
   this.interceptorManager = new InterceptorManager();
   this.slackIntegrationService = null;
   this.inAppNotificationService = null;
+  this.ActivityService = null;
   this.xss = new Xss();
 
   this.tokens = null;
@@ -122,6 +123,7 @@ Crowi.prototype.init = async function() {
     this.setupImport(),
     this.setupPageService(),
     this.setupInAppNotificationService(),
+    this.setupActivityService(),
     this.setupSyncPageStatusService(),
   ]);
 
@@ -160,7 +162,8 @@ Crowi.prototype.initForTest = async function() {
     // this.setupExport(),
     // this.setupImport(),
     this.setupPageService(),
-    this.setupInAppNotificationService(),
+    // this.setupInAppNotificationService(),
+    // this.setupActivityService(),
   ]);
 
   // globalNotification depends on slack and mailer
@@ -648,6 +651,13 @@ Crowi.prototype.setupInAppNotificationService = async function() {
   }
 };
 
+Crowi.prototype.setupActivityService = async function() {
+  const ActivityService = require('../service/activity');
+  if (this.activityService == null) {
+    this.activityService = new ActivityService(this);
+  }
+};
+
 Crowi.prototype.setupSyncPageStatusService = async function() {
   const SyncPageStatusService = require('../service/system-events/sync-page-status');
   if (this.syncPageStatusService == null) {

+ 42 - 1
packages/app/src/server/service/activity.ts

@@ -1,6 +1,6 @@
 import loggerFactory from '../../utils/logger';
 
-import { ActivityDocument } from '../models/activity';
+import { Activity } from '~/server/models/activity';
 
 const InAppNotificationService = require('./in-app-notification');
 
@@ -11,8 +11,49 @@ class ActivityService {
 
   crowi: any;
 
+  commentEvent!: any;
+
   constructor(crowi) {
     this.crowi = crowi;
+    this.commentEvent = crowi.event('comment');
+
+    // init
+    this.initCommentEvent();
+  }
+
+  initCommentEvent(): void {
+    // create
+    this.commentEvent.on('create', async(savedComment) => {
+      this.commentEvent.onCreate();
+
+      try {
+        const activityLog = await Activity.createByPageComment(savedComment);
+        logger.info('Activity created', activityLog);
+      }
+      catch (err) {
+        throw err;
+      }
+
+    });
+
+    // update
+    this.commentEvent.on('update', (user) => {
+      this.commentEvent.onUpdate();
+    });
+
+    // remove
+    this.commentEvent.on('remove', async(comment) => {
+      this.commentEvent.onRemove();
+
+      try {
+        // TODO: Able to remove child activities of comment by GW-7510
+        await Activity.removeByPageCommentDelete(comment);
+      }
+      catch (err) {
+        logger.error(err);
+      }
+    });
+
   }
 
 }

+ 0 - 29
packages/app/src/server/service/in-app-notification.ts

@@ -27,40 +27,11 @@ class InAppNotificationService {
 
 
   initCommentEvent(): void {
-    // create
-    this.commentEvent.on('create', async(savedComment) => {
-      this.commentEvent.onCreate();
-
-      try {
-        const activityLog = await Activity.createByPageComment(savedComment);
-        logger.info('Activity created', activityLog);
-      }
-      catch (err) {
-        throw err;
-      }
-    });
-
     // update
     this.commentEvent.on('update', (user) => {
-      this.commentEvent.onUpdate();
-
       if (this.socketIoService.isInitialized) {
         this.socketIoService.getDefaultSocket().emit('comment updated', { user });
       }
-
-    });
-
-    // remove
-    this.commentEvent.on('remove', async(comment) => {
-      this.commentEvent.onRemove();
-
-      try {
-        // TODO: Able to remove child activities of comment by GW-7510
-        await Activity.removeByPageCommentDelete(comment);
-      }
-      catch (err) {
-        logger.error(err);
-      }
     });
 
   }