kaori 4 лет назад
Родитель
Сommit
5c9fea37b8

+ 2 - 2
packages/app/src/server/crowi/index.js

@@ -64,8 +64,8 @@ function Crowi() {
   this.interceptorManager = new InterceptorManager();
   this.interceptorManager = new InterceptorManager();
   this.slackIntegrationService = null;
   this.slackIntegrationService = null;
   this.inAppNotificationService = null;
   this.inAppNotificationService = null;
-  this.ActivityService = null;
-  this.CommentService = null;
+  this.activityService = null;
+  this.commentService = null;
   this.xss = new Xss();
   this.xss = new Xss();
 
 
   this.tokens = null;
   this.tokens = null;

+ 19 - 0
packages/app/src/server/service/activity.ts

@@ -63,6 +63,25 @@ class ActivityService {
     return;
     return;
   };
   };
 
 
+    /**
+     * @param {Page} page
+     * @param {User} user
+     * @return {Promise}
+     */
+    createByPageUpdate = async function(page, user) {
+      const parameters = {
+        user: user._id,
+        targetModel: ActivityDefine.MODEL_PAGE,
+        target: page,
+        action: ActivityDefine.ACTION_MODIFY,
+      };
+      console.log('createByPageUpdate', parameters);
+      const Activity = getModelSafely('Activity') || require('../models/activity')(this.crowi);
+      await Activity.createByParameters(parameters);
+      return;
+    };
+
+
 }
 }
 
 
 module.exports = ActivityService;
 module.exports = ActivityService;

+ 2 - 1
packages/app/src/server/service/comment.ts

@@ -51,7 +51,8 @@ class CommentService {
     this.commentEvent.on('remove', async(comment) => {
     this.commentEvent.on('remove', async(comment) => {
       this.commentEvent.onRemove();
       this.commentEvent.onRemove();
 
 
-      const { activityService } = this.crowi;
+      const { activityService, inAppNotificationService } = this.crowi;
+      console.log('inAppNotificationServiceFUga', inAppNotificationService);
 
 
       try {
       try {
         // TODO: Able to remove child activities of comment by GW-7510
         // TODO: Able to remove child activities of comment by GW-7510

+ 34 - 3
packages/app/src/server/service/page.js

@@ -5,8 +5,8 @@ const mongoose = require('mongoose');
 const escapeStringRegexp = require('escape-string-regexp');
 const escapeStringRegexp = require('escape-string-regexp');
 const streamToPromise = require('stream-to-promise');
 const streamToPromise = require('stream-to-promise');
 
 
-const logger = loggerFactory('growi:models:page');
-const debug = require('debug')('growi:models:page');
+const logger = loggerFactory('growi:service:page');
+const debug = require('debug')('growi:service:page');
 const { Writable } = require('stream');
 const { Writable } = require('stream');
 const { createBatchStream } = require('~/server/util/batch-stream');
 const { createBatchStream } = require('~/server/util/batch-stream');
 
 
@@ -19,14 +19,45 @@ class PageService {
 
 
   constructor(crowi) {
   constructor(crowi) {
     this.crowi = crowi;
     this.crowi = crowi;
+    // this.activityService = this.crowi.activityService;
     this.pageEvent = crowi.event('page');
     this.pageEvent = crowi.event('page');
 
 
+    // this.pageEvent.on('create', this.pageEvent.onCreate);
+    // this.pageEvent.on('update', this.pageEvent.onUpdate);
+    // this.pageEvent.on('createMany', this.pageEvent.onCreateMany);
+
     // init
     // init
+    this.initPageEvent();
+  }
+
+  async initPageEvent() {
+    console.log('this.crowi.hoge', this.crowi);
+    const { activityService } = this.crowi;
+
+    // create
     this.pageEvent.on('create', this.pageEvent.onCreate);
     this.pageEvent.on('create', this.pageEvent.onCreate);
-    this.pageEvent.on('update', this.pageEvent.onUpdate);
+
+    // update
+    this.pageEvent.on('update', async(page, user) => {
+      this.pageEvent.onUpdate();
+
+      try {
+        console.log('activityServiceHoge', activityService);
+        const activityLog = await activityService.createByPageUpdate(page, user);
+        logger.info('Activity created', activityLog);
+      }
+      catch (err) {
+        logger.error(err);
+
+      }
+    });
+
+
+    // createMany
     this.pageEvent.on('createMany', this.pageEvent.onCreateMany);
     this.pageEvent.on('createMany', this.pageEvent.onCreateMany);
   }
   }
 
 
+
   /**
   /**
    * go back by using redirectTo and return the paths
    * go back by using redirectTo and return the paths
    *  ex: when
    *  ex: when

+ 5 - 5
packages/app/src/server/util/activityDefine.ts

@@ -2,10 +2,10 @@ const MODEL_PAGE = 'Page';
 const MODEL_COMMENT = 'Comment';
 const MODEL_COMMENT = 'Comment';
 
 
 const ACTION_CREATE = 'CREATE'; // Not support yet
 const ACTION_CREATE = 'CREATE'; // Not support yet
-const ACTION_MODIFY = 'MODIFY'; // Not support yet
+const ACTION_MODIFY = 'MODIFY';
 const ACTION_DELETE = 'DELETE'; // Not support yet
 const ACTION_DELETE = 'DELETE'; // Not support yet
 const ACTION_COMMENT = 'COMMENT';
 const ACTION_COMMENT = 'COMMENT';
-const ACTION_LIKE = 'LIKE';
+const ACTION_LIKE = 'LIKE'; // Not support yet
 
 
 const getSupportTargetModelNames = () => {
 const getSupportTargetModelNames = () => {
   return [MODEL_PAGE];
   return [MODEL_PAGE];
@@ -18,10 +18,10 @@ const getSupportEventModelNames = () => {
 const getSupportActionNames = () => {
 const getSupportActionNames = () => {
   return [
   return [
     // ACTION_CREATE,
     // ACTION_CREATE,
-    // ACTION_MODIFY,
+    ACTION_MODIFY,
     // ACTION_DELETE,
     // ACTION_DELETE,
     ACTION_COMMENT,
     ACTION_COMMENT,
-    ACTION_LIKE,
+    // ACTION_LIKE,
   ];
   ];
 };
 };
 
 
@@ -30,7 +30,7 @@ const activityDefine = {
   MODEL_COMMENT,
   MODEL_COMMENT,
 
 
   ACTION_CREATE, // Not support yet
   ACTION_CREATE, // Not support yet
-  ACTION_MODIFY, // Not support yet
+  ACTION_MODIFY,
   ACTION_DELETE, // Not support yet
   ACTION_DELETE, // Not support yet
   ACTION_COMMENT,
   ACTION_COMMENT,
   ACTION_LIKE,
   ACTION_LIKE,