Skip to content

Commit 96c2c2b

Browse files
committed
register xmpp appservice
1 parent 052a969 commit 96c2c2b

4 files changed

Lines changed: 27 additions & 16 deletions

File tree

apps/meteor/ee/server/startup/federation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const startFederationService = async (): Promise<void> => {
115115
return;
116116
}
117117

118-
const joined = await FederationMatrixService.joinXMPPChatRoom(channel, user);
118+
const joined = await FederationMatrixService.joinAppServiceRoom(`_xmpp_${channel}`, user);
119119

120120
const lng = settings.get<string>('Language') || 'en';
121121
if (joined) {

ee/packages/federation-matrix/src/FederationMatrix.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,19 +1043,17 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS
10431043
);
10441044
}
10451045

1046-
async joinXMPPChatRoom(roomAlias: string, user: IUser): Promise<boolean> {
1046+
async joinAppServiceRoom(roomAlias: string, user: IUser): Promise<boolean> {
10471047
try {
10481048
if (isUserNativeFederated(user)) {
1049-
throw new Error('Federated users cannot join XMPP chat rooms');
1049+
throw new Error('Federated users cannot join App Service rooms');
10501050
}
10511051

1052-
await federationSDK.joinXMPPChatRoom(roomAlias, userIdSchema.parse(`@${user.username}:${this.serverName}`));
1053-
1054-
this.logger.info({ msg: 'User joined XMPP chat room successfully', username: user.username, roomAlias });
1052+
await federationSDK.joinAppServiceRoom(roomAlias, userIdSchema.parse(`@${user.username}:${this.serverName}`));
10551053

10561054
return true;
10571055
} catch (err) {
1058-
this.logger.error({ msg: 'Failed to join XMPP chat room', err, username: user.username, roomAlias });
1056+
this.logger.error({ msg: 'Failed to join App Service room', err, username: user.username, roomAlias });
10591057

10601058
return false;
10611059
}

ee/packages/federation-matrix/src/setup.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export async function configureFederationMatrixSettings(settings: {
6969
throw new Error('Invalid Federation domain');
7070
}
7171

72-
await federationSDK.setConfig({
72+
federationSDK.setConfig({
7373
instanceId,
7474
serverName,
7575
keyRefreshInterval: Number.parseInt(process.env.MATRIX_KEY_REFRESH_INTERVAL || '60', 10),
@@ -106,14 +106,27 @@ export async function configureFederationMatrixSettings(settings: {
106106
processPresence: processEDUPresence,
107107
processReceipt: processEDUReceipt,
108108
},
109-
...(xmppEnabled && {
110-
xmpp: {
111-
bridgeURL: xmppBridgeURL,
112-
hsToken: xmppBridgeHSToken,
113-
asToken: xmppBridgeASToken,
114-
},
115-
}),
116109
});
110+
111+
if (xmppEnabled) {
112+
await federationSDK.registerAppService({
113+
_id: 'xmpp',
114+
url: xmppBridgeURL,
115+
asToken: xmppBridgeASToken,
116+
hsToken: xmppBridgeHSToken,
117+
senderLocalpart: 'xmpp',
118+
namespaces: {
119+
users: [{ regex: '@_xmpp_.*', exclusive: true }],
120+
aliases: [{ regex: '#_xmpp_.*', exclusive: true }],
121+
rooms: [],
122+
},
123+
protocols: ['xmpp'],
124+
rateLimited: false,
125+
receiveEphemeral: true,
126+
});
127+
} else {
128+
await federationSDK.unregisterAppService('xmpp');
129+
}
117130
}
118131

119132
export async function setupFederationMatrix() {

packages/core-services/src/types/IFederationMatrixService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ export interface IFederationMatrixService {
3434
canUserAccessFederation(user: IUser): Promise<boolean>;
3535
notifyRoomRead(params: { room: IRoomNativeFederated; userId: string; threadId?: string }): Promise<void>;
3636
updateUserName(user: IUser): Promise<void>;
37-
joinXMPPChatRoom(roomAlias: string, user: IUser): Promise<boolean>;
37+
joinAppServiceRoom(roomAlias: string, user: IUser): Promise<boolean>;
3838
saveFederationMessage(event: { event: PduForType<'m.room.message'>; event_id: EventID }): Promise<void>;
3939
}

0 commit comments

Comments
 (0)