Skip to content

Commit 2cdc68f

Browse files
authored
Merge pull request #1610 from matrix-org/t3chguy/spaces2
Room helper for getting type and checking if it is a space room
2 parents b55e6c4 + 8e0fc8d commit 2cdc68f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/@types/event.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,9 @@ export enum MsgType {
8787
Location = "m.location",
8888
Video = "m.video",
8989
}
90+
91+
export const RoomCreateTypeField = "org.matrix.msc1772.type"; // Spaces MSC1772
92+
93+
export enum RoomType {
94+
Space = "org.matrix.msc1772.space", // Spaces MSC1772
95+
}

src/models/room.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {RoomMember} from "./room-member";
3030
import {RoomSummary} from "./room-summary";
3131
import {logger} from '../logger';
3232
import {ReEmitter} from '../ReEmitter';
33-
import {EventType} from "../@types/event";
33+
import {EventType, RoomCreateTypeField, RoomType} from "../@types/event";
3434

3535
// These constants are used as sane defaults when the homeserver doesn't support
3636
// the m.room_versions capability. In practice, KNOWN_SAFE_ROOM_VERSION should be
@@ -1856,6 +1856,27 @@ Room.prototype.getJoinRule = function() {
18561856
return this.currentState.getJoinRule();
18571857
};
18581858

1859+
/**
1860+
* Returns the type of the room from the `m.room.create` event content or undefined if none is set
1861+
* @returns {?string} the type of the room. Currently only RoomType.Space is known.
1862+
*/
1863+
Room.prototype.getType = function() {
1864+
const createEvent = this.currentState.getStateEvents("m.room.create", "");
1865+
if (!createEvent) {
1866+
logger.warn("Room " + this.roomId + " does not have an m.room.create event");
1867+
return undefined;
1868+
}
1869+
return createEvent.getContent()[RoomCreateTypeField];
1870+
};
1871+
1872+
/**
1873+
* Returns whether the room is a space-room as defined by MSC1772.
1874+
* @returns {boolean} true if the room's type is RoomType.Space
1875+
*/
1876+
Room.prototype.isSpaceRoom = function() {
1877+
return this.getType() === RoomType.Space;
1878+
};
1879+
18591880
/**
18601881
* This is an internal method. Calculates the name of the room from the current
18611882
* room state.

0 commit comments

Comments
 (0)