@@ -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
@@ -1822,7 +1823,7 @@ Room.prototype.getAccountData = function(type) {
18221823
18231824
18241825/**
1825- * Returns wheter the syncing user has permission to send a message in the room
1826+ * Returns whether the syncing user has permission to send a message in the room
18261827 * @return {boolean } true if the user should be permitted to send
18271828 * message events into the room.
18281829 */
@@ -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.
@@ -2048,3 +2073,12 @@ function memberNamesToRoomName(names, count = (names.length + 1)) {
20482073 *
20492074 * @param {EventStatus } oldStatus The previous event status.
20502075 */
2076+
2077+ /**
2078+ * Fires when the logged in user's membership in the room is updated.
2079+ *
2080+ * @event module:models/room~Room#"Room.myMembership"
2081+ * @param {Room } room The room in which the membership has been updated
2082+ * @param {string } membership The new membership value
2083+ * @param {string } prevMembership The previous membership value
2084+ */
0 commit comments