Skip to content

Commit 44c1242

Browse files
committed
Fix V12 policy room creation.
the-draupnir-project/Draupnir#934.
1 parent e9ac598 commit 44c1242

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/PolicyList/PolicyListManager.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
MatrixRoomID,
5555
StringUserID,
5656
MatrixRoomReference,
57-
MatrixUserID,
57+
userServerName,
5858
} from '@the-draupnir-project/matrix-basic-types';
5959

6060
export class BotSDKPolicyRoomManager implements PolicyRoomManager {
@@ -106,18 +106,28 @@ export class BotSDKPolicyRoomManager implements PolicyRoomManager {
106106
invite: string[],
107107
createRoomOptions: RoomCreateOptions
108108
): Promise<ActionResult<MatrixRoomID>> {
109-
const rawCreatorResult = await this.client.getUserId().then(
110-
(user) => Ok(user),
109+
const creator = await this.client.getUserId().then(
110+
(user) => Ok(StringUserID(user)),
111111
(exception: unknown) =>
112112
ActionException.Result(
113113
'Could not create a list because we could not find the mxid of the list creator.',
114114
{ exception, exceptionKind: ActionExceptionKind.Unknown }
115115
)
116116
);
117-
if (isError(rawCreatorResult)) {
118-
return rawCreatorResult;
117+
if (isError(creator)) {
118+
return creator;
119119
}
120-
const creator = new MatrixUserID(rawCreatorResult.ok as StringUserID);
120+
const clientCapabilities = await this.clientPlatform
121+
.toClientCapabilitiesNegotiation()
122+
.getClientCapabilities();
123+
if (isError(clientCapabilities)) {
124+
return clientCapabilities.elaborate(
125+
'Unable to get client capabilities for the policy room creator.'
126+
);
127+
}
128+
const isV12OrAboveDefault =
129+
parseInt(clientCapabilities.ok.capabilities['m.room_versions'].default) >=
130+
12;
121131
const powerLevels: RoomCreateOptions['power_level_content_override'] = {
122132
ban: 50,
123133
events: {
@@ -133,7 +143,7 @@ export class BotSDKPolicyRoomManager implements PolicyRoomManager {
133143
redact: 50,
134144
state_default: 50,
135145
users: {
136-
[creator.toString()]: 100,
146+
...(isV12OrAboveDefault ? {} : { [creator.ok]: 100 }),
137147
...invite.reduce((users, mxid) => ({ ...users, [mxid]: 50 }), {}),
138148
},
139149
users_default: 0,
@@ -167,7 +177,7 @@ export class BotSDKPolicyRoomManager implements PolicyRoomManager {
167177
}
168178
return await this.client.createRoom(finalRoomCreateOptions).then(
169179
(roomId) => {
170-
const room = new MatrixRoomID(roomId, [creator.serverName]);
180+
const room = new MatrixRoomID(roomId, [userServerName(creator.ok)]);
171181
this.joinPreempter.preemptTimelineJoin(
172182
this.clientUserID,
173183
room.toRoomIDOrAlias()

0 commit comments

Comments
 (0)