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

+ 1 - 2
packages/app/src/server/routes/apiv3/bookmarks.js

@@ -310,13 +310,12 @@ module.exports = (crowi) => {
       bookmark.depopulate('user');
     }
 
-    const activityId = res.locals.activity._id;
     const parameters = {
       targetModel: SUPPORTED_TARGET_MODEL_TYPE.MODEL_PAGE,
       target: page,
       action: bool ? SUPPORTED_ACTION_TYPE.ACTION_PAGE_BOOKMARK : SUPPORTED_ACTION_TYPE.ACTION_PAGE_UNBOOKMARK,
     };
-    activityEvent.emit('update', activityId, parameters, page);
+    activityEvent.emit('update', res.locals.activity._id, parameters, page);
 
     return res.apiv3({ bookmark });
   });

+ 3 - 4
packages/app/src/server/routes/comment.js

@@ -245,7 +245,7 @@ module.exports = function(crowi, app) {
     let createdComment;
     try {
       createdComment = await Comment.create(pageId, req.user._id, revisionId, comment, position, isMarkdown, replyTo);
-      commentEvent.emit('create', req.user, createdComment);
+      commentEvent.emit('create', createdComment);
     }
     catch (err) {
       logger.error(err);
@@ -260,7 +260,6 @@ module.exports = function(crowi, app) {
       },
     );
 
-    const activityId = res.locals.activity._id;
     const parameters = {
       targetModel: SUPPORTED_TARGET_MODEL_TYPE.MODEL_PAGE,
       target: page,
@@ -268,7 +267,7 @@ module.exports = function(crowi, app) {
       event: createdComment,
       action: SUPPORTED_ACTION_TYPE.ACTION_COMMENT_CREATE,
     };
-    activityEvent.emit('update', activityId, parameters, page);
+    activityEvent.emit('update', res.locals.activity._id, parameters, page);
 
     res.json(ApiResponse.success({ comment: createdComment }));
 
@@ -391,7 +390,7 @@ module.exports = function(crowi, app) {
         { _id: commentId },
         { $set: { comment: commentStr, isMarkdown, revision } },
       );
-      commentEvent.emit('update', req.user, updatedComment);
+      commentEvent.emit('update', updatedComment);
     }
     catch (err) {
       logger.error(err);

+ 1 - 2
packages/app/src/server/routes/page.js

@@ -991,13 +991,12 @@ module.exports = function(crowi, app) {
       }
     }
 
-    const activityId = res.locals.activity._id;
     const parameters = {
       targetModel: SUPPORTED_TARGET_MODEL_TYPE.MODEL_PAGE,
       target: page,
       action: SUPPORTED_ACTION_TYPE.ACTION_PAGE_UPDATE,
     };
-    activityEvent.emit('update', activityId, parameters, page);
+    activityEvent.emit('update', res.locals.activity._id, parameters, page);
   };
 
   /**

+ 3 - 39
packages/app/src/server/service/comment.ts

@@ -1,13 +1,6 @@
 import { getModelSafely } from '@growi/core';
 import { Types } from 'mongoose';
 
-import {
-  SUPPORTED_TARGET_MODEL_TYPE, SUPPORTED_ACTION_TYPE, SupportedActionType, ISnapshot,
-} from '~/interfaces/activity';
-import { IPage } from '~/interfaces/page';
-import { IUserHasId } from '~/interfaces/user';
-import { stringifySnapshot } from '~/models/serializers/in-app-notification-snapshot/page';
-
 import loggerFactory from '../../utils/logger';
 import Crowi from '../crowi';
 
@@ -39,7 +32,7 @@ class CommentService {
 
   initCommentEventListeners(): void {
     // create
-    this.commentEvent.on('create', async(user, savedComment) => {
+    this.commentEvent.on('create', async(savedComment) => {
 
       try {
         const Page = getModelSafely('Page') || require('../models/page')(this.crowi);
@@ -52,7 +45,7 @@ class CommentService {
     });
 
     // update
-    this.commentEvent.on('update', async(user, updatedComment) => {
+    this.commentEvent.on('update', async() => {
       try {
         this.commentEvent.onUpdate();
       }
@@ -75,36 +68,7 @@ class CommentService {
     });
   }
 
-  private createActivity = async function(user: IUserHasId, target: IPage, action: SupportedActionType) {
-    const snapshot: ISnapshot = { username: user.username };
-    const parameters = {
-      user: user._id,
-      targetModel: SUPPORTED_TARGET_MODEL_TYPE.MODEL_PAGE,
-      target,
-      action,
-      snapshot,
-    };
-    const activity = await this.activityService.createByParameters(parameters);
-    return activity;
-  };
-
-  private createAndSendNotifications = async function(activity, page: IPage) {
-
-    // Get user to be notified
-    let targetUsers: Types.ObjectId[] = [];
-    targetUsers = await activity.getNotificationTargetUsers();
-
-    // Create and send notifications
-    const snapshot = stringifySnapshot(page);
-    // Add mentioned users to targetUsers
-    const mentionedUsers = await this.getMentionedUsers(activity.event);
-    targetUsers = targetUsers.concat(mentionedUsers);
-
-    await this.inAppNotificationService.upsertByActivity(targetUsers, activity, snapshot);
-    await this.inAppNotificationService.emitSocketIo(targetUsers);
-  };
-
-  getMentionedUsers = async function(commentId: Types.ObjectId): Promise<Types.ObjectId[]> {
+  getMentionedUsers = async(commentId: Types.ObjectId): Promise<Types.ObjectId[]> => {
     const Comment = getModelSafely('Comment') || require('../models/comment')(this.crowi);
     const User = getModelSafely('User') || require('../models/user')(this.crowi);