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

Merge branch 'feat/81841-create-notification-when-page-is-deleted' into feat/81696-create-like-event

Shun Miyazawa 4 лет назад
Родитель
Сommit
c7d25e5830

+ 12 - 2
packages/app/src/components/InAppNotification/InAppNotificationElm.tsx

@@ -11,7 +11,8 @@ interface Props {
   notification: IInAppNotification & HasObjectId
 }
 
-const InAppNotificationElm = (props: Props): JSX.Element => {
+// TODO 81946 Return to not nullable
+const InAppNotificationElm = (props: Props): JSX.Element | null => {
 
   const { notification } = props;
 
@@ -66,7 +67,12 @@ const InAppNotificationElm = (props: Props): JSX.Element => {
   }, []);
 
   const actionUsers = getActionUsers();
-  const pagePath = { path: props.notification.target.path };
+
+  // TODO 81946 Return to not nullable
+  const pagePath = { path: props.notification.target?.path };
+  if (pagePath.path == null) {
+    return null;
+  }
 
   const actionType: string = notification.action;
   let actionMsg: string;
@@ -81,6 +87,10 @@ const InAppNotificationElm = (props: Props): JSX.Element => {
       actionMsg = 'renamed';
       actionIcon = 'icon-action-redo';
       break;
+    case 'PAGE_DELETE':
+      actionMsg = 'deleted';
+      actionIcon = 'icon-trash';
+      break;
     case 'COMMENT_CREATE':
       actionMsg = 'commented on';
       actionIcon = 'icon-bubble';

+ 1 - 0
packages/app/src/server/models/page.js

@@ -1022,6 +1022,7 @@ module.exports = function(crowi) {
     }
 
     pageEvent.emit('update', savedPage, user);
+    pageEvent.emit('update:notification', savedPage, user);
 
     return savedPage;
   };

+ 13 - 4
packages/app/src/server/service/page.js

@@ -32,7 +32,7 @@ class PageService {
     this.pageEvent.on('create', this.pageEvent.onCreate);
 
     // update
-    this.pageEvent.on('update', async(page, user) => {
+    this.pageEvent.on('update:notification', async(page, user) => {
 
       this.pageEvent.onUpdate();
 
@@ -45,7 +45,7 @@ class PageService {
     });
 
     // rename
-    this.pageEvent.on('rename', async(page, user) => {
+    this.pageEvent.on('rename:notification', async(page, user) => {
       try {
         await this.createAndSendNotifications(page, user, ActivityDefine.ACTION_PAGE_RENAME);
       }
@@ -54,7 +54,15 @@ class PageService {
       }
     });
 
-    // TODO 81841
+    // delete
+    this.pageEvent.on('delete:notification', async(page, user) => {
+      try {
+        await this.createAndSendNotifications(page, user, ActivityDefine.ACTION_PAGE_DELETE);
+      }
+      catch (err) {
+        logger.error(err);
+      }
+    });
 
     // createMany
     this.pageEvent.on('createMany', this.pageEvent.onCreateMany);
@@ -145,7 +153,7 @@ class PageService {
 
     this.pageEvent.emit('delete', page, user);
     this.pageEvent.emit('create', renamedPage, user);
-    this.pageEvent.emit('rename', page, user);
+    this.pageEvent.emit('rename:notification', page, user);
 
     return renamedPage;
   }
@@ -474,6 +482,7 @@ class PageService {
 
     this.pageEvent.emit('delete', page, user);
     this.pageEvent.emit('create', deletedPage, user);
+    this.pageEvent.emit('delete:notification', page, user);
 
     return deletedPage;
   }

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

@@ -3,6 +3,7 @@ const MODEL_COMMENT = 'Comment';
 
 const ACTION_PAGE_UPDATE = 'PAGE_UPDATE';
 const ACTION_PAGE_RENAME = 'PAGE_RENAME';
+const ACTION_PAGE_DELETE = 'PAGE_DELETE';
 const ACTION_COMMENT_CREATE = 'COMMENT_CREATE';
 const ACTION_COMMENT_UPDATE = 'COMMENT_UPDATE';
 
@@ -18,6 +19,7 @@ const getSupportActionNames = () => {
   return [
     ACTION_PAGE_UPDATE,
     ACTION_PAGE_RENAME,
+    ACTION_PAGE_DELETE,
     ACTION_COMMENT_CREATE,
     ACTION_COMMENT_UPDATE,
   ];
@@ -29,6 +31,7 @@ const activityDefine = {
 
   ACTION_PAGE_UPDATE,
   ACTION_PAGE_RENAME,
+  ACTION_PAGE_DELETE,
   ACTION_COMMENT_CREATE,
   ACTION_COMMENT_UPDATE,