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

Incorporate appservice bridge types #1101

Merged
merged 24 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ WORKDIR /build
RUN apt-get update && apt-get install -y git python3 libicu-dev build-essential

COPY src/ /build/src/
COPY types/ /build/types/
COPY .eslintrc *json /build/

RUN npm ci
Expand Down
1 change: 1 addition & 0 deletions changelog.d/1101.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use types from `matrix-appservice-bridge` rather than local definitions.
175 changes: 71 additions & 104 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"irc": "matrix-org/node-irc#9028c2197c216dd8e6fc2cb3cc07ce2d6bf741a7",
"js-yaml": "^3.2.7",
"logform": "^2.1.2",
"matrix-appservice": "^0.4.1",
"matrix-appservice-bridge": "^1.14.0-rc2",
"matrix-appservice": "^0.5.0",
"matrix-appservice-bridge": "2.0.0-rc1",
"matrix-lastactive": "^0.1.5",
"nedb": "^1.1.2",
"nopt": "^3.0.1",
Expand All @@ -51,7 +51,7 @@
},
"devDependencies": {
"@types/bluebird": "^3.5.27",
"@types/express": "^4.17.2",
"@types/express": "^4.17.7",
"@types/extend": "^3.0.1",
"@types/he": "^1.1.0",
"@types/nedb": "^1.8.9",
Expand Down
12 changes: 6 additions & 6 deletions spec/integ/dynamic-channels.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("Dynamic channels", function() {
return Promise.resolve({});
});

env.mockAppService._queryAlias(tAlias).done(function() {
env.mockAppService._queryAlias(tAlias).then(function() {
if (joinedIrcChannel) {
done();
}
Expand Down Expand Up @@ -112,7 +112,7 @@ describe("Dynamic channels", function() {
return Promise.resolve({});
});

env.mockAppService._queryAlias(tAlias).done(function() {
env.mockAppService._queryAlias(tAlias).then(function() {
expect(joinedIrcChannel).toBe(true, "Failed to join irc channel");
done();
}, function(e) {
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("Dynamic channels", function() {

env.mockAppService._queryAlias(tAlias).then(function() {
return env.mockAppService._queryAlias(tCapsAlias);
}).done(function() {
}).then(function() {
expect(madeAlias).toBe(true, "Failed to create alias");
done();
});
Expand Down Expand Up @@ -204,7 +204,7 @@ describe("Dynamic channels", function() {
return Promise.resolve({});
});

env.mockAppService._queryAlias(tAlias).done(function() {
env.mockAppService._queryAlias(tAlias).then(function() {
expect(joinedIrcChannel).toBe(true, "Failed to join irc channel");
done();
}, function(e) {
Expand Down Expand Up @@ -280,7 +280,7 @@ describe("Dynamic channels (federation disabled)", function() {
return Promise.resolve({});
});

env.mockAppService._queryAlias(tAlias).done(function() {
env.mockAppService._queryAlias(tAlias).then(function() {
expect(joinedIrcChannel).toBe(true, "Failed to join irc channel");
done();
}, function(e) {
Expand Down Expand Up @@ -352,7 +352,7 @@ describe("Dynamic channels (disabled)", function() {
return Promise.resolve({});
});

env.mockAppService._queryAlias(tAlias).done(function() {
env.mockAppService._queryAlias(tAlias).then(function() {
expect(joinedIrcChannel).toBe(false, "Joined channel by alias");
done();
});
Expand Down
6 changes: 2 additions & 4 deletions spec/integ/hs-queries.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ describe("Homeserver user queries", function() {
returnUserId: testUserId
});

env.mockAppService._queryUser(testUserId).done(function(res) {
done();
});
env.mockAppService._queryUser(testUserId).then(done);
});
});

Expand Down Expand Up @@ -109,7 +107,7 @@ describe("Homeserver alias queries", function() {
}
});

env.mockAppService._queryAlias(testAlias).done(function() {
env.mockAppService._queryAlias(testAlias).then(function() {
expect(botJoined).toBe(true, "Bot didn't join " + testChannel);
done();
}, function(err) {
Expand Down
2 changes: 1 addition & 1 deletion spec/integ/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("Initialisation", function() {
env.ircMock._whenClient(roomMapping.server, ircNick, "connect",
function(client, cb) {
// after the connect callback, modify their nick and emit an event.
client._invokeCallback(cb).done(function() {
client._invokeCallback(cb).then(function() {
process.nextTick(function() {
client.nick = assignedNick;
client.emit("nick", ircNick, assignedNick);
Expand Down
4 changes: 2 additions & 2 deletions spec/integ/invite-rooms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("Invite-only rooms", function() {
room_id: adminRoomId,
type: "m.room.member"
});
}).done(function() {
}).then(function() {
expect(joinRoomCount).toEqual(2, "Failed to join admin room again");
done();
}, function(err) {
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("Invite-only rooms", function() {
});

let leftRoom = false;
sdk.leave.and.callFake(function(roomId) {
sdk.kick.and.callFake(function(roomId) {
expect(roomId).toEqual(roomMapping.roomId);
leftRoom = true;
return Promise.resolve({});
Expand Down
4 changes: 2 additions & 2 deletions spec/integ/irc-client-cycling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe("IRC client cycling", function() {
room_id: roomMapping.roomId,
type: "m.room.message"
});
}).done(function() {
}).then(function() {
// everyone should have connected/said something
let i;
for (i = 0; i < testUsers.length; i++) {
Expand Down Expand Up @@ -165,7 +165,7 @@ describe("IRC client cycling", function() {
room_id: roomMapping.roomId,
type: "m.room.message"
});
}).done(function() {
}).then(function() {
// the first guy should have 2 says, 2 connects and 1 disconnect.
// We're mainly interested in that there were 2 connect calls. If
// there is just 1, it indicates it used a cached copy.
Expand Down
51 changes: 26 additions & 25 deletions spec/integ/irc-connections.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ describe("IRC connections", function() {
roomMapping.server, roomMapping.botNick, roomMapping.channel
);

// we're not interested in the joins, so autojoin them.
env.ircMock._autoJoinChannels(
roomMapping.server, testUser.nick, roomMapping.channel
);

// do the init
yield test.initEnv(env, config);
}));
Expand Down Expand Up @@ -95,7 +90,7 @@ describe("IRC connections", function() {
user_id: testUser.id,
room_id: roomMapping.roomId,
type: "m.room.message"
}).done(function() {
}).then(function() {
expect(gotConnectCall).toBe(
true, nickForDisplayName + " failed to connect to IRC."
);
Expand Down Expand Up @@ -154,7 +149,7 @@ describe("IRC connections", function() {
user_id: testUser.id,
room_id: roomMapping.roomId,
type: "m.room.message"
}).done(function() {
}).then(function() {
expect(gotConnectCall).toBe(
true, nickForDisplayName + " failed to connect to IRC."
);
Expand Down Expand Up @@ -216,7 +211,7 @@ describe("IRC connections", function() {
// user error)
env.ircMock._findClientAsync(
roomMapping.server, roomMapping.botNick
).done(function(client) {
).then(function(client) {
client.emit(
"message", assignedNick, roomMapping.channel, "some text"
);
Expand All @@ -233,6 +228,10 @@ describe("IRC connections", function() {
"to be sent to IRC", async function() {
let connectCount = 0;

env.ircMock._autoJoinChannels(
roomMapping.server, testUser.nick, roomMapping.channel
);

env.ircMock._whenClient(roomMapping.server, testUser.nick, "connect", (client, cb) => {
connectCount += 1;
// add an artificially long delay to make sure it isn't connecting
Expand Down Expand Up @@ -349,12 +348,12 @@ describe("IRC connections", function() {
room_id: roomMapping.roomId,
type: "m.room.message"
});
}).done(function() {
}).then(function() {
// send an echo of the 3rd message: it shouldn't pass it through
// because it is a virtual user!
env.ircMock._findClientAsync(
roomMapping.server, roomMapping.botNick
).done(function(client) {
).then(function(client) {
client.emit(
"message", users[0].assignedNick, roomMapping.channel,
"3rd message"
Expand Down Expand Up @@ -422,7 +421,7 @@ describe("IRC connections", function() {
room_id: roomMapping.roomId,
type: "m.room.message"
});
}).done(function() {
}).then(function() {
expect(usr1.username).toBeDefined();
expect(usr2.username).toBeDefined();
expect(usr1.username).not.toEqual(usr2.username);
Expand Down Expand Up @@ -486,7 +485,7 @@ describe("IRC connections", function() {
room_id: roomMapping.roomId,
type: "m.room.message"
});
Promise.all([p1, p2]).done(function() {
Promise.all([p1, p2]).then(function() {
expect(usr1.username).toBeDefined();
expect(usr2.username).toBeDefined();
expect(usr1.username).not.toEqual(usr2.username);
Expand All @@ -495,33 +494,35 @@ describe("IRC connections", function() {
});

it("should gracefully fail if it fails to join a channel when sending a message",
function(done) {
async function() {
env.ircMock._autoConnectNetworks(
roomMapping.server, testUser.nick, roomMapping.server
);

let errorEmitted = false;
env.ircMock._whenClient(roomMapping.server, testUser.nick, "join",
function(client, cb) {
(client) => {
errorEmitted = true;
client.emit("error", {
command: "err_bannedfromchan",
args: [roomMapping.channel]
});
});

env.mockAppService._trigger("type:m.room.message", {
content: {
body: "A message",
msgtype: "m.text"
},
user_id: testUser.id,
room_id: roomMapping.roomId,
type: "m.room.message"
}).catch(function(e) {
try {
await env.mockAppService._trigger("type:m.room.message", {
content: {
body: "A message",
msgtype: "m.text"
},
user_id: testUser.id,
room_id: roomMapping.roomId,
type: "m.room.message"
});
throw Error('Expected exception');
} catch (ex) {
expect(errorEmitted).toBe(true);
done();
});
}
});

it("should not bridge matrix users who are excluded", async function() {
Expand Down
8 changes: 4 additions & 4 deletions spec/integ/irc-modes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("IRC-to-Matrix mode bridging", function() {
return Promise.resolve();
});

env.ircMock._findClientAsync(roomMapping.server, roomMapping.botNick).done(
env.ircMock._findClientAsync(roomMapping.server, roomMapping.botNick).then(
function(client) {
client.emit("+mode", roomMapping.channel, "anIrcUser", "k");
});
Expand All @@ -78,7 +78,7 @@ describe("IRC-to-Matrix mode bridging", function() {
return Promise.resolve();
});

env.ircMock._findClientAsync(roomMapping.server, roomMapping.botNick).done(
env.ircMock._findClientAsync(roomMapping.server, roomMapping.botNick).then(
function(client) {
client.emit("+mode", roomMapping.channel, "anIrcUser", "i");
});
Expand All @@ -97,7 +97,7 @@ describe("IRC-to-Matrix mode bridging", function() {
return Promise.resolve();
});

env.ircMock._findClientAsync(roomMapping.server, roomMapping.botNick).done(
env.ircMock._findClientAsync(roomMapping.server, roomMapping.botNick).then(
function(client) {
client.emit("-mode", roomMapping.channel, "anIrcUser", "i");
});
Expand All @@ -116,7 +116,7 @@ describe("IRC-to-Matrix mode bridging", function() {
return Promise.resolve();
});

env.ircMock._findClientAsync(roomMapping.server, roomMapping.botNick).done(
env.ircMock._findClientAsync(roomMapping.server, roomMapping.botNick).then(
function(client) {
client.emit("-mode", roomMapping.channel, "anIrcUser", "k");
});
Expand Down
Loading