-
Notifications
You must be signed in to change notification settings - Fork 13k
feat: adds get state and state_id endpoints #36929
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
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 |
|---|---|---|
|
|
@@ -202,6 +202,56 @@ const ErrorResponseSchema = { | |
|
|
||
| const isErrorResponseProps = ajv.compile(ErrorResponseSchema); | ||
|
|
||
| const GetStateIdsParamsSchema = { | ||
| type: 'object', | ||
| properties: { | ||
| event_id: { | ||
| type: 'string', | ||
| }, | ||
| }, | ||
| required: ['event_id'], | ||
| }; | ||
|
|
||
| const isGetStateIdsParamsProps = ajv.compile(GetStateIdsParamsSchema); | ||
|
|
||
| const GetStateIdsResponseSchema = { | ||
| type: 'object', | ||
| properties: { | ||
| stateIds: { | ||
| type: 'array', | ||
| items: { | ||
| type: 'string', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const isGetStateIdsResponseProps = ajv.compile(GetStateIdsResponseSchema); | ||
| const GetStateParamsSchema = { | ||
| type: 'object', | ||
| properties: { | ||
| event_id: { | ||
| type: 'string', | ||
| }, | ||
| }, | ||
| }; | ||
| const isGetStateParamsProps = ajv.compile<{ | ||
| event_id: string | ||
| }>(GetStateParamsSchema); | ||
|
|
||
| const GetStateResponseSchema = { | ||
| type: 'object', | ||
| properties: { | ||
| state: { | ||
| type: 'object', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const isGetStateResponseProps = ajv.compile(GetStateResponseSchema); | ||
|
|
||
|
|
||
|
|
||
| export const getMatrixTransactionsRoutes = (services: HomeserverServices) => { | ||
| const { event, config } = services; | ||
|
|
||
|
|
@@ -253,6 +303,67 @@ export const getMatrixTransactionsRoutes = (services: HomeserverServices) => { | |
| }, | ||
| ) | ||
|
|
||
| // GET /_matrix/federation/v1/state_ids/{roomId} | ||
|
|
||
| .get( | ||
| '/v1/state_ids/:roomId', | ||
| { | ||
| params: isGetStateIdsParamsProps, | ||
| response: { | ||
| 200: isGetStateIdsResponseProps, | ||
| }, | ||
| }, | ||
| async (c) => { | ||
|
|
||
| const roomId = c.req.param('roomId'); | ||
| const eventId = c.req.query('event_id'); | ||
|
|
||
| if(!eventId) { | ||
| return { | ||
| body: { | ||
| errcode: 'M_NOT_FOUND', | ||
| error: 'Event not found', | ||
| }, | ||
| statusCode: 404, | ||
| } | ||
| } | ||
|
|
||
| const stateIds = await event.getStateIds(roomId, eventId); | ||
|
|
||
| return { | ||
| body: stateIds, | ||
| statusCode: 200, | ||
| }; | ||
|
Comment on lines
+333
to
+336
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Response body shape mismatch with declared schemas
Apply: - return {
- body: stateIds,
- statusCode: 200,
- };
+ return {
+ body: { stateIds },
+ statusCode: 200,
+ };- return {
- statusCode: 200,
- body: state,
- };
+ return {
+ statusCode: 200,
+ body: { state },
+ };Also applies to: 399-401 🤖 Prompt for AI Agents |
||
| }, | ||
| ) | ||
| .get( | ||
| '/v1/state/:roomId', | ||
| { | ||
| params: isGetStateParamsProps, | ||
| response: { | ||
| 200: isGetStateResponseProps, | ||
| }, | ||
| }, | ||
| async (c) => { | ||
| const roomId = c.req.param('roomId'); | ||
| const eventId = c.req.query('event_id'); | ||
|
|
||
| if(!eventId) { | ||
| return { | ||
| body: { | ||
| errcode: 'M_NOT_FOUND', | ||
| error: 'Event not found', | ||
| }, | ||
| statusCode: 404, | ||
| } | ||
| } | ||
| const state = await event.getState(roomId, eventId); | ||
| return { | ||
| statusCode: 200, | ||
| body: state, | ||
| }; | ||
| }, | ||
| ) | ||
| // GET /_matrix/federation/v1/event/{eventId} | ||
| .get( | ||
| '/v1/event/:eventId', | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use query validators (not params) for event_id
event_id is a query param; current code places its validator under params so it never runs. Move to options.query.
Apply:
And for state:
Also applies to: 387-394
🤖 Prompt for AI Agents