@@ -30,7 +30,7 @@ import {RoomMember} from "./room-member";
3030import { RoomSummary } from "./room-summary" ;
3131import { logger } from '../logger' ;
3232import { 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