Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge IRC kicks as kicks, and fall back to leaves #994

Merged
merged 4 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/994.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Kicks from one IRC user to another will now be shown as kicks on Matrix.
26 changes: 17 additions & 9 deletions spec/integ/kicking.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ describe("Kicking", function() {
id: "@" + config._server + "_bob:" + config.homeserver.domain
};

const ircUserKicker = {
nick: "KickerNick",
localpart: config._server + "_KickerNick",
id: "@" + config._server + "_KickerNick:" + config.homeserver.domain
};

beforeEach(test.coroutine(function*() {
yield test.beforeEach(env);

Expand Down Expand Up @@ -72,23 +78,25 @@ describe("Kicking", function() {
}));

describe("IRC users on IRC", function() {
it("should make the kickee leave the Matrix room", test.coroutine(function*() {
let kickPromise = new Promise(function(resolve, reject) {
let ircUserSdk = env.clientMock._client(ircUser.id);
ircUserSdk.leave.and.callFake(function(roomId) {
it("should make the kickee leave the Matrix room", async () => {
const kickReason = "They had to go, they knew too much";
const kickPromise = new Promise((resolve) => {
const ircUserSdk = env.clientMock._client(ircUserKicker.id);
ircUserSdk.kick.and.callFake(async (roomId, kickee, reason) => {
expect(roomId).toEqual(config._roomid);
expect(kickee).toEqual(ircUser.id);
expect(reason).toEqual(kickReason)
resolve();
return Promise.resolve();
});
});

// send the KICK command
let ircUserCli = yield env.ircMock._findClientAsync(
const ircUserCli = await env.ircMock._findClientAsync(
config._server, config._botnick
);
ircUserCli.emit("kick", config._chan, ircUser.nick, "KickerNick", "Reasons");
yield kickPromise;
}));
ircUserCli.emit("kick", config._chan, ircUser.nick, ircUserKicker.nick, kickReason);
await kickPromise;
});
});

describe("Matrix users on Matrix", function() {
Expand Down
23 changes: 17 additions & 6 deletions src/bridge/IrcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,19 +737,30 @@ export class IrcHandler {
// will NOT send a PART command. We equally cannot make a fake PART command and
// reuse the same code path as we want to force this to go through, regardless of
// whether incremental join/leave syncing is turned on.
const matrixUser = await this.ircBridge.getMatrixUser(kickee);
req.log.info("Mapped kickee nick %s to %s", kickee.nick, JSON.stringify(matrixUser));
const matrixUserKickee = await this.ircBridge.getMatrixUser(kickee);
const matrixUserKicker = await this.ircBridge.getMatrixUser(kicker);
req.log.info("Mapped kickee nick %s to %s", kickee.nick, JSON.stringify(matrixUserKickee));
const matrixRooms = await this.ircBridge.getStore().getMatrixRoomsForChannel(server, chan);
if (matrixRooms.length === 0) {
req.log.info("No mapped matrix rooms for IRC channel %s", chan);
return;
}
await Promise.all(matrixRooms.map(async (room) => {
await this.membershipQueue.leave(
room.getId(), matrixUser.getId(), req,
);
try {
await this.roomAccessSyncer.removePowerLevels(room.getId(), [matrixUser.getId()]);
await this.membershipQueue.leave(
room.getId(), matrixUserKickee.getId(), req, false, reason, matrixUserKicker.getId(),
);
}
catch (ex) {
const formattedReason = `Kicked by ${kicker.nick} ${reason ? ": " + reason : ""}`;
// We failed to show a real kick, so just leave.
await this.membershipQueue.leave(
room.getId(), matrixUserKickee.getId(), req, false, formattedReason,
);
// If this fails, we want to fail the operation.
}
try {
await this.roomAccessSyncer.removePowerLevels(room.getId(), [matrixUserKickee.getId()]);
}
catch (ex) {
// This is non-critical but annoying.
Expand Down