Procházet zdrojové kódy

Merge pull request #5749 from weseek/feat/93526-create-notification-when-page-is-duplicated

feat: Create notification when page is duplicated
Yuki Takei před 4 roky
rodič
revize
cb163290ee

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

@@ -1,16 +1,18 @@
 import React, {
   FC, useRef,
 } from 'react';
-import { DropdownItem } from 'reactstrap';
 
 import { UserPicture } from '@growi/ui';
-import { IInAppNotification, InAppNotificationStatuses } from '~/interfaces/in-app-notification';
+import { DropdownItem } from 'reactstrap';
+
+import { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
+import { apiv3Post } from '~/client/util/apiv3-client';
 import { HasObjectId } from '~/interfaces/has-object-id';
+import { IInAppNotification, InAppNotificationStatuses } from '~/interfaces/in-app-notification';
 
 // Change the display for each targetmodel
 import PageModelNotification from './PageNotification/PageModelNotification';
-import { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
-import { apiv3Post } from '~/client/util/apiv3-client';
+
 
 interface Props {
   notification: IInAppNotification & HasObjectId
@@ -101,6 +103,10 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
       actionMsg = 'renamed';
       actionIcon = 'icon-action-redo';
       break;
+    case 'PAGE_DUPLICATE':
+      actionMsg = 'duplicated';
+      actionIcon = 'icon-docs';
+      break;
     case 'PAGE_DELETE':
       actionMsg = 'deleted';
       actionIcon = 'icon-trash';

+ 12 - 1
packages/app/src/server/service/page.ts

@@ -32,7 +32,6 @@ import { serializePageSecurely } from '../models/serializers/page-serializer';
 import Subscription from '../models/subscription';
 import ActivityDefine from '../util/activityDefine';
 
-
 const debug = require('debug')('growi:services:page');
 
 const logger = loggerFactory('growi:services:page');
@@ -175,6 +174,16 @@ class PageService {
       }
     });
 
+    // duplicate
+    this.pageEvent.on('duplicate', async(page, user) => {
+      try {
+        await this.createAndSendNotifications(page, user, ActivityDefine.ACTION_PAGE_DUPLICATE);
+      }
+      catch (err) {
+        logger.error(err);
+      }
+    });
+
     // delete
     this.pageEvent.on('delete', async(page, user) => {
       try {
@@ -967,6 +976,7 @@ class PageService {
         newPagePath, page.revision.body, user, options,
       );
     }
+    this.pageEvent.emit('duplicate', page, user);
 
     // 4. Take over tags
     const originTags = await page.findRelatedTagsById();
@@ -1061,6 +1071,7 @@ class PageService {
     const createdPage = await Page.create(
       newPagePath, page.revision.body, user, options,
     );
+    this.pageEvent.emit('duplicate', page, user);
 
     if (isRecursively) {
       this.duplicateDescendantsWithStream(page, newPagePath, user);

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

@@ -1,10 +1,13 @@
+// TargetModel
 const MODEL_PAGE = 'Page';
 const MODEL_COMMENT = 'Comment';
 
+// Activity
 const ACTION_PAGE_LIKE = 'PAGE_LIKE';
 const ACTION_PAGE_BOOKMARK = 'PAGE_BOOKMARK';
 const ACTION_PAGE_UPDATE = 'PAGE_UPDATE';
 const ACTION_PAGE_RENAME = 'PAGE_RENAME';
+const ACTION_PAGE_DUPLICATE = 'PAGE_DUPLICATE';
 const ACTION_PAGE_DELETE = 'PAGE_DELETE';
 const ACTION_PAGE_DELETE_COMPLETELY = 'PAGE_DELETE_COMPLETELY';
 const ACTION_COMMENT_CREATE = 'COMMENT_CREATE';
@@ -24,6 +27,7 @@ const getSupportActionNames = () => {
     ACTION_PAGE_BOOKMARK,
     ACTION_PAGE_UPDATE,
     ACTION_PAGE_RENAME,
+    ACTION_PAGE_DUPLICATE,
     ACTION_PAGE_DELETE,
     ACTION_PAGE_DELETE_COMPLETELY,
     ACTION_COMMENT_CREATE,
@@ -39,6 +43,7 @@ const activityDefine = {
   ACTION_PAGE_BOOKMARK,
   ACTION_PAGE_UPDATE,
   ACTION_PAGE_RENAME,
+  ACTION_PAGE_DUPLICATE,
   ACTION_PAGE_DELETE,
   ACTION_PAGE_DELETE_COMPLETELY,
   ACTION_COMMENT_CREATE,