Parcourir la source

move to inAppNotificationService

Shun Miyazawa il y a 4 ans
Parent
commit
23ad6aa80c

+ 0 - 9
packages/app/src/server/crowi/index.js

@@ -69,7 +69,6 @@ function Crowi() {
   this.interceptorManager = new InterceptorManager();
   this.interceptorManager = new InterceptorManager();
   this.slackIntegrationService = null;
   this.slackIntegrationService = null;
   this.inAppNotificationService = null;
   this.inAppNotificationService = null;
-  this.inAppNotificationSettingsService = null;
   this.activityService = null;
   this.activityService = null;
   this.commentService = null;
   this.commentService = null;
   this.xss = new Xss();
   this.xss = new Xss();
@@ -130,7 +129,6 @@ Crowi.prototype.init = async function() {
     this.setupImport(),
     this.setupImport(),
     this.setupPageService(),
     this.setupPageService(),
     this.setupInAppNotificationService(),
     this.setupInAppNotificationService(),
-    this.setupInAppNotificationSettingsService(),
     this.setupActivityService(),
     this.setupActivityService(),
     this.setupCommentService(),
     this.setupCommentService(),
     this.setupSyncPageStatusService(),
     this.setupSyncPageStatusService(),
@@ -688,13 +686,6 @@ Crowi.prototype.setupInAppNotificationService = async function() {
   }
   }
 };
 };
 
 
-Crowi.prototype.setupInAppNotificationSettingsService = async function() {
-  const InAppNotificationSettingsService = require('../service/in-app-notification-settings');
-  if (this.inAppNotificationSettingsService == null) {
-    this.inAppNotificationSettingsService = new InAppNotificationSettingsService(this);
-  }
-};
-
 Crowi.prototype.setupActivityService = async function() {
 Crowi.prototype.setupActivityService = async function() {
   const ActivityService = require('../service/activity');
   const ActivityService = require('../service/activity');
   if (this.activityService == null) {
   if (this.activityService == null) {

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

@@ -322,7 +322,7 @@ module.exports = (crowi) => {
 
 
     // create subscription
     // create subscription
     try {
     try {
-      await crowi.inAppNotificationSettingsService.createSubscription(req.user.id, createdPage._id, subscribeRuleNames.PAGE_CREATE);
+      await crowi.inAppNotificationService.createSubscription(req.user.id, createdPage._id, subscribeRuleNames.PAGE_CREATE);
     }
     }
     catch (err) {
     catch (err) {
       logger.error('Failed to create subscription document', err);
       logger.error('Failed to create subscription document', err);

+ 0 - 26
packages/app/src/server/service/in-app-notification-settings.ts

@@ -1,26 +0,0 @@
-import InAppNotificationSettings from '~/server/models/in-app-notification-settings';
-import Subscription, { STATUS_SUBSCRIBE } from '~/server/models/subscription';
-
-import Crowi from '../crowi';
-
-export default class InAppNotificationSettingsService {
-
-  crowi!: Crowi;
-
-  constructor(crowi: Crowi) {
-    this.crowi = crowi;
-  }
-
-  createSubscription = async(userId, pageId, targetRuleName) => {
-    const inAppNotificationSettings = await InAppNotificationSettings.findOne({ userId });
-    if (inAppNotificationSettings != null) {
-      const subscribeRule = inAppNotificationSettings.subscribeRules.find(subscribeRule => subscribeRule.name === targetRuleName);
-      if (subscribeRule !== undefined && subscribeRule.isEnabled) {
-        await Subscription.subscribeByPageId(userId, pageId, STATUS_SUBSCRIBE);
-      }
-    }
-  };
-
-}
-
-module.exports = InAppNotificationSettingsService;

+ 11 - 0
packages/app/src/server/service/in-app-notification.ts

@@ -5,6 +5,8 @@ import {
   InAppNotification, InAppNotificationDocument, STATUS_UNREAD, STATUS_UNOPENED,
   InAppNotification, InAppNotificationDocument, STATUS_UNREAD, STATUS_UNOPENED,
 } from '~/server/models/in-app-notification';
 } from '~/server/models/in-app-notification';
 import { ActivityDocument } from '~/server/models/activity';
 import { ActivityDocument } from '~/server/models/activity';
+import InAppNotificationSettings from '~/server/models/in-app-notification-settings';
+import Subscription, { STATUS_SUBSCRIBE } from '~/server/models/subscription';
 
 
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
 import { RoomPrefix, getRoomNameWithId } from '../util/socket-io-helpers';
@@ -124,6 +126,15 @@ export default class InAppNotificationService {
     }
     }
   };
   };
 
 
+  createSubscription = async(userId, pageId, targetRuleName) => {
+    const inAppNotificationSettings = await InAppNotificationSettings.findOne({ userId });
+    if (inAppNotificationSettings != null) {
+      const subscribeRule = inAppNotificationSettings.subscribeRules.find(subscribeRule => subscribeRule.name === targetRuleName);
+      if (subscribeRule != null && subscribeRule.isEnabled) {
+        await Subscription.subscribeByPageId(userId, pageId, STATUS_SUBSCRIBE);
+      }
+    }
+  };
 
 
 }
 }