@@ -30,6 +30,7 @@ import {RoomMember} from "./room-member";
30
30
import { RoomSummary } from "./room-summary" ;
31
31
import { logger } from '../logger' ;
32
32
import { ReEmitter } from '../ReEmitter' ;
33
+ import { EventType } from "../@types/event" ;
33
34
34
35
// These constants are used as sane defaults when the homeserver doesn't support
35
36
// the m.room_versions capability. In practice, KNOWN_SAFE_ROOM_VERSION should be
@@ -1822,7 +1823,7 @@ Room.prototype.getAccountData = function(type) {
1822
1823
1823
1824
1824
1825
/**
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
1826
1827
* @return {boolean } true if the user should be permitted to send
1827
1828
* message events into the room.
1828
1829
*/
@@ -1831,6 +1832,30 @@ Room.prototype.maySendMessage = function() {
1831
1832
this . currentState . maySendEvent ( 'm.room.message' , this . myUserId ) ;
1832
1833
} ;
1833
1834
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
+
1834
1859
/**
1835
1860
* This is an internal method. Calculates the name of the room from the current
1836
1861
* room state.
@@ -2048,3 +2073,12 @@ function memberNamesToRoomName(names, count = (names.length + 1)) {
2048
2073
*
2049
2074
* @param {EventStatus } oldStatus The previous event status.
2050
2075
*/
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