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

Use actual homeserver URL for the bridge bot #233

Merged
merged 4 commits into from
Sep 25, 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/233.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure that the bridge bot uses the real homeserver URL when encryption is enabled
17 changes: 14 additions & 3 deletions src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ export class Bridge {
}

this.clientFactory = this.opts.clientFactory || new ClientFactory({
url: this.opts.bridgeEncryption?.homeserverUrl || this.opts.homeserverUrl,
url: this.opts.homeserverUrl,
token: asToken,
appServiceUserId: this.botUserId,
clientSchedulerBuilder: function() {
Expand Down Expand Up @@ -983,7 +983,14 @@ export class Bridge {
throw Error('Cannot call getIntent before calling .run()');
}
return this.botIntent;
} else if (userId === this.botUserId) {
if (!this.botIntent) {
// This will be defined when .run is called.
throw Error('Cannot call getIntent before calling .run()');
}
return this.botIntent;
}

if (this.opts.escapeUserIds === undefined || this.opts.escapeUserIds) {
userId = new MatrixUser(userId).getId(); // Escape the ID
}
Expand All @@ -995,7 +1002,12 @@ export class Bridge {
return existingIntent.intent;
}

const client = this.clientFactory.getClientAs(userId, request, !!this.opts.bridgeEncryption);
const client = this.clientFactory.getClientAs(
userId,
request,
this.opts.bridgeEncryption?.homeserverUrl,
!!this.opts.bridgeEncryption,
);
const clientIntentOpts: IntentOpts = {
backingStore: this.intentBackingStore,
...this.opts.intentOptions?.clients,
Expand All @@ -1009,7 +1021,6 @@ export class Bridge {
ensureClientSyncingCallback: async () => {
return this.eeEventBroker?.startSyncingUser(userId!);
},
homeserverUrl: encryptionOpts.homeserverUrl,
};
}
const intent = new Intent(client, this.botClient, clientIntentOpts);
Expand Down
4 changes: 2 additions & 2 deletions src/components/client-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class ClientFactory {
* resolved.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public getClientAs(userId?: string, request?: any, usingE2E = false) {
public getClientAs(userId?: string, request?: any, urlOverride?: string, usingE2E = false) {
const reqId = request ? request.getId() : "-";
const userIdKey = userId || "bot";

Expand All @@ -144,7 +144,7 @@ export class ClientFactory {
queryParams.access_token = this.token;
const clientOpts = {
accessToken: this.token,
baseUrl: this.url,
baseUrl: urlOverride || this.url,
userId: userId || this.botUserId, // NB: no clobber so we don't set ?user_id=BOT
queryParams: queryParams,
scheduler: this.clientSchedulerBuilder ? this.clientSchedulerBuilder() : undefined,
Expand Down
2 changes: 0 additions & 2 deletions src/components/intent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export interface IntentOpts {
sessionPromise: Promise<ClientEncryptionSession|null>;
sessionCreatedCallback: (session: ClientEncryptionSession) => Promise<void>;
ensureClientSyncingCallback: () => Promise<void>;
homeserverUrl: string;
};
}

Expand Down Expand Up @@ -118,7 +117,6 @@ export class Intent {
sessionPromise: Promise<ClientEncryptionSession|null>;
sessionCreatedCallback: (session: ClientEncryptionSession) => Promise<void>;
ensureClientSyncingCallback: () => Promise<void>;
homeserverUrl: string;
};
private readyPromise?: Promise<unknown>;

Expand Down