Skip to content

Commit 60a8686

Browse files
techsmythhero101
andauthored
Admin joining (#43)
* updated to work with new DTOs + event types * updated dtos + events * add admin to room if not a member, and then wait for invitation to accept and/or room to sync * tidy up * version bump * added a small explainer * reverted default account * version bump * ensure can delete message also by being part of room for admin user --------- Co-authored-by: Svetoslav <[email protected]>
1 parent 7278eb8 commit 60a8686

23 files changed

+327
-181
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"editor.defaultFormatter": "esbenp.prettier-vscode",
33
"editor.codeActionsOnSave": {
4-
"source.fixAll.eslint": true
4+
"source.fixAll.eslint": "explicit"
55
},
66
"files.eol": "\n"
77
}

lib/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alkemio/matrix-adapter-lib",
3-
"version": "0.3.6",
3+
"version": "0.4.1",
44
"description": "Library for interacting with Alkemio Matrix Adapter service",
55
"author": "Alkemio Foundation",
66
"private": false,

lib/src/dto/index.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ export * from './remove.room.payload';
2929
export * from './remove.room.response.payload';
3030
export * from './room.members.payload';
3131
export * from './room.members.response.payload';
32-
export * from './room.join.rule.payload';
33-
export * from './room.join.rule.response.payload';
34-
export * from './update.rooms.guest.access.payload';
35-
export * from './update.rooms.guest.access.response.payload';
32+
export * from './update.room.state.payload';
33+
export * from './update.room.state.payload';
3634
export * from './send.message.to.user.payload';
3735
export * from './send.message.to.user.response.payload';
3836
export * from './register.new.user.payload';

lib/src/dto/room.details.payload.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import { BaseMatrixAdapterEventPayload } from './base.event.payload';
33

44
export interface RoomDetailsPayload extends BaseMatrixAdapterEventPayload {
55
roomID: string;
6+
withState?: boolean;
67
}

lib/src/dto/room.join.rule.payload.ts

-6
This file was deleted.

lib/src/dto/room.join.rule.response.payload.ts

-6
This file was deleted.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
import { BaseMatrixAdapterEventPayload } from './base.event.payload';
3+
4+
export interface UpdateRoomStatePayload extends BaseMatrixAdapterEventPayload {
5+
roomID: string;
6+
7+
historyWorldVisibile?: boolean;
8+
allowJoining?: boolean;
9+
}

lib/src/dto/update.rooms.guest.access.payload.ts

-7
This file was deleted.

lib/src/dto/update.rooms.guest.access.response.payload.ts

-6
This file was deleted.

lib/src/matrix.adapter.event.type.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export enum MatrixAdapterEventType {
22
ROOM_DETAILS = 'roomDetails',
3-
ROOM_JOIN_RULE = 'roomJoinRule',
43
ROOM_MEMBERS = 'roomMembers',
54
ROOM_SEND_MESSAGE = 'roomSendMessage',
65
ROOM_SEND_MESSAGE_REPLY = 'roomSendMessageReply',
@@ -19,7 +18,7 @@ export enum MatrixAdapterEventType {
1918
ADD_USER_TO_ROOMS = 'addUserToRooms',
2019
ADD_USER_TO_ROOM = 'addUserToRoom',
2120
REMOVE_ROOM = 'removeRoom',
22-
UPDATE_ROOMS_GUEST_ACCESS = 'updateRoomsGuestAccess',
21+
UPDATE_ROOM_STATE = 'updateRoomState',
2322
SEND_MESSAGE_TO_USER = 'sendMessageToUser',
2423
REGISTER_NEW_USER = 'registerNewUser',
2524
}

lib/src/types/room.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ export class RoomResult {
99

1010
// The communication IDs of the room members
1111
members!: string[];
12+
13+
joinRule?: string;
14+
15+
historyVisibility?: string;
1216
}

package-lock.json

-6
This file was deleted.

service/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,12 @@ Alkemio Matrix Adapter service.
3232
Execute the following command from the workspace root:
3333

3434
`docker build -t alkemio/matrix-adapter:v0.2.0 .`
35+
36+
## Explainer
37+
38+
The way syncing works with Matrix SDK client is that you see the rooms in the MatrixClient that you are a member of.
39+
40+
For the way we use it this can mean that the admin account can potentially have a lot of rooms that it is a member of, and hence take a long time to sync.
41+
42+
To address this, an admin account is only added as a member at the moment that it needs to read the room. This does mean the sync time will increase over time, but it
43+
is then trivial to go to a new admin account and have that gradually join the rooms that are needed.

service/package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "alkemio-matrix-adapter",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "Alkemio Matrix Adapter service",
55
"author": "Alkemio Foundation",
66
"private": false,
@@ -34,7 +34,7 @@
3434
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config src/config/typeorm.cli.config.ts"
3535
},
3636
"dependencies": {
37-
"@alkemio/matrix-adapter-lib": "^0.3.6",
37+
"@alkemio/matrix-adapter-lib": "^0.4.1",
3838
"@nestjs/axios": "^2.0.0",
3939
"@nestjs/common": "^9.4.0",
4040
"@nestjs/config": "^2.3.1",

service/src/app.controller.ts

+8-47
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ import { LogContext } from './common/enums';
1111
import {
1212
MatrixAdapterEventType,
1313
RoomDetailsResponsePayload,
14-
RoomJoinRulePayload,
15-
RoomJoinRuleResponsePayload,
1614
RoomMembersPayload,
1715
RoomMembersResponsePayload,
18-
UpdateRoomsGuestAccessPayload,
19-
UpdateRoomsGuestAccessResponsePayload,
16+
UpdateRoomStatePayload,
2017
} from '@alkemio/matrix-adapter-lib';
2118
import { RoomDetailsPayload } from '@alkemio/matrix-adapter-lib';
2219
import { CommunicationAdapter } from './services/communication-adapter/communication.adapter';
@@ -344,13 +341,13 @@ export class AppController {
344341
}
345342
}
346343

347-
@MessagePattern({ cmd: MatrixAdapterEventType.ROOM_JOIN_RULE })
348-
async roomJoinRule(
349-
@Payload() data: RoomJoinRulePayload,
344+
@MessagePattern({ cmd: MatrixAdapterEventType.UPDATE_ROOM_STATE })
345+
async updateRoomState(
346+
@Payload() data: UpdateRoomStatePayload,
350347
@Ctx() context: RmqContext
351-
): Promise<RoomJoinRuleResponsePayload> {
348+
): Promise<RoomDetailsResponsePayload> {
352349
this.logger.verbose?.(
353-
`${MatrixAdapterEventType.ROOM_JOIN_RULE} - payload: ${JSON.stringify(
350+
`${MatrixAdapterEventType.UPDATE_ROOM_STATE} - payload: ${JSON.stringify(
354351
data
355352
)}`,
356353
LogContext.EVENTS
@@ -359,46 +356,10 @@ export class AppController {
359356
const originalMsg = context.getMessage();
360357

361358
try {
362-
const rule = await this.communicationAdapter.getRoomJoinRule(data.roomID);
363-
channel.ack(originalMsg);
364-
const response: RoomJoinRuleResponsePayload = {
365-
rule: rule,
366-
};
367-
368-
return response;
369-
} catch (error) {
370-
const errorMessage = `Error when getting join rule on room: ${error}`;
371-
this.logger.error(errorMessage, LogContext.COMMUNICATION);
372-
channel.ack(originalMsg);
373-
throw new RpcException(errorMessage);
374-
}
375-
}
376-
377-
@MessagePattern({ cmd: MatrixAdapterEventType.UPDATE_ROOMS_GUEST_ACCESS })
378-
async updateRoomsGuestAccess(
379-
@Payload() data: UpdateRoomsGuestAccessPayload,
380-
@Ctx() context: RmqContext
381-
): Promise<UpdateRoomsGuestAccessResponsePayload> {
382-
this.logger.verbose?.(
383-
`${
384-
MatrixAdapterEventType.UPDATE_ROOMS_GUEST_ACCESS
385-
} - payload: ${JSON.stringify(data)}`,
386-
LogContext.EVENTS
387-
);
388-
const channel = context.getChannelRef();
389-
const originalMsg = context.getMessage();
390-
391-
try {
392-
const result = await this.communicationAdapter.setMatrixRoomsGuestAccess(
393-
data.roomIDs,
394-
data.allowGuests
395-
);
359+
const result = await this.communicationAdapter.updateRoomState(data);
396360
channel.ack(originalMsg);
397-
const response: UpdateRoomsGuestAccessResponsePayload = {
398-
success: result,
399-
};
400361

401-
return response;
362+
return result;
402363
} catch (error) {
403364
const errorMessage = `Error when getting join rule on room: ${error}`;
404365
this.logger.error(errorMessage, LogContext.COMMUNICATION);

0 commit comments

Comments
 (0)