Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into release-v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Sep 25, 2020
2 parents 93b7dca + e9e1bbc commit 6243ab6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
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

0 comments on commit 6243ab6

Please sign in to comment.