mizozobu 6 лет назад
Родитель
Сommit
89bc4b8517
1 измененных файлов с 14 добавлено и 63 удалено
  1. 14 63
      src/server/service/global-notification.js

+ 14 - 63
src/server/service/global-notification.js

@@ -25,10 +25,10 @@ class GlobalNotificationService {
   fire(notifications, option) {
     notifications.forEach((notification) => {
       if (notification.__t === 'mail') {
-        this.notifyByMail(notification, option.mail);
+        this.notifyByMail(notification, option);
       }
       else if (notification.__t === 'slack') {
-        this.notifyBySlack(notification, option.slack);
+        this.notifyBySlack(notification, option);
       }
     });
   }
@@ -41,7 +41,8 @@ class GlobalNotificationService {
   async notifyPageCreate(page) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(page.path, 'pageCreate');
     const lang = 'en-US'; // FIXME
-    const baseOption = {
+    const option = {
+      subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
       template: nodePath.join(this.crowi.localeDir, `${lang}/notifications/pageCreate.txt`),
       vars: {
         appTitle: this.appTitle,
@@ -49,15 +50,6 @@ class GlobalNotificationService {
         username: page.creator.username,
       },
     };
-    const option = {
-      mail: {
-        subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
-        ...baseOption,
-      },
-      slack: {
-        ...baseOption,
-      },
-    };
 
     logger.debug('notifyPageCreate', option);
 
@@ -72,7 +64,8 @@ class GlobalNotificationService {
   async notifyPageEdit(page) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(page.path, 'pageEdit');
     const lang = 'en-US'; // FIXME
-    const baseOption = {
+    const option = {
+      subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
       template: nodePath.join(this.crowi.localeDir, `${lang}/notifications/pageEdit.txt`),
       vars: {
         appTitle: this.appTitle,
@@ -80,15 +73,6 @@ class GlobalNotificationService {
         username: page.creator.username,
       },
     };
-    const option = {
-      mail: {
-        subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
-        ...baseOption,
-      },
-      slack: {
-        ...baseOption,
-      },
-    };
 
     logger.debug('notifyPageEdit', option);
 
@@ -103,7 +87,8 @@ class GlobalNotificationService {
   async notifyPageDelete(page, triggeredBy) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(page.path, 'pageDelete');
     const lang = 'en-US'; // FIXME
-    const baseOption = {
+    const option = {
+      subject: `#pageDelete - ${triggeredBy.username} deleted ${page.path}`, // FIXME
       template: nodePath.join(this.crowi.localeDir, `${lang}/notifications/pageDelete.txt`),
       vars: {
         appTitle: this.appTitle,
@@ -111,16 +96,6 @@ class GlobalNotificationService {
         username: triggeredBy.username,
       },
     };
-    const option = {
-      mail: {
-        subject: `#pageDelete - ${triggeredBy.username} deleted ${page.path}`, // FIXME
-        ...baseOption,
-      },
-      slack: {
-        ...baseOption,
-
-      },
-    };
 
     this.fire(notifications, option);
   }
@@ -133,7 +108,8 @@ class GlobalNotificationService {
   async notifyPageMove(page, oldPagePath, triggeredBy) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(page.path, 'pageMove');
     const lang = 'en-US'; // FIXME
-    const baseOption = {
+    const option = {
+      subject: `#pageMove - ${triggeredBy.username} moved ${page.path} to ${page.path}`, // FIXME
       template: nodePath.join(this.crowi.localeDir, `${lang}/notifications/pageMove.txt`),
       vars: {
         appTitle: this.appTitle,
@@ -142,15 +118,6 @@ class GlobalNotificationService {
         username: triggeredBy.username,
       },
     };
-    const option = {
-      mail: {
-        subject: `#pageMove - ${triggeredBy.username} moved ${page.path} to ${page.path}`, // FIXME
-        ...baseOption,
-      },
-      slack: {
-        ...baseOption,
-      },
-    };
 
     this.fire(notifications, option);
   }
@@ -163,7 +130,8 @@ class GlobalNotificationService {
   async notifyPageLike(page, triggeredBy) {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(page.path, 'pageLike');
     const lang = 'en-US'; // FIXME
-    const baseOption = {
+    const option = {
+      subject: `#pageLike - ${triggeredBy.username} liked ${page.path}`,
       template: nodePath.join(this.crowi.localeDir, `${lang}/notifications/pageLike.txt`),
       vars: {
         appTitle: this.appTitle,
@@ -171,15 +139,6 @@ class GlobalNotificationService {
         username: triggeredBy.username,
       },
     };
-    const option = {
-      mail: {
-        subject: `#pageLike - ${triggeredBy.username} liked ${page.path}`,
-        ...baseOption,
-      },
-      slack: {
-        ...baseOption,
-      },
-    };
 
     this.fire(notifications, option);
   }
@@ -194,7 +153,8 @@ class GlobalNotificationService {
     const notifications = await this.GlobalNotification.findSettingByPathAndEvent(path, 'comment');
     const lang = 'en-US'; // FIXME
     const triggeredBy = await this.User.findOne({ _id: comment.creator });
-    const baseOption = {
+    const option = {
+      subject: `#comment - ${triggeredBy.username} commented on ${path}`,
       template: nodePath.join(this.crowi.localeDir, `${lang}/notifications/comment.txt`),
       vars: {
         appTitle: this.appTitle,
@@ -203,15 +163,6 @@ class GlobalNotificationService {
         comment: comment.comment,
       },
     };
-    const option = {
-      mail: {
-        subject: `#comment - ${triggeredBy.username} commented on ${path}`,
-        ...baseOption,
-      },
-      slack: {
-        ...baseOption,
-      },
-    };
 
     this.fire(notifications, option);
   }