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

+ 4 - 2
lib/models/comment.js

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

+ 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.post(createdComment, user, 'general, random', 'comment', null);
+    await slackNotify.post(createdComment, user, 'general', 'comment', null);
 
 
     return res.json(ApiResponse.success({comment: createdComment}));
     return res.json(ApiResponse.success({comment: createdComment}));
   };
   };

+ 8 - 9
lib/util/slack.js

@@ -80,12 +80,13 @@ module.exports = function(crowi) {
     return diffText;
     return diffText;
   };
   };
 
 
-  const prepareAttachmentTextForComment = function(page, user, channel, updateType, previousRevision) {
-    return {
-      channel: '#general',
-      username: 'Growi',
-      text: '`comment uploaded`'
-    };
+  const prepareAttachmentTextForComment = function(comment) {
+    let body = comment.comment;
+    if (body.length > 2000) {
+      body = body.substr(0, 2000) + '...';
+    }
+
+    return convertMarkdownToMrkdwn(body);
   };
   };
 
 
   const prepareSlackMessageForPage = function(page, user, channel, updateType, previousRevision) {
   const prepareSlackMessageForPage = function(page, user, channel, updateType, previousRevision) {
@@ -132,8 +133,6 @@ module.exports = function(crowi) {
       author_name: '@' + user.username,
       author_name: '@' + user.username,
       author_link: url + '/user/' + user.username,
       author_link: url + '/user/' + user.username,
       author_icon: user.image,
       author_icon: user.image,
-      title: comment.comment,
-      title_link: url + '/' + comment._id,
       text: body,
       text: body,
       mrkdwn_in: ['text'],
       mrkdwn_in: ['text'],
     };
     };
@@ -144,7 +143,7 @@ module.exports = function(crowi) {
     const message = {
     const message = {
       channel: '#' + channel,
       channel: '#' + channel,
       username: Config.appTitle(config),
       username: Config.appTitle(config),
-      text: getSlackMessageText(comment.path, user, updateType),
+      text: getSlackMessageText(comment.page.path, user, updateType),
       attachments: [attachment],
       attachments: [attachment],
     };
     };