-
Notifications
You must be signed in to change notification settings - Fork 12
Improve Room 12 support. Use synapse capabilities endpoint. #866
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0d46ac4
Use capabilities endpoint to get synapse default room version
maheichyk 0710fb0
Update changeset
maheichyk fca7169
Update MatrixClientAdapter.test.ts
maheichyk e212acc
Make defaultRoomVersion required
maheichyk 0ad9dce
Delete DEFAULT_ROOM_VERSION config option
maheichyk bd007c4
Update changeset.
maheichyk 3f4b5c5
Merge branch 'main' into nic/fix/NEO-1601
maheichyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@nordeck/matrix-meetings-bot': patch | ||
| --- | ||
|
|
||
| Improve Matrix Room Version 12 support by using `/_matrix/client/v3/capabilities` endpoint to retrieve synapse room default version. The `DEFAULT_ROOM_VERSION` option is not needed and is deleted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
matrix-meetings-bot/src/client/MatrixClientAdapter.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * Copyright 2025 Nordeck IT + Consulting GmbH | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { MatrixClient } from 'matrix-bot-sdk'; | ||
| import { MatrixClientAdapter } from './MatrixClientAdapter'; | ||
|
|
||
| jest.mock('matrix-bot-sdk'); | ||
|
|
||
| describe('MatrixClientAdapter', () => { | ||
| beforeEach(() => { | ||
| jest | ||
| .spyOn(MatrixClient.prototype, 'doRequest') | ||
| .mockImplementation((method, endpoint) => { | ||
| const response = | ||
| endpoint === '/_matrix/client/v3/capabilities' | ||
| ? { | ||
| capabilities: { | ||
| 'm.room_versions': { | ||
| default: '12', | ||
| available: {}, | ||
| }, | ||
| 'm.change_password': { enabled: true }, | ||
| 'm.set_displayname': { enabled: true }, | ||
| 'm.set_avatar_url': { enabled: true }, | ||
| 'm.3pid_changes': { enabled: true }, | ||
| 'm.get_login_token': { enabled: false }, | ||
| 'm.profile_fields': { enabled: true }, | ||
| }, | ||
| } | ||
| : undefined; | ||
|
|
||
| return Promise.resolve(response); | ||
| }); | ||
| }); | ||
|
|
||
| it('should get synapse default room version via capabilities endpoint', async () => { | ||
| const matrixClient = new MatrixClient('https://example.com', 'token123'); | ||
| const matrixClientAdapter = new MatrixClientAdapter(matrixClient); | ||
|
|
||
| expect( | ||
| await matrixClientAdapter.getCapabilitiesDefaultRoomVersion(), | ||
| ).toEqual('12'); | ||
| expect(MatrixClient.prototype.doRequest).toHaveBeenCalledWith( | ||
| 'GET', | ||
| '/_matrix/client/v3/capabilities', | ||
| ); | ||
| expect(MatrixClient.prototype.doRequest).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should get and cache synapse default room version via capabilities endpoint', async () => { | ||
| jest.useFakeTimers(); | ||
|
|
||
| const matrixClient = new MatrixClient('https://example.com', 'token123'); | ||
| const matrixClientAdapter = new MatrixClientAdapter(matrixClient); | ||
|
|
||
| expect( | ||
| await matrixClientAdapter.getCapabilitiesDefaultRoomVersion(), | ||
| ).toEqual('12'); | ||
| expect(MatrixClient.prototype.doRequest).toHaveBeenCalledWith( | ||
| 'GET', | ||
| '/_matrix/client/v3/capabilities', | ||
| ); | ||
| expect(MatrixClient.prototype.doRequest).toHaveBeenCalledTimes(1); | ||
|
|
||
| expect( | ||
| await matrixClientAdapter.getCapabilitiesDefaultRoomVersion(), | ||
| ).toEqual('12'); | ||
| expect(MatrixClient.prototype.doRequest).toHaveBeenCalledTimes(1); | ||
|
|
||
| jest.advanceTimersByTime(7200000); // 2 hours | ||
|
|
||
| expect( | ||
| await matrixClientAdapter.getCapabilitiesDefaultRoomVersion(), | ||
| ).toEqual('12'); | ||
| expect(MatrixClient.prototype.doRequest).toHaveBeenCalledTimes(2); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright 2025 Nordeck IT + Consulting GmbH | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { Injectable } from '@nestjs/common'; | ||
| import { MatrixClient } from 'matrix-bot-sdk'; | ||
|
|
||
| // Follows what matrix bot sdk doing for versions: https://github.com/turt2live/matrix-bot-sdk/blob/ac53f0fb625911b87b3c1427661824b9a38d0514/src/MatrixClient.ts#L50 | ||
| const defaultRoomVersionCacheMs = 7200000; // 2 hours | ||
|
|
||
| @Injectable() | ||
| export class MatrixClientAdapter { | ||
| private cachedDefaultRoomVersion?: string; | ||
| private defaultRoomVersionLastFetched: number = 0; | ||
|
|
||
| constructor(private matrixClient: MatrixClient) {} | ||
|
|
||
| /** | ||
| * Retrieves synapse default room version using '/_matrix/client/v3/capabilities' endpoint. | ||
| * @returns {Promise<string>} Resolves to the synapse default room version | ||
| */ | ||
| public async getCapabilitiesDefaultRoomVersion(): Promise<string> { | ||
| let defaultRoomVersion: string; | ||
|
|
||
| if ( | ||
| !this.cachedDefaultRoomVersion || | ||
| Date.now() - this.defaultRoomVersionLastFetched >= | ||
| defaultRoomVersionCacheMs | ||
| ) { | ||
| const response = await this.matrixClient.doRequest( | ||
| 'GET', | ||
| '/_matrix/client/v3/capabilities', | ||
| ); | ||
| const responseDefaultRoomVersion = | ||
| response['capabilities']['m.room_versions']['default']; | ||
| defaultRoomVersion = responseDefaultRoomVersion; | ||
| this.cachedDefaultRoomVersion = responseDefaultRoomVersion; | ||
| this.defaultRoomVersionLastFetched = Date.now(); | ||
| } else { | ||
| defaultRoomVersion = this.cachedDefaultRoomVersion; | ||
| } | ||
|
|
||
| return defaultRoomVersion; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.