Przeglądaj źródła

Merge pull request #4696 from weseek/feat/81679-81700-create-notification-when-page-is-renamed

feat: 81679 81700 create notification when page is renamed
Yuki Takei 4 lat temu
rodzic
commit
7c60a8e085

+ 4 - 0
packages/app/src/components/InAppNotification/InAppNotificationElm.tsx

@@ -77,6 +77,10 @@ const InAppNotificationElm = (props: Props): JSX.Element => {
       actionMsg = 'updated on';
       actionIcon = 'ti-agenda';
       break;
+    case 'PAGE_RENAME':
+      actionMsg = 'renamed';
+      actionIcon = 'icon-action-redo';
+      break;
     case 'COMMENT_CREATE':
       actionMsg = 'commented on';
       actionIcon = 'icon-bubble';

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

@@ -37,13 +37,24 @@ class PageService {
       this.pageEvent.onUpdate();
 
       try {
-        await this.createAndSendNotifications(page, user);
+        await this.createAndSendNotifications(page, user, ActivityDefine.ACTION_PAGE_UPDATE);
       }
       catch (err) {
         logger.error(err);
       }
     });
 
+    // rename
+    this.pageEvent.on('rename', async(page, user) => {
+      try {
+        await this.createAndSendNotifications(page, user, ActivityDefine.ACTION_PAGE_RENAME);
+      }
+      catch (err) {
+        logger.error(err);
+      }
+    });
+
+    // TODO 81841
 
     // createMany
     this.pageEvent.on('createMany', this.pageEvent.onCreateMany);
@@ -129,6 +140,7 @@ class PageService {
 
     this.pageEvent.emit('delete', page, user);
     this.pageEvent.emit('create', renamedPage, user);
+    this.pageEvent.emit('rename', page, user);
 
     return renamedPage;
   }
@@ -760,7 +772,7 @@ class PageService {
     }
   }
 
-  createAndSendNotifications = async function(page, user) {
+  createAndSendNotifications = async function(page, user, action) {
 
     const { activityService, inAppNotificationService } = this.crowi;
 
@@ -769,7 +781,7 @@ class PageService {
       user: user._id,
       targetModel: ActivityDefine.MODEL_PAGE,
       target: page,
-      action: ActivityDefine.ACTION_PAGE_UPDATE,
+      action,
     };
     const activity = await activityService.createByParameters(parameters);
 

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

@@ -2,6 +2,7 @@ const MODEL_PAGE = 'Page';
 const MODEL_COMMENT = 'Comment';
 
 const ACTION_PAGE_UPDATE = 'PAGE_UPDATE';
+const ACTION_PAGE_RENAME = 'PAGE_RENAME';
 const ACTION_COMMENT_CREATE = 'COMMENT_CREATE';
 const ACTION_COMMENT_UPDATE = 'COMMENT_UPDATE';
 
@@ -16,6 +17,7 @@ const getSupportEventModelNames = () => {
 const getSupportActionNames = () => {
   return [
     ACTION_PAGE_UPDATE,
+    ACTION_PAGE_RENAME,
     ACTION_COMMENT_CREATE,
     ACTION_COMMENT_UPDATE,
   ];
@@ -26,6 +28,7 @@ const activityDefine = {
   MODEL_COMMENT,
 
   ACTION_PAGE_UPDATE,
+  ACTION_PAGE_RENAME,
   ACTION_COMMENT_CREATE,
   ACTION_COMMENT_UPDATE,