|
|
@@ -111,12 +111,27 @@ module.exports = function(crowi) {
|
|
|
return this.convertMarkdownToMrkdwn(body);
|
|
|
};
|
|
|
|
|
|
- slack.prepareAttachmentTextForUpdate = function(page, user) {
|
|
|
- // create diff
|
|
|
- return 'diff';
|
|
|
+ slack.prepareAttachmentTextForUpdate = function(page, user, previousRevision) {
|
|
|
+ var diff = require('diff');
|
|
|
+ var diffText = ''
|
|
|
+
|
|
|
+ diff.diffLines(previousRevision.body, page.revision.body).forEach(function(line) {
|
|
|
+ debug('diff line', line)
|
|
|
+ if (line.added) {
|
|
|
+ diffText += '+' + line.value.replace(/\n/g, '\n+ ');
|
|
|
+ } else if (line.removed) {
|
|
|
+ diffText += '-' + line.value.replace(/\n/g, '\n- ');
|
|
|
+ } else {
|
|
|
+ diffText += '...\n';
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ debug('diff is', diffText)
|
|
|
+
|
|
|
+ return diffText;
|
|
|
};
|
|
|
|
|
|
- slack.prepareSlackMessage = function(page, user, channel, updateType) {
|
|
|
+ slack.prepareSlackMessage = function(page, user, channel, updateType, previousRevision) {
|
|
|
var config = crowi.getConfig();
|
|
|
var url = config.crowi['app:url'] || '';
|
|
|
var body = page.revision.body;
|
|
|
@@ -124,7 +139,7 @@ module.exports = function(crowi) {
|
|
|
if (updateType == 'create') {
|
|
|
body = this.prepareAttachmentTextForCreate(page, user);
|
|
|
} else {
|
|
|
- body = this.prepareAttachmentTextForUpdate(page, user);
|
|
|
+ body = this.prepareAttachmentTextForUpdate(page, user, previousRevision);
|
|
|
}
|
|
|
|
|
|
var attachment = {
|