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

Merge pull request #4564 from weseek/fix/80424-remove-comment-update-activity

Fix/80424 remove comment update activity
Yuki Takei 4 лет назад
Родитель
Сommit
96bfc89cad

+ 8 - 11
packages/app/src/components/InAppNotification/InAppNotification.tsx

@@ -55,19 +55,16 @@ export const InAppNotification = (props: Props): JSX.Element => {
     );
   };
 
-  const componentName = `${notification.targetModel}:${notification.action}`;
-  const propsNew = {
-    actionUsers: getActionUsers(),
-    ...props,
-  };
-
   const renderInAppNotificationContent = (): JSX.Element => {
-    switch (componentName) {
-      // TODO Is the naming of componentName too subtle?
-      case 'Page:UPDATE':
+    const propsNew = {
+      actionUsers: getActionUsers(),
+      ...props,
+    };
+    const action: string = notification.action;
+    switch (action) {
+      case 'PAGE_UPDATE':
         return <PageUpdateNotification {...propsNew} onClick={props.onClick(props.notification)} />;
-      case 'Page:COMMENT_CREATE':
-      case 'Page:COMMENT_UPDATE':
+      case 'COMMENT_CREATE':
         return <PageCommentNotification {...propsNew} onClick={props.onClick(props.notification)} />;
       default:
         return <></>;

+ 9 - 9
packages/app/src/server/service/comment.ts

@@ -6,7 +6,6 @@ import Crowi from '../crowi';
 
 const logger = loggerFactory('growi:service:CommentService');
 
-
 class CommentService {
 
   crowi!: Crowi;
@@ -28,7 +27,6 @@ class CommentService {
     this.initCommentEventListeners();
   }
 
-
   initCommentEventListeners(): void {
     // create
     this.commentEvent.on('create', async(savedComment) => {
@@ -37,7 +35,8 @@ class CommentService {
         const Page = getModelSafely('Page') || require('../models/page')(this.crowi);
         await Page.updateCommentCount(savedComment.page);
 
-        await this.createAndSendNotifications(savedComment, ActivityDefine.ACTION_COMMENT_CREATE);
+        const activity = await this.createActivity(savedComment, ActivityDefine.ACTION_COMMENT_CREATE);
+        await this.createAndSendNotifications(activity);
       }
       catch (err) {
         logger.error('Error occurred while handling the comment create event:\n', err);
@@ -49,8 +48,7 @@ class CommentService {
     this.commentEvent.on('update', async(updatedComment) => {
       try {
         this.commentEvent.onUpdate();
-
-        await this.createAndSendNotifications(updatedComment, ActivityDefine.ACTION_COMMENT_UPDATE);
+        await this.createActivity(updatedComment, ActivityDefine.ACTION_COMMENT_UPDATE);
       }
       catch (err) {
         logger.error('Error occurred while handling the comment update event:\n', err);
@@ -71,18 +69,20 @@ class CommentService {
     });
   }
 
-  private createAndSendNotifications = async function(comment, actionType) {
-
-    // Create activity
+  private createActivity = async function(comment, action) {
     const parameters = {
       user: comment.creator,
       targetModel: ActivityDefine.MODEL_PAGE,
       target: comment.page,
       eventModel: ActivityDefine.MODEL_COMMENT,
       event: comment._id,
-      action: actionType,
+      action,
     };
     const activity = await this.activityService.createByParameters(parameters);
+    return activity;
+  };
+
+  private createAndSendNotifications = async function(activity) {
 
     // Get user to be notified
     let targetUsers: Types.ObjectId[] = [];

+ 1 - 1
packages/app/src/server/service/page.js

@@ -769,7 +769,7 @@ class PageService {
       user: user._id,
       targetModel: ActivityDefine.MODEL_PAGE,
       target: page,
-      action: ActivityDefine.ACTION_UPDATE,
+      action: ActivityDefine.ACTION_PAGE_UPDATE,
     };
     const activity = await activityService.createByParameters(parameters);
 

+ 3 - 15
packages/app/src/server/util/activityDefine.ts

@@ -1,11 +1,7 @@
 const MODEL_PAGE = 'Page';
 const MODEL_COMMENT = 'Comment';
 
-const ACTION_UPDATE = 'UPDATE';
-const ACTION_COMMENT = 'COMMENT';
-const ACTION_CREATE = 'CREATE'; // Not support yet
-const ACTION_DELETE = 'DELETE'; // Not support yet
-const ACTION_LIKE = 'LIKE'; // Not support yet
+const ACTION_PAGE_UPDATE = 'PAGE_UPDATE';
 const ACTION_COMMENT_CREATE = 'COMMENT_CREATE';
 const ACTION_COMMENT_UPDATE = 'COMMENT_UPDATE';
 
@@ -19,11 +15,7 @@ const getSupportEventModelNames = () => {
 
 const getSupportActionNames = () => {
   return [
-    // ACTION_CREATE,
-    ACTION_UPDATE,
-    // ACTION_DELETE,
-    ACTION_COMMENT,
-    // ACTION_LIKE,
+    ACTION_PAGE_UPDATE,
     ACTION_COMMENT_CREATE,
     ACTION_COMMENT_UPDATE,
   ];
@@ -33,11 +25,7 @@ const activityDefine = {
   MODEL_PAGE,
   MODEL_COMMENT,
 
-  ACTION_CREATE, // Not support yet
-  ACTION_UPDATE,
-  ACTION_DELETE, // Not support yet
-  ACTION_COMMENT,
-  ACTION_LIKE,
+  ACTION_PAGE_UPDATE,
   ACTION_COMMENT_CREATE,
   ACTION_COMMENT_UPDATE,