sou 7 лет назад
Родитель
Сommit
53de8c73fa
3 измененных файлов с 14 добавлено и 10 удалено
  1. 1 1
      lib/routes/comment.js
  2. 1 1
      lib/routes/page.js
  3. 12 8
      lib/util/slack.js

+ 1 - 1
lib/routes/comment.js

@@ -79,7 +79,7 @@ module.exports = function(crowi, app) {
     // slack notification
     const slackNotify = new slack(crowi);
     const user = await User.findUserByUsername(req.user.username);
-    await slackNotify.post(createdComment, user, 'general', 'comment', null);
+    await slackNotify.postComment(createdComment, user, 'general', 'comment');
 
     return res.json(ApiResponse.success({comment: createdComment}));
   };

+ 1 - 1
lib/routes/page.js

@@ -668,7 +668,7 @@ module.exports = function(crowi, app) {
 
           if (crowi.slack) {
             notify.slack.channel.split(',').map(function(chan) {
-              crowi.slack.post(pageData, req.user, chan, updateOrCreate, previousRevision);
+              crowi.slack.postPage(pageData, req.user, chan, updateOrCreate, previousRevision);
             });
           }
         }

+ 12 - 8
lib/util/slack.js

@@ -169,15 +169,19 @@ module.exports = function(crowi) {
   };
 
   // slack.post = function (channel, message, opts) {
-  slack.post = (pageOrComment, user, channel, updateType, previousRevision) => {
-    let messageObj;
-    if (updateType === 'comment') {
-      messageObj = prepareSlackMessageForComment(pageOrComment, user, channel, updateType);
-    }
-    else {
-      messageObj = prepareSlackMessageForPage(pageOrComment, user, channel, updateType, previousRevision);
-    }
+  slack.postPage = (page, user, channel, updateType, previousRevision) => {
+    const messageObj = prepareSlackMessageForPage(page, user, channel, updateType, previousRevision);
+
+    return promisifiedSlackSend(messageObj);
+  };
+
+  slack.postComment = (comment, user, channel, updateType) => {
+    const messageObj = prepareSlackMessageForComment(comment, user, channel, updateType);
+
+    return promisifiedSlackSend(messageObj);
+  };
 
+  const promisifiedSlackSend = (messageObj) => {
     return new Promise((resolve, reject) => {
       // define callback function for Promise
       const callback = function(err, res) {