Skip to content

Commit 3e2e505

Browse files
committed
Tighter guard around room type in PolicyList
As we updated typescript, we need to have a better guard around the room type. matrix-bot-sdk was also updated because of this.
1 parent 53f9312 commit 3e2e505

File tree

3 files changed

+385
-146
lines changed

3 files changed

+385
-146
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"humanize-duration-ts": "^2.1.1",
4444
"js-yaml": "^4.1.0",
4545
"jsdom": "^16.6.0",
46-
"matrix-bot-sdk": "^0.5.19",
46+
"matrix-bot-sdk": "^0.6.2",
4747
"parse-duration": "^1.0.2",
4848
"shell-quote": "^1.7.3",
4949
"yaml": "^2.1.1"

src/models/PolicyList.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { extractRequestError, LogService, MatrixClient, UserID } from "matrix-bot-sdk";
17+
import { extractRequestError, LogService, MatrixClient, RoomCreateOptions, UserID } from "matrix-bot-sdk";
1818
import { EventEmitter } from "events";
1919
import { ALL_RULE_TYPES, EntityType, ListRule, Recommendation, ROOM_RULE_TYPES, RULE_ROOM, RULE_SERVER, RULE_USER, SERVER_RULE_TYPES, USER_RULE_TYPES } from "./ListRule";
2020

@@ -121,7 +121,7 @@ class PolicyList extends EventEmitter {
121121
client: MatrixClient,
122122
shortcode: string,
123123
invite: string[],
124-
createRoomOptions = {}
124+
createRoomOptions: RoomCreateOptions = {}
125125
): Promise<string /* room id */> {
126126
const powerLevels: { [key: string]: any } = {
127127
"ban": 50,
@@ -143,7 +143,7 @@ class PolicyList extends EventEmitter {
143143
},
144144
"users_default": 0,
145145
};
146-
const finalRoomCreateOptions = {
146+
const finalRoomCreateOptions: RoomCreateOptions = {
147147
// Support for MSC3784.
148148
creation_content: {
149149
type: PolicyList.ROOM_TYPE
@@ -161,7 +161,8 @@ class PolicyList extends EventEmitter {
161161
...createRoomOptions
162162
};
163163
// Guard room type in case someone overwrites it when declaring custom creation_content in future code.
164-
if (!PolicyList.ROOM_TYPE_VARIANTS.includes(finalRoomCreateOptions.creation_content.type)) {
164+
const roomType = finalRoomCreateOptions.creation_content?.type;
165+
if (typeof roomType === 'string' && !PolicyList.ROOM_TYPE_VARIANTS.includes(roomType)) {
165166
throw new TypeError(`Creating a policy room with a type other than the policy room type is not supported, you probably don't want to do this.`);
166167
}
167168
const listRoomId = await client.createRoom(finalRoomCreateOptions);

0 commit comments

Comments
 (0)