Skip to content

Commit b4689a9

Browse files
authored
fix: get_missing_events endpoint payload according to spec (#301)
1 parent 5cc3127 commit b4689a9

File tree

6 files changed

+150
-203
lines changed

6 files changed

+150
-203
lines changed

packages/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export * from './models/event.model';
7272

7373
// Procedures
7474
export { makeJoinEventBuilder } from './procedures/makeJoin';
75-
export { makeGetMissingEventsProcedure } from './procedures/getMissingEvents';
7675
export { getPublicKeyFromRemoteServer } from './procedures/getPublicKeyFromServer';
7776

7877
export { createLogger, logger } from './utils/logger';

packages/core/src/procedures/getMissingEvents.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

packages/federation-sdk/src/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ export class FederationSDK {
271271
}
272272

273273
getMissingEvents(
274-
...args: Parameters<typeof this.profilesService.getMissingEvents>
274+
...args: Parameters<typeof this.eventService.getMissingEvents>
275275
) {
276-
return this.profilesService.getMissingEvents(...args);
276+
return this.eventService.getMissingEvents(...args);
277277
}
278278

279279
eventAuth(...args: Parameters<typeof this.profilesService.eventAuth>) {

packages/federation-sdk/src/services/profiles.service.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { createLogger } from '@rocket.chat/federation-core';
21
import { ConfigService } from './config.service';
3-
import { EventService } from './event.service';
42

53
import {
64
EventID,
@@ -15,11 +13,8 @@ import { StateService } from './state.service';
1513

1614
@singleton()
1715
export class ProfilesService {
18-
private readonly logger = createLogger('ProfilesService');
19-
2016
constructor(
2117
private readonly configService: ConfigService,
22-
private readonly eventService: EventService,
2318
private readonly stateService: StateService,
2419
) {}
2520
async queryProfile(userId: string): Promise<{
@@ -114,22 +109,6 @@ export class ProfilesService {
114109
};
115110
}
116111

117-
async getMissingEvents(
118-
roomId: RoomID,
119-
earliestEvents: EventID[],
120-
latestEvents: EventID[],
121-
limit = 10,
122-
minDepth = 0,
123-
): Promise<{ events: Pdu[] }> {
124-
return this.eventService.getMissingEvents(
125-
roomId,
126-
earliestEvents,
127-
latestEvents,
128-
limit,
129-
minDepth,
130-
);
131-
}
132-
133112
async eventAuth(
134113
_roomId: RoomID,
135114
_eventId: EventID,

packages/homeserver/src/controllers/federation/profiles.controller.ts

Lines changed: 133 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
GetMissingEventsParamsDto,
1414
GetMissingEventsResponseDto,
1515
MakeJoinParamsDto,
16-
MakeJoinQueryDto,
1716
MakeJoinResponseDto,
1817
QueryKeysBodyDto,
1918
QueryKeysResponseDto,
@@ -22,143 +21,148 @@ import {
2221
} from '../../dtos';
2322

2423
export const profilesPlugin = (app: Elysia) => {
25-
return app
26-
.group('/_matrix', (app) =>
27-
app
28-
.use(isAuthenticatedMiddleware())
29-
.get(
30-
'/federation/v1/query/profile',
31-
({ query: { user_id } }) =>
32-
federationSDK.queryProfile(user_id as UserID),
33-
{
34-
query: QueryProfileQueryDto,
35-
response: {
36-
200: QueryProfileResponseDto,
24+
return (
25+
app
26+
.group('/_matrix', (app) =>
27+
app
28+
.use(isAuthenticatedMiddleware())
29+
.get(
30+
'/federation/v1/query/profile',
31+
({ query: { user_id } }) =>
32+
federationSDK.queryProfile(user_id as UserID),
33+
{
34+
query: QueryProfileQueryDto,
35+
response: {
36+
200: QueryProfileResponseDto,
37+
},
38+
detail: {
39+
tags: ['Federation'],
40+
summary: 'Query profile',
41+
description: "Query a user's profile",
42+
},
3743
},
38-
detail: {
39-
tags: ['Federation'],
40-
summary: 'Query profile',
41-
description: "Query a user's profile",
44+
)
45+
.post(
46+
'/federation/v1/user/keys/query',
47+
async ({ set }) => {
48+
set.status = 501;
49+
return {
50+
errcode: 'M_UNRECOGNIZED',
51+
error: 'E2EE is not implemented yet',
52+
};
4253
},
43-
},
44-
)
45-
.post(
46-
'/federation/v1/user/keys/query',
47-
async ({ set }) => {
48-
set.status = 501;
49-
return {
50-
errcode: 'M_UNRECOGNIZED',
51-
error: 'E2EE is not implemented yet',
52-
};
53-
},
54-
{
55-
body: QueryKeysBodyDto,
56-
response: {
57-
200: QueryKeysResponseDto,
58-
501: t.Object({
59-
errcode: t.String(),
60-
error: t.String(),
61-
}),
54+
{
55+
body: QueryKeysBodyDto,
56+
response: {
57+
200: QueryKeysResponseDto,
58+
501: t.Object({
59+
errcode: t.String(),
60+
error: t.String(),
61+
}),
62+
},
63+
detail: {
64+
tags: ['Federation'],
65+
summary: 'Query keys',
66+
description:
67+
"Query a user's device keys (E2EE not implemented)",
68+
},
6269
},
63-
detail: {
64-
tags: ['Federation'],
65-
summary: 'Query keys',
66-
description: "Query a user's device keys (E2EE not implemented)",
67-
},
68-
},
69-
)
70-
.get(
71-
'/federation/v1/user/devices/:userId',
72-
async ({ set }) => {
73-
set.status = 501;
74-
return {
75-
errcode: 'M_UNRECOGNIZED',
76-
error: 'E2EE is not implemented yet',
77-
};
78-
},
79-
{
80-
params: GetDevicesParamsDto,
81-
response: {
82-
200: GetDevicesResponseDto,
83-
501: t.Object({
84-
errcode: t.String(),
85-
error: t.String(),
86-
}),
70+
)
71+
.get(
72+
'/federation/v1/user/devices/:userId',
73+
async ({ set }) => {
74+
set.status = 501;
75+
return {
76+
errcode: 'M_UNRECOGNIZED',
77+
error: 'E2EE is not implemented yet',
78+
};
8779
},
88-
detail: {
89-
tags: ['Federation'],
90-
summary: 'Get devices',
91-
description: "Get a user's devices (E2EE not implemented)",
80+
{
81+
params: GetDevicesParamsDto,
82+
response: {
83+
200: GetDevicesResponseDto,
84+
501: t.Object({
85+
errcode: t.String(),
86+
error: t.String(),
87+
}),
88+
},
89+
detail: {
90+
tags: ['Federation'],
91+
summary: 'Get devices',
92+
description: "Get a user's devices (E2EE not implemented)",
93+
},
9294
},
93-
},
94-
),
95-
)
96-
.use(canAccessResourceMiddleware('room'))
97-
.get(
98-
'/_matrix/federation/v1/make_join/:roomId/:userId',
99-
async ({ params, query: _query }) => {
100-
const { roomId, userId } = params;
95+
),
96+
)
97+
.use(canAccessResourceMiddleware('room'))
98+
.get(
99+
'/_matrix/federation/v1/make_join/:roomId/:userId',
100+
async ({ params, query: _query }) => {
101+
const { roomId, userId } = params;
101102

102-
// const { ver } = query;
103+
// const { ver } = query;
103104

104-
return federationSDK.makeJoin(roomId as RoomID, userId as UserID, [
105-
'10',
106-
]);
107-
},
108-
{
109-
params: MakeJoinParamsDto,
110-
query: t.Any(),
111-
response: {
112-
200: MakeJoinResponseDto,
113-
400: ErrorResponseDto,
114-
},
115-
detail: {
116-
tags: ['Federation'],
117-
summary: 'Make join',
118-
description: 'Make a join event',
119-
},
120-
},
121-
)
122-
.post(
123-
'/_matrix/federation/v1/get_missing_events/:roomId',
124-
async ({ params, body }) =>
125-
federationSDK.getMissingEvents(
126-
params.roomId as RoomID,
127-
body.earliest_events as EventID[],
128-
body.latest_events as EventID[],
129-
body.limit,
130-
body.min_depth,
131-
),
132-
{
133-
params: GetMissingEventsParamsDto,
134-
body: GetMissingEventsBodyDto,
135-
response: {
136-
200: GetMissingEventsResponseDto,
105+
return federationSDK.makeJoin(roomId as RoomID, userId as UserID, [
106+
'10',
107+
]);
137108
},
138-
detail: {
139-
tags: ['Federation'],
140-
summary: 'Get missing events',
141-
description: 'Get missing events for a room',
109+
{
110+
params: MakeJoinParamsDto,
111+
query: t.Any(),
112+
response: {
113+
200: MakeJoinResponseDto,
114+
400: ErrorResponseDto,
115+
},
116+
detail: {
117+
tags: ['Federation'],
118+
summary: 'Make join',
119+
description: 'Make a join event',
120+
},
142121
},
143-
},
144-
)
145-
.get(
146-
'/_matrix/federation/v1/event_auth/:roomId/:eventId',
147-
({ params }) =>
148-
federationSDK.eventAuth(
149-
params.roomId as RoomID,
150-
params.eventId as EventID,
151-
),
152-
{
153-
params: EventAuthParamsDto,
154-
response: {
155-
200: EventAuthResponseDto,
122+
)
123+
124+
// https://spec.matrix.org/v1.16/server-server-api/#post_matrixfederationv1get_missing_eventsroomid
125+
.post(
126+
'/_matrix/federation/v1/get_missing_events/:roomId',
127+
async ({ params, body }) =>
128+
federationSDK.getMissingEvents(
129+
params.roomId as RoomID,
130+
body.earliest_events as EventID[],
131+
body.latest_events as EventID[],
132+
body.limit || 10,
133+
body.min_depth || 0,
134+
),
135+
{
136+
params: GetMissingEventsParamsDto,
137+
body: GetMissingEventsBodyDto,
138+
response: {
139+
200: GetMissingEventsResponseDto,
140+
},
141+
detail: {
142+
tags: ['Federation'],
143+
summary: 'Get missing events',
144+
description: 'Get missing events for a room',
145+
},
156146
},
157-
detail: {
158-
tags: ['Federation'],
159-
summary: 'Event auth',
160-
description: 'Get event auth for a room',
147+
)
148+
.get(
149+
'/_matrix/federation/v1/event_auth/:roomId/:eventId',
150+
({ params }) =>
151+
federationSDK.eventAuth(
152+
params.roomId as RoomID,
153+
params.eventId as EventID,
154+
),
155+
{
156+
params: EventAuthParamsDto,
157+
response: {
158+
200: EventAuthResponseDto,
159+
},
160+
detail: {
161+
tags: ['Federation'],
162+
summary: 'Event auth',
163+
description: 'Get event auth for a room',
164+
},
161165
},
162-
},
163-
);
166+
)
167+
);
164168
};

0 commit comments

Comments
 (0)