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

refactor global user notification

zahmis 5 лет назад
Родитель
Сommit
d3a10e8f67

+ 3 - 6
src/server/service/global-notification/global-notification-slack.js

@@ -31,16 +31,13 @@ class GlobalNotificationSlackService {
     const messageBody = this.generateMessageBody(event, path, triggeredBy, vars);
     const attachmentBody = this.generateAttachmentBody(event, path, triggeredBy, vars);
 
-    if (this.crowi.configManager.getConfig('notification', 'slack:isIncomingWebhookPrioritized')) {
-      await Promise.all(notifications.map((notification) => {
-        return this.slackLegacy.sendGlobalNotification(messageBody, attachmentBody, notification.slackChannels);
-      }));
-    }
-    else if (this.crowi.configManager.getConfig('crowi', 'slackbot:token')) {
+    // use SlackBot
+    if (this.crowi.configManager.getConfig('crowi', 'slackbot:token')) {
       await Promise.all(notifications.map((notification) => {
         return this.slack.sendGlobalNotification(messageBody, attachmentBody, notification.slackChannels);
       }));
     }
+    // use SlackLegacy
     else {
       await Promise.all(notifications.map((notification) => {
         return this.slackLegacy.sendGlobalNotification(messageBody, attachmentBody, notification.slackChannels);

+ 12 - 8
src/server/service/user-notification/index.js

@@ -24,7 +24,9 @@ class UserNotificationService {
    * @param {Comment} comment
    */
   async fire(page, user, slackChannelsStr, mode, option, comment = {}) {
-    const { slackNotificationService, slackLegacy, slack } = this.crowi;
+    const {
+      slackNotificationService, configManager, slackLegacy, slack,
+    } = this.crowi;
 
     const opt = option || {};
     const previousRevision = opt.previousRevision || '';
@@ -41,17 +43,19 @@ class UserNotificationService {
     const promises = slackChannels.map(async(chan) => {
       let res;
       if (mode === 'comment') {
-        if (this.crowi.configManager.getConfig('notification', 'slack:isIncomingWebhookPrioritized')) {
-          res = slackLegacy.postComment(comment, user, chan, page.path);
+        if (configManager.getConfig('crowi', 'slackbot:token')) {
+          res = await slack.postComment(comment, user, chan, page.path);
         }
-        res = await slack.postComment(comment, user, chan, page.path);
-      }
-      else {
-        if (this.crowi.configManager.getConfig('notification', 'slack:isIncomingWebhookPrioritized')) {
-          res = slackLegacy.postComment(comment, user, chan, page.path);
+        else {
+          res = await slackLegacy.postComment(comment, user, chan, page.path);
         }
+      }
+      else if (configManager.getConfig('crowi', 'slackbot:token')) {
         res = await slack.postPage(page, user, chan, mode, previousRevision);
       }
+      else {
+        res = await slackLegacy.postPage(page, user, chan, mode, previousRevision);
+      }
       if (res.status !== 'ok') {
         throw new Error(`fail to send slack notification to #${chan} channel`);
       }