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

Changed the file name to correspond to kebab case

WNomunomu 2 лет назад
Родитель
Сommit
a48885a30e

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

@@ -1,7 +1,7 @@
 import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
 import { generateAddActivityMiddleware } from '~/server/middlewares/add-activity';
 import { serializeBookmarkSecurely } from '~/server/models/serializers/bookmark-serializer';
-import { preNotifyService } from '~/server/service/preNotify';
+import { preNotifyService } from '~/server/service/pre-notify';
 import loggerFactory from '~/utils/logger';
 
 import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';

+ 1 - 1
apps/app/src/server/routes/apiv3/page.js

@@ -14,7 +14,7 @@ import { apiV3FormValidator } from '~/server/middlewares/apiv3-form-validator';
 import { excludeReadOnlyUser } from '~/server/middlewares/exclude-read-only-user';
 import Subscription from '~/server/models/subscription';
 import UserGroup from '~/server/models/user-group';
-import { preNotifyService } from '~/server/service/preNotify';
+import { preNotifyService } from '~/server/service/pre-notify';
 import { divideByType } from '~/server/util/granted-group';
 import loggerFactory from '~/utils/logger';
 

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

@@ -6,7 +6,7 @@ import { normalizePath, addHeadingSlash, attachTitleHeader } from '@growi/core/d
 
 import { SupportedTargetModel, SupportedAction } from '~/interfaces/activity';
 import { subscribeRuleNames } from '~/interfaces/in-app-notification';
-import { preNotifyService } from '~/server/service/preNotify';
+import { preNotifyService } from '~/server/service/pre-notify';
 import loggerFactory from '~/utils/logger';
 
 import { generateAddActivityMiddleware } from '../../middlewares/add-activity';

+ 1 - 1
apps/app/src/server/routes/comment.js

@@ -3,7 +3,7 @@ import { Comment, CommentEvent, commentEvent } from '~/features/comment/server';
 import { SupportedAction, SupportedTargetModel, SupportedEventModel } from '~/interfaces/activity';
 import loggerFactory from '~/utils/logger';
 
-import { preNotifyService } from '../service/preNotify';
+import { preNotifyService } from '../service/pre-notify';
 
 /**
  * @swagger

+ 1 - 1
apps/app/src/server/routes/page.js

@@ -7,7 +7,7 @@ import loggerFactory from '~/utils/logger';
 
 import { PathAlreadyExistsError } from '../models/errors';
 import UpdatePost from '../models/update-post';
-import { preNotifyService } from '../service/preNotify';
+import { preNotifyService } from '../service/pre-notify';
 
 const { serializePageSecurely } = require('../models/serializers/page-serializer');
 const { serializeRevisionSecurely } = require('../models/serializers/revision-serializer');

+ 11 - 4
apps/app/src/server/service/activity.ts

@@ -11,7 +11,7 @@ import loggerFactory from '../../utils/logger';
 import Crowi from '../crowi';
 
 
-import type { GeneratePreNotify, GetAdditionalTargetUsers } from './preNotify';
+import type { GeneratePreNotify, GetAdditionalTargetUsers } from './pre-notify';
 
 const logger = loggerFactory('growi:service:ActivityService');
 
@@ -42,7 +42,7 @@ class ActivityService {
 
   initActivityEventListeners(): void {
     this.activityEvent.on('update', async(
-        activityId: string, parameters, target: IPage, generatePreNotify: GeneratePreNotify, getAdditionalTargetUsers?: GetAdditionalTargetUsers,
+        activityId: string, parameters, target: IPage, generatePreNotify?: GeneratePreNotify, getAdditionalTargetUsers?: GetAdditionalTargetUsers,
     ) => {
       let activity: ActivityDocument;
       const shoudUpdate = this.shoudUpdateActivity(parameters.action);
@@ -56,9 +56,16 @@ class ActivityService {
           return;
         }
 
-        const preNotify = generatePreNotify(activity, getAdditionalTargetUsers);
+        if (generatePreNotify != null) {
+          const preNotify = generatePreNotify(activity, getAdditionalTargetUsers);
+
+          this.activityEvent.emit('updated', activity, target, preNotify);
+
+          return;
+        }
+
+        this.activityEvent.emit('updated', activity, target);
 
-        this.activityEvent.emit('updated', activity, target, preNotify);
       }
     });
   }

+ 1 - 1
apps/app/src/server/service/in-app-notification.ts

@@ -20,7 +20,7 @@ import Crowi from '../crowi';
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
 
 import { generateSnapshot } from './in-app-notification/in-app-notification-utils';
-import { preNotifyService, type PreNotify } from './preNotify';
+import { preNotifyService, type PreNotify } from './pre-notify';
 
 
 const { STATUS_UNREAD, STATUS_UNOPENED, STATUS_OPENED } = InAppNotificationStatuses;

+ 1 - 1
apps/app/src/server/service/page.ts

@@ -46,7 +46,7 @@ import UserGroupRelation from '../models/user-group-relation';
 import { V5ConversionError } from '../models/vo/v5-conversion-error';
 import { divideByType } from '../util/granted-group';
 
-import { preNotifyService } from './preNotify';
+import { preNotifyService } from './pre-notify';
 
 const debug = require('debug')('growi:services:page');
 

+ 0 - 61
apps/app/src/server/service/preNotify.ts

@@ -1,61 +0,0 @@
-import type {
-  IPage, IUser, Ref,
-} from '@growi/core';
-
-import { ActivityDocument } from '../models/activity';
-import Subscription from '../models/subscription';
-import { getModelSafely } from '../util/mongoose-utils';
-
-export type PreNotifyProps = {
-  notificationTargetUsers?: Ref<IUser>[],
-}
-
-export type PreNotify = (props: PreNotifyProps) => Promise<void>;
-export type GeneratePreNotify = (activity: ActivityDocument, getAdditionalTargetUsers?: (activity?: ActivityDocument) => Ref<IUser>[]) => PreNotify;
-
-export type GetAdditionalTargetUsers = (activity: ActivityDocument) => Ref<IUser>[];
-
-class PreNotifyService {
-
-  generateInitialPreNotifyProps = (): PreNotifyProps => {
-
-    const initialPreNotifyProps: Ref<IUser>[] = [];
-
-    return { notificationTargetUsers: initialPreNotifyProps };
-  };
-
-  generatePreNotify = (activity: ActivityDocument, getAdditionalTargetUsers?: GetAdditionalTargetUsers): PreNotify => {
-
-    const preNotify = async(props: PreNotifyProps) => {
-      const { notificationTargetUsers } = props;
-
-      const User = getModelSafely('User') || require('~/server/models/user')();
-      const actionUser = activity.user;
-      const target = activity.target;
-      const subscribedUsers = await Subscription.getSubscription(target as unknown as Ref<IPage>);
-      const notificationUsers = subscribedUsers.filter(item => (item.toString() !== actionUser._id.toString()));
-      const activeNotificationUsers = await User.find({
-        _id: { $in: notificationUsers },
-        status: User.STATUS_ACTIVE,
-      }).distinct('_id');
-
-      if (getAdditionalTargetUsers == null) {
-        notificationTargetUsers?.push(...activeNotificationUsers);
-      }
-      else {
-        const AdditionalTargetUsers = getAdditionalTargetUsers(activity);
-
-        notificationTargetUsers?.push(
-          ...activeNotificationUsers,
-          ...AdditionalTargetUsers,
-        );
-      }
-
-    };
-
-    return preNotify;
-  };
-
-}
-
-export const preNotifyService = new PreNotifyService();