-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathinvite.controller.ts
More file actions
76 lines (72 loc) · 2.01 KB
/
invite.controller.ts
File metadata and controls
76 lines (72 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { EventID, RoomID } from '@rocket.chat/federation-room';
import {
EventAuthorizationService,
InviteService,
NotAllowedError,
} from '@rocket.chat/federation-sdk';
import { isAuthenticatedMiddleware } from '@rocket.chat/homeserver/middlewares/isAuthenticated';
import { Elysia, t } from 'elysia';
import { container } from 'tsyringe';
import {
FederationErrorResponseDto,
ProcessInviteParamsDto,
ProcessInviteResponseDto,
RoomVersionDto,
} from '../../dtos';
export const invitePlugin = (app: Elysia) => {
const inviteService = container.resolve(InviteService);
const eventAuthService = container.resolve(EventAuthorizationService);
return app.use(isAuthenticatedMiddleware(eventAuthService)).put(
'/_matrix/federation/v2/invite/:roomId/:eventId',
async ({ body, set, params: { roomId, eventId }, authenticatedServer }) => {
if (!authenticatedServer) {
throw new Error('Missing authenticated server from request');
}
try {
return await inviteService.processInvite(
body.event,
roomId as RoomID,
eventId as EventID,
body.room_version,
authenticatedServer,
body.invite_room_state,
);
} catch (error) {
if (error instanceof NotAllowedError) {
set.status = 403;
return {
errcode: 'M_FORBIDDEN',
error:
'This server does not allow joining this type of room based on federation settings.',
};
}
set.status = 500;
return {
errcode: 'M_UNKNOWN',
error:
error instanceof Error
? error.message
: 'Internal server error while processing request',
};
}
},
{
params: ProcessInviteParamsDto,
body: t.Object({
event: t.Any(),
room_version: RoomVersionDto,
invite_room_state: t.Any(),
}),
response: {
200: ProcessInviteResponseDto,
403: FederationErrorResponseDto,
500: FederationErrorResponseDto,
},
detail: {
tags: ['Federation'],
summary: 'Process room invite',
description: 'Process an invite event from another Matrix server',
},
},
);
};