Skip to content

Commit 396d77f

Browse files
committed
feat: add state management DTOs and update profiles controller
1 parent 0c41fdf commit 396d77f

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

packages/federation-sdk/src/repositories/state.repository.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { StateMapKey } from '@hs/room';
1212
import type { PersistentEventBase } from '@hs/room';
1313

1414
export type StateStore = {
15+
_id: ObjectId;
1516
delta: {
1617
identifier: StateMapKey;
1718
eventId: string;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import {
1111
GetMissingEventsBodyDto,
1212
GetMissingEventsParamsDto,
1313
GetMissingEventsResponseDto,
14+
GetStateIdsParamsDto,
15+
GetStateIdsQueryDto,
16+
GetStateIdsResponseDto,
17+
GetStateParamsDto,
18+
GetStateQueryDto,
19+
GetStateResponseDto,
1420
MakeJoinParamsDto,
1521
MakeJoinQueryDto,
1622
MakeJoinResponseDto,
@@ -76,7 +82,7 @@ export const profilesPlugin = (app: Elysia) => {
7682

7783
const { ver } = query;
7884

79-
return profilesService.makeJoin(roomId, userId, ver ?? ['1']) as any;
85+
return profilesService.makeJoin(roomId, userId, ver ?? ['1']);
8086
},
8187
{
8288
params: MakeJoinParamsDto,

packages/homeserver/src/dtos/federation/profiles.dto.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,26 @@ export const MakeJoinQueryDto = t.Object({
7676
),
7777
});
7878

79+
const MembershipDto = t.Union([
80+
t.Literal('join'),
81+
t.Literal('leave'),
82+
t.Literal('invite'),
83+
t.Literal('ban'),
84+
t.Literal('knock'),
85+
]);
86+
7987
export const MakeJoinResponseDto = t.Object({
8088
room_version: t.String({ description: 'Room version' }),
8189
event: t.Object({
8290
content: t.Object({
83-
membership: t.Literal('join'),
91+
membership: MembershipDto,
8492
join_authorised_via_users_server: t.Optional(t.String()),
8593
}),
8694
room_id: RoomIdDto,
8795
sender: UsernameDto,
8896
state_key: UsernameDto,
8997
type: t.Literal('m.room.member'),
9098
origin_server_ts: TimestampDto,
91-
origin: ServerNameDto,
9299
depth: t.Optional(
93100
t.Number({ description: 'Depth of the event in the DAG' }),
94101
),
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { type Static, t } from 'elysia';
2+
import { RoomIdDto } from '../common/validation.dto';
3+
4+
export const GetStateIdsParamsDto = t.Object({
5+
roomId: RoomIdDto,
6+
});
7+
8+
export const GetStateIdsQueryDto = t.Object({
9+
event_id: t.String({ description: 'Event ID to get state at' }),
10+
});
11+
12+
export const GetStateIdsResponseDto = t.Object({
13+
pdu_ids: t.Array(t.String(), { description: 'List of state event IDs' }),
14+
auth_chain_ids: t.Array(t.String(), {
15+
description: 'List of auth chain event IDs',
16+
}),
17+
});
18+
19+
export type GetStateIdsParams = Static<typeof GetStateIdsParamsDto>;
20+
export type GetStateIdsQuery = Static<typeof GetStateIdsQueryDto>;
21+
export type GetStateIdsResponse = Static<typeof GetStateIdsResponseDto>;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { type Static, t } from 'elysia';
2+
import { RoomIdDto } from '../common/validation.dto';
3+
4+
export const GetStateParamsDto = t.Object({
5+
roomId: RoomIdDto,
6+
});
7+
8+
export const GetStateQueryDto = t.Object({
9+
event_id: t.String({ description: 'Event ID to get state at' }),
10+
});
11+
12+
export const GetStateResponseDto = t.Object({
13+
pdus: t.Array(t.Record(t.String(), t.Any()), {
14+
description: 'List of state event objects',
15+
}),
16+
auth_chain: t.Array(t.Record(t.String(), t.Any()), {
17+
description: 'List of auth chain event objects',
18+
}),
19+
});
20+
21+
export type GetStateParams = Static<typeof GetStateParamsDto>;
22+
export type GetStateQuery = Static<typeof GetStateQueryDto>;
23+
export type GetStateResponse = Static<typeof GetStateResponseDto>;

packages/homeserver/src/dtos/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export * from './common/validation.dto';
77
export * from './federation/invite.dto';
88
export * from './federation/profiles.dto';
99
export * from './federation/send-join.dto';
10+
export * from './federation/state-ids.dto';
11+
export * from './federation/state.dto';
1012
export * from './federation/transactions.dto';
1113
export * from './federation/versions.dto';
1214

0 commit comments

Comments
 (0)