|
|
@@ -88,21 +88,18 @@ module.exports = function(crowi) {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
- const prepareSlackMessage = function(page, user, channel, updateType, previousRevision, comment) {
|
|
|
- var url = config.crowi['app:url'] || '';
|
|
|
- var body = page.revision.body;
|
|
|
+ const prepareSlackMessageForPage = function(page, user, channel, updateType, previousRevision) {
|
|
|
+ const url = config.crowi['app:url'] || '';
|
|
|
+ let body = page.revision.body;
|
|
|
|
|
|
if (updateType == 'create') {
|
|
|
body = prepareAttachmentTextForCreate(page, user);
|
|
|
}
|
|
|
- else if (updateType == 'comment') {
|
|
|
- body = prepareAttachmentTextForComment(page, user);
|
|
|
- }
|
|
|
else {
|
|
|
body = prepareAttachmentTextForUpdate(page, user, previousRevision);
|
|
|
}
|
|
|
|
|
|
- var attachment = {
|
|
|
+ const attachment = {
|
|
|
color: '#263a3c',
|
|
|
author_name: '@' + user.username,
|
|
|
author_link: url + '/user/' + user.username,
|
|
|
@@ -113,27 +110,43 @@ module.exports = function(crowi) {
|
|
|
mrkdwn_in: ['text'],
|
|
|
};
|
|
|
|
|
|
- if (updateType == 'comment') {
|
|
|
- attachment = {
|
|
|
- color: '#263a3c',
|
|
|
- author_name: '@' + user.username,
|
|
|
- author_link: url + '/user/' + user.username,
|
|
|
- author_icon: user.image,
|
|
|
- title: comment.comment,
|
|
|
- title_link: url + '/' + page._id,
|
|
|
- text: body,
|
|
|
- mrkdwn_in: ['text'],
|
|
|
- };
|
|
|
+ if (user.image) {
|
|
|
+ attachment.author_icon = user.image;
|
|
|
}
|
|
|
|
|
|
+ const message = {
|
|
|
+ channel: '#' + channel,
|
|
|
+ username: Config.appTitle(config),
|
|
|
+ text: getSlackMessageText(page.path, user, updateType),
|
|
|
+ attachments: [attachment],
|
|
|
+ };
|
|
|
+
|
|
|
+ return message;
|
|
|
+ };
|
|
|
+
|
|
|
+ const prepareSlackMessageForComment = function(comment, user, channel, updateType) {
|
|
|
+ const url = config.crowi['app:url'] || '';
|
|
|
+ const body = prepareAttachmentTextForComment(comment, user);
|
|
|
+
|
|
|
+ const attachment = {
|
|
|
+ color: '#263a3c',
|
|
|
+ author_name: '@' + user.username,
|
|
|
+ author_link: url + '/user/' + user.username,
|
|
|
+ author_icon: user.image,
|
|
|
+ title: comment.comment,
|
|
|
+ title_link: url + '/' + comment._id,
|
|
|
+ text: body,
|
|
|
+ mrkdwn_in: ['text'],
|
|
|
+ };
|
|
|
+
|
|
|
if (user.image) {
|
|
|
attachment.author_icon = user.image;
|
|
|
}
|
|
|
|
|
|
- var message = {
|
|
|
+ const message = {
|
|
|
channel: '#' + channel,
|
|
|
username: Config.appTitle(config),
|
|
|
- text: getSlackMessageText(page.path, user, updateType),
|
|
|
+ text: getSlackMessageText(comment.path, user, updateType),
|
|
|
attachments: [attachment],
|
|
|
};
|
|
|
|
|
|
@@ -159,8 +172,14 @@ module.exports = function(crowi) {
|
|
|
};
|
|
|
|
|
|
// slack.post = function (channel, message, opts) {
|
|
|
- slack.post = (page, user, channel, updateType, previousRevision, comment) => {
|
|
|
- const messageObj = prepareSlackMessage(page, user, channel, updateType, previousRevision, comment);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
// define callback function for Promise
|