Browse Source
Add sendMsg function to channel class
This function implements sending messages to all users in a channel
while sending the channel name as target to the user's socket.
feature/sendChannelMsg
Sheogorath
6 years ago
No known key found for this signature in database
GPG Key ID: 1F05CC3635CDDFFD
2 changed files with
24 additions and
0 deletions
-
src/channel.js
-
test/channel.js
|
@ -20,6 +20,13 @@ function Channel(name) { |
|
|
this.userlist.splice(index, 1) |
|
|
this.userlist.splice(index, 1) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.sendMsg = function(from, message) { |
|
|
|
|
|
const channel = this |
|
|
|
|
|
this.userlist.forEach(function(item) { |
|
|
|
|
|
item.sendMsg(from, message, channel.name) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
module.exports = Channel |
|
|
module.exports = Channel |
|
@ -38,4 +38,21 @@ describe('Channel', function () { |
|
|
channel.part(mockedUser) |
|
|
channel.part(mockedUser) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('#sendMsg(from, message)', function () { |
|
|
|
|
|
it("should remove a user from a channel and send a PART command to the user", function (done) { |
|
|
|
|
|
const channel = new Channel("#testchan") |
|
|
|
|
|
let mockedUser = {nickname: "some_nick", sendRaw: function() {}} |
|
|
|
|
|
mockedUser.sendMsg = function(from, message, to) { |
|
|
|
|
|
assert.equal(from, mockedUser) |
|
|
|
|
|
assert.equal(message, "test message") |
|
|
|
|
|
assert.equal(to, "#testchan") |
|
|
|
|
|
done() |
|
|
|
|
|
} |
|
|
|
|
|
// we can't part a channel without joining it first
|
|
|
|
|
|
channel.join(mockedUser) |
|
|
|
|
|
|
|
|
|
|
|
channel.sendMsg(mockedUser, "test message") |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |