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

Modified the code based off the FB

Shunm634-source 3 лет назад
Родитель
Сommit
bf9aba54be

+ 2 - 3
packages/app/src/server/service/in-app-notification.ts

@@ -203,7 +203,7 @@ export default class InAppNotificationService {
 
 
   createInAppNotification = async function(activity: ActivityDocument, target: IPage, descendantPages?: Ref<IPage>[]): Promise<void> {
   createInAppNotification = async function(activity: ActivityDocument, target: IPage, descendantPages?: Ref<IPage>[]): Promise<void> {
     const shouldNotification = activity != null && target != null && (AllEssentialActions as ReadonlyArray<string>).includes(activity.action);
     const shouldNotification = activity != null && target != null && (AllEssentialActions as ReadonlyArray<string>).includes(activity.action);
-    const snapshot = stringifySnapshot(target as IPage);
+    const snapshot = stringifySnapshot(target);
     if (shouldNotification) {
     if (shouldNotification) {
       let mentionedUsers: IUser[] = [];
       let mentionedUsers: IUser[] = [];
       if (activity.action === SupportedAction.ACTION_COMMENT_CREATE) {
       if (activity.action === SupportedAction.ACTION_COMMENT_CREATE) {
@@ -221,8 +221,7 @@ export default class InAppNotificationService {
         }).distinct('_id');
         }).distinct('_id');
       }
       }
       await this.upsertByActivity([...notificationTargetUsers, ...mentionedUsers, ...notificationDescendantsUsers], activity, snapshot);
       await this.upsertByActivity([...notificationTargetUsers, ...mentionedUsers, ...notificationDescendantsUsers], activity, snapshot);
-      await this.emitSocketIo(notificationTargetUsers);
-      if (notificationDescendantsUsers != null && notificationDescendantsUsers.length > 0) await this.emitSocketIo(notificationDescendantsUsers);
+      await this.emitSocketIo([...notificationTargetUsers, notificationDescendantsUsers]);
     }
     }
     else {
     else {
       throw Error('No activity to notify');
       throw Error('No activity to notify');

+ 8 - 10
packages/app/src/server/service/page.ts

@@ -467,7 +467,6 @@ class PageService {
       update.updatedAt = new Date();
       update.updatedAt = new Date();
     }
     }
     const renamedPage = await Page.findByIdAndUpdate(page._id, { $set: update }, { new: true });
     const renamedPage = await Page.findByIdAndUpdate(page._id, { $set: update }, { new: true });
-    this.pageEvent.emit('rename', page, user);
 
 
     // 5.increase parent's descendantCount.
     // 5.increase parent's descendantCount.
     // see: https://dev.growi.org/62149d019311629d4ecd91cf#Handling%20of%20descendantCount%20in%20case%20of%20unexpected%20process%20interruption
     // see: https://dev.growi.org/62149d019311629d4ecd91cf#Handling%20of%20descendantCount%20in%20case%20of%20unexpected%20process%20interruption
@@ -479,6 +478,7 @@ class PageService {
       const PageRedirect = mongoose.model('PageRedirect') as unknown as PageRedirectModel;
       const PageRedirect = mongoose.model('PageRedirect') as unknown as PageRedirectModel;
       await PageRedirect.create({ fromPath: page.path, toPath: newPagePath });
       await PageRedirect.create({ fromPath: page.path, toPath: newPagePath });
     }
     }
+    this.pageEvent.emit('rename');
 
 
     // Set to Sub
     // Set to Sub
     const pageOp = await PageOperation.findByIdAndUpdatePageActionStage(pageOpId, PageActionStage.Sub);
     const pageOp = await PageOperation.findByIdAndUpdatePageActionStage(pageOpId, PageActionStage.Sub);
@@ -531,7 +531,6 @@ class PageService {
     }
     }
 
 
     await PageOperation.findByIdAndDelete(pageOpId);
     await PageOperation.findByIdAndDelete(pageOpId);
-
   }
   }
 
 
   async resumeRenameSubOperation(renamedPage: PageDocument, pageOp: PageOperationDocument): Promise<void> {
   async resumeRenameSubOperation(renamedPage: PageDocument, pageOp: PageOperationDocument): Promise<void> {
@@ -1388,10 +1387,6 @@ class PageService {
        */
        */
       this.deleteRecursivelyMainOperation(page, user, pageOp._id);
       this.deleteRecursivelyMainOperation(page, user, pageOp._id);
     }
     }
-    else {
-
-      this.pageEvent.emit('delete', page, user);
-    }
 
 
     return deletedPage;
     return deletedPage;
   }
   }
@@ -1417,6 +1412,7 @@ class PageService {
         throw err;
         throw err;
       }
       }
     }
     }
+    this.pageEvent.emit('delete', page, user);
     this.pageEvent.emit('create', deletedPage, user);
     this.pageEvent.emit('create', deletedPage, user);
 
 
     return deletedPage;
     return deletedPage;
@@ -1682,6 +1678,10 @@ class PageService {
     // delete leaf empty pages
     // delete leaf empty pages
     await Page.removeLeafEmptyPagesRecursively(page.parent);
     await Page.removeLeafEmptyPagesRecursively(page.parent);
 
 
+    if (!page.isEmpty && !preventEmitting) {
+      this.pageEvent.emit('deleteCompletely', page, user);
+    }
+
     if (isRecursively) {
     if (isRecursively) {
       let pageOp;
       let pageOp;
       try {
       try {
@@ -1703,9 +1703,6 @@ class PageService {
        */
        */
       this.deleteCompletelyRecursivelyMainOperation(page, user, options, pageOp._id);
       this.deleteCompletelyRecursivelyMainOperation(page, user, options, pageOp._id);
     }
     }
-    else if (!page.isEmpty && !preventEmitting) {
-      this.pageEvent.emit('deleteCompletely', page, user);
-    }
 
 
     return;
     return;
   }
   }
@@ -1887,9 +1884,10 @@ class PageService {
     }, { new: true });
     }, { new: true });
     await PageTagRelation.updateMany({ relatedPage: page._id }, { $set: { isPageTrashed: false } });
     await PageTagRelation.updateMany({ relatedPage: page._id }, { $set: { isPageTrashed: false } });
 
 
+    this.pageEvent.emit('revert', page, user);
+
     if (!isRecursively) {
     if (!isRecursively) {
       await this.updateDescendantCountOfAncestors(parent._id, 1, true);
       await this.updateDescendantCountOfAncestors(parent._id, 1, true);
-      this.pageEvent.emit('revert', page, user);
     }
     }
     else {
     else {
       let pageOp;
       let pageOp;