@@ -30,6 +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" ;
3334
3435// These constants are used as sane defaults when the homeserver doesn't support
3536// the m.room_versions capability. In practice, KNOWN_SAFE_ROOM_VERSION should be
@@ -1831,6 +1832,30 @@ Room.prototype.maySendMessage = function() {
18311832 this . currentState . maySendEvent ( 'm.room.message' , this . myUserId ) ;
18321833} ;
18331834
1835+ /**
1836+ * Returns whether the given user has permissions to issue an invite for this room.
1837+ * @param {string } userId the ID of the Matrix user to check permissions for
1838+ * @returns {boolean } true if the user should be permitted to issue invites for this room.
1839+ */
1840+ Room . prototype . canInvite = function ( userId ) {
1841+ let canInvite = this . getMyMembership ( ) === "join" ;
1842+ const powerLevelsEvent = this . currentState . getStateEvents ( EventType . RoomPowerLevels , "" ) ;
1843+ const powerLevels = powerLevelsEvent && powerLevelsEvent . getContent ( ) ;
1844+ const me = this . getMember ( userId ) ;
1845+ if ( powerLevels && me && powerLevels . invite > me . powerLevel ) {
1846+ canInvite = false ;
1847+ }
1848+ return canInvite ;
1849+ } ;
1850+
1851+ /**
1852+ * Returns the join rule based on the m.room.join_rule state event, defaulting to `invite`.
1853+ * @returns {string } the join_rule applied to this room
1854+ */
1855+ Room . prototype . getJoinRule = function ( ) {
1856+ return this . currentState . getJoinRule ( ) ;
1857+ } ;
1858+
18341859/**
18351860 * This is an internal method. Calculates the name of the room from the current
18361861 * room state.
0 commit comments