Browse Source
Implement channel parting on the channel object
This patch allows the channel to part users from it. This provides the
basics for the future implementation of the PART command.
test/channel
Sheogorath
5 years ago
No known key found for this signature in database
GPG Key ID: 1F05CC3635CDDFFD
2 changed files with
29 additions and
0 deletions
-
src/channel.js
-
test/channel.js
|
|
@ -9,6 +9,17 @@ function Channel(name) { |
|
|
|
item.sendRaw(`:${user.nickname} JOIN ${channel.name}`) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
this.part = function(user) { |
|
|
|
let channel = this |
|
|
|
let userIndex = this.userlist.indexOf(user) |
|
|
|
if (userIndex >= 0) { |
|
|
|
this.userlist.forEach(function(item) { |
|
|
|
item.sendRaw(`:${user.nickname} PART ${channel.name}`) |
|
|
|
}) |
|
|
|
this.userlist.splice(index, 1) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = Channel |
|
|
@ -20,4 +20,22 @@ describe('Channel', function () { |
|
|
|
channel.join(mockedUser) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('#part(user)', 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"} |
|
|
|
mockedUser.sendRaw = function(data) { |
|
|
|
// we expect a PART message from our user to the channel (including us)
|
|
|
|
if (data.indexOf("PART") >= 0) { |
|
|
|
assert.equal(data, ":some_nick PART #testchan") |
|
|
|
done() |
|
|
|
} |
|
|
|
} |
|
|
|
// we can't part a channel without joining it first
|
|
|
|
channel.join(mockedUser) |
|
|
|
|
|
|
|
channel.part(mockedUser) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |