diff --git a/common/at.js b/common/at.js index ec37f7b..f132acf 100644 --- a/common/at.js +++ b/common/at.js @@ -71,6 +71,11 @@ exports.sendMessageToMentionUsers = function (text, topicId, authorId, reply_id, } var ep = new EventProxy(); ep.fail(callback); + + users = users.filter(function (user) { + return !user._id.equals(authorId); + }); + ep.after('sent', users.length, function () { callback(); }); diff --git a/test/common/at.test.js b/test/common/at.test.js index 1dd7d4a..609f7f9 100644 --- a/test/common/at.test.js +++ b/test/common/at.test.js @@ -11,12 +11,13 @@ var multiline = require('multiline'); var pedding = require('pedding'); describe('test/common/at.test.js', function () { - var testTopic, normalUser, normalUser2; + var testTopic, normalUser, normalUser2, adminUser; before(function (done) { support.ready(function () { testTopic = support.testTopic; normalUser = support.normalUser; normalUser2 = support.normalUser2; + adminUser = support.adminUser; done(); }); }); @@ -156,7 +157,7 @@ aldjf describe('sendMessageToMentionUsers()', function () { it('should send message to all mention users', function (done) { done = pedding(done, 2); - var atUserIds = [String(normalUser._id), String(normalUser2._id)]; + var atUserIds = [String(adminUser._id), String(normalUser2._id)]; var ep = new eventproxy(); ep.after('user_id', atUserIds.length, function (user_ids) { @@ -170,7 +171,7 @@ aldjf callback(); }); - var text = '@' + normalUser.loginname + ' @' + normalUser2.loginname + ' @notexitstuser 你们好'; + var text = '@' + adminUser.loginname + ' @' + normalUser2.loginname + ' @notexitstuser 你们好'; at.sendMessageToMentionUsers(text, testTopic._id, normalUser._id, @@ -191,6 +192,19 @@ aldjf }); }); + it('should not send at msg to author', function (done) { + mm(message, 'sendAtMessage', function () { + throw new Error('should not call me'); + }); + + at.sendMessageToMentionUsers('@' + normalUser.loginname + ' hello', + testTopic._id, normalUser._id, + function (err) { + should.not.exist(err); + done(); + }); + }); + describe('mock message.sendAtMessage() error', function () { beforeEach(function () { mm(message, 'sendAtMessage', function () { diff --git a/test/support/support.js b/test/support/support.js index 01dc1ae..42a15c9 100644 --- a/test/support/support.js +++ b/test/support/support.js @@ -52,6 +52,7 @@ ep.all('user', 'user2', 'admin', function (user, user2, admin) { var adminObj = JSON.parse(JSON.stringify(admin)); adminObj.is_admin = true; + exports.adminUser = admin; exports.adminUserCookie = mockUser(adminObj); createTopic(user._id, ep.done('topic'));