Jelajahi Sumber

Modified the code based off the first FB

Shunm634-source 3 tahun lalu
induk
melakukan
942b6f310d

+ 3 - 4
packages/app/src/server/models/subscription.ts

@@ -26,7 +26,7 @@ export interface SubscriptionModel extends Model<SubscriptionDocument> {
   subscribeByPageId(user: Types.ObjectId, pageId: Types.ObjectId, status: string): any
   getSubscription(target: Types.ObjectId): Promise<Types.ObjectId[]>
   getUnsubscription(target: Types.ObjectId): Promise<Types.ObjectId[]>
-  getSubscriptions(actionUser: Types.ObjectId, targets: Types.ObjectId[]): Promise<Types.ObjectId[]>
+  getSubscriptions(targets: Types.ObjectId[]): Promise<Types.ObjectId[]>
 }
 
 const subscriptionSchema = new Schema<SubscriptionDocument, SubscriptionModel>({
@@ -88,9 +88,8 @@ subscriptionSchema.statics.getUnsubscription = async function(target) {
   return this.find({ target, status: SubscriptionStatusType.UNSUBSCRIBE }).distinct('user');
 };
 
-subscriptionSchema.statics.getSubscriptions = async function(actionUser, targets) {
-  return (await this.find({ $in: targets, status: SubscriptionStatusType.SUBSCRIBE }).distinct('user'))
-    .filter(item => (item.toString() !== actionUser.toString()));
+subscriptionSchema.statics.getSubscriptions = async function(targets) {
+  return this.find({ $in: targets, status: SubscriptionStatusType.SUBSCRIBE }).distinct('user');
 };
 
 export default getOrCreateModel<SubscriptionDocument, SubscriptionModel>('Subscription', subscriptionSchema);

+ 0 - 1
packages/app/src/server/routes/apiv3/pages.js

@@ -681,7 +681,6 @@ module.exports = (crowi) => {
    */
   router.post('/duplicate', accessTokenParser, loginRequiredStrictly, csrf, validator.duplicatePage, apiV3FormValidator, async(req, res) => {
     const { pageId, isRecursively } = req.body;
-    // console.log('The page is duplicated recursively?', isRecursively, pageId);
 
     const newPagePath = pathUtils.normalizePath(req.body.pageNameInput);
 

+ 4 - 6
packages/app/src/server/service/page.ts

@@ -561,7 +561,7 @@ class PageService {
     return renamedPage;
   }
 
-  async renameSubOperation(page, newPagePath: string, user, options, renamedPage, pageOpId: ObjectIdLike) {
+  async renameSubOperation(page, newPagePath: string, user, options, renamedPage, pageOpId: ObjectIdLike): Promise<void> {
     const Page = mongoose.model('Page') as unknown as PageModel;
 
     const exParentId = page.parent;
@@ -685,7 +685,7 @@ class PageService {
       await PageRedirect.create({ fromPath: page.path, toPath: newPagePath });
     }
 
-    this.pageEvent.emit('rename', page, user);
+    this.pageEvent.emit('rename', page, null, user);
 
     return renamedPage;
   }
@@ -762,7 +762,6 @@ class PageService {
     }
 
     this.pageEvent.emit('updateMany', pages, user);
-    return pages;
   }
 
   private async renameDescendantsV4(pages, user, options, oldPagePathPrefix, newPagePathPrefix) {
@@ -1847,7 +1846,6 @@ class PageService {
         await this.deletePage(page, user, {}, isRecursively);
       }
     }
-    // Call the pageEvent function with the pagesToDelete as the parameter.
   }
 
   // use the same process in both v4 and v5
@@ -2252,8 +2250,8 @@ class PageService {
     // Get user to be notified
     let targetUsers = await activity.getNotificationTargetUsers();
     if (descendantPages != null) {
-      const targetDescendantsUsers = await Subscription.getSubscriptions(user._id, descendantPages);
-      targetUsers = targetUsers.concat(targetDescendantsUsers);
+      const targetDescendantsUsers = await Subscription.getSubscriptions(descendantPages);
+      targetUsers = targetUsers.concat(targetDescendantsUsers.filter(item => (item.toString() !== user._id.toString())));
     }
     // Create and send notifications
     await inAppNotificationService.upsertByActivity(targetUsers, activity, snapshot);