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

no update type for commentPost

sou 7 лет назад
Родитель
Сommit
33d9d76618
3 измененных файлов с 20 добавлено и 17 удалено
  1. 2 4
      lib/models/comment.js
  2. 1 1
      lib/routes/comment.js
  3. 17 12
      lib/util/slack.js

+ 2 - 4
lib/models/comment.js

@@ -36,10 +36,8 @@ module.exports = function(crowi) {
           debug('Error on saving comment.', err);
           debug('Error on saving comment.', err);
           return reject(err);
           return reject(err);
         }
         }
-        data.populate('page', function(err, commentWithPage) {
-          debug('Comment saved.', commentWithPage);
-          return resolve(commentWithPage);
-        });
+        debug('Comment saved.', data);
+        return resolve(data);
       });
       });
     });
     });
   };
   };

+ 1 - 1
lib/routes/comment.js

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

+ 17 - 12
lib/util/slack.js

@@ -117,14 +117,14 @@ module.exports = function(crowi) {
     const message = {
     const message = {
       channel: '#' + channel,
       channel: '#' + channel,
       username: Config.appTitle(config),
       username: Config.appTitle(config),
-      text: getSlackMessageText(page.path, user, updateType),
+      text: getSlackMessageTextForPage(page.path, user, updateType),
       attachments: [attachment],
       attachments: [attachment],
     };
     };
 
 
     return message;
     return message;
   };
   };
 
 
-  const prepareSlackMessageForComment = function(comment, user, channel, updateType) {
+  const prepareSlackMessageForComment = function(comment, user, channel) {
     const url = config.crowi['app:url'] || '';
     const url = config.crowi['app:url'] || '';
     const body = prepareAttachmentTextForComment(comment, user);
     const body = prepareAttachmentTextForComment(comment, user);
 
 
@@ -143,14 +143,14 @@ module.exports = function(crowi) {
     const message = {
     const message = {
       channel: '#' + channel,
       channel: '#' + channel,
       username: Config.appTitle(config),
       username: Config.appTitle(config),
-      text: getSlackMessageText(comment.page.path, user, updateType),
+      text: getSlackMessageTextForComment('what do i do with path', user),
       attachments: [attachment],
       attachments: [attachment],
     };
     };
 
 
     return message;
     return message;
   };
   };
 
 
-  const getSlackMessageText = function(path, user, updateType) {
+  const getSlackMessageTextForPage = function(path, user, updateType) {
     let text;
     let text;
     const url = config.crowi['app:url'] || '';
     const url = config.crowi['app:url'] || '';
 
 
@@ -158,9 +158,6 @@ module.exports = function(crowi) {
     if (updateType == 'create') {
     if (updateType == 'create') {
       text = `:white_check_mark: ${user.username} created a new page! ${pageUrl}`;
       text = `:white_check_mark: ${user.username} created a new page! ${pageUrl}`;
     }
     }
-    else if (updateType == 'comment') {
-      text = `:speech_balloon: ${user.username} commented on ${pageUrl}`;
-    }
     else {
     else {
       text = `:up: ${user.username} updated ${pageUrl}`;
       text = `:up: ${user.username} updated ${pageUrl}`;
     }
     }
@@ -168,20 +165,28 @@ module.exports = function(crowi) {
     return text;
     return text;
   };
   };
 
 
+  const getSlackMessageTextForComment = function(path, user) {
+    const url = config.crowi['app:url'] || '';
+    const pageUrl = `<${url}${path}|${path}>`;
+    const text = `:speech_balloon: ${user.username} commented on ${pageUrl}`;
+
+    return text;
+  };
+
   // slack.post = function (channel, message, opts) {
   // slack.post = function (channel, message, opts) {
   slack.postPage = (page, user, channel, updateType, previousRevision) => {
   slack.postPage = (page, user, channel, updateType, previousRevision) => {
     const messageObj = prepareSlackMessageForPage(page, user, channel, updateType, previousRevision);
     const messageObj = prepareSlackMessageForPage(page, user, channel, updateType, previousRevision);
 
 
-    return promisifiedSlackSend(messageObj);
+    return promisifiedSlackPost(messageObj);
   };
   };
 
 
-  slack.postComment = (comment, user, channel, updateType) => {
-    const messageObj = prepareSlackMessageForComment(comment, user, channel, updateType);
+  slack.postComment = (comment, user, channel) => {
+    const messageObj = prepareSlackMessageForComment(comment, user, channel);
 
 
-    return promisifiedSlackSend(messageObj);
+    return promisifiedSlackPost(messageObj);
   };
   };
 
 
-  const promisifiedSlackSend = (messageObj) => {
+  const promisifiedSlackPost = (messageObj) => {
     return new Promise((resolve, reject) => {
     return new Promise((resolve, reject) => {
       // define callback function for Promise
       // define callback function for Promise
       const callback = function(err, res) {
       const callback = function(err, res) {