You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-01 04:43:29 +03:00
maySendRedactionForEvent for userId
done using a private helper so kick/ban etc perms can be done easily at a later stage Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -246,6 +246,47 @@ RoomState.prototype.getUserIdsWithDisplayName = function(displayName) {
|
||||
return this._displayNameToUserIds[displayName] || [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if userId is in room, event is not redacted and either sender of
|
||||
* mxEvent or has powerlevel sufficient to redact events other than their own.
|
||||
* @param {MatrixEvent} mxEvent The event to test permission for
|
||||
* @param {string} userId The user ID of the user to test permission for
|
||||
* @return {boolean} true if the given used ID can redact given event
|
||||
*/
|
||||
RoomState.prototype.maySendRedactionForEvent = function(mxEvent, userId) {
|
||||
const member = this.getMember(userId);
|
||||
if (!member || member.membership === 'leave') return false;
|
||||
|
||||
if (mxEvent.isRedacted()) return false;
|
||||
if (mxEvent.getSender() === userId) return true;
|
||||
|
||||
return this._hasSufficientPowerLevelFor('redact', userId);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the given user ID has sufficient power level for type
|
||||
* @param {string} type The type of power level to check against
|
||||
* @param {string} userId The user ID of the user to test permission for
|
||||
* @return {boolean} true if the given user ID has sufficient power level
|
||||
*/
|
||||
RoomState.prototype._hasSufficientPowerLevelFor = function(type, userId) {
|
||||
const member = this.getMember(userId);
|
||||
|
||||
const power_levels_event = this.getStateEvents('m.room.power_levels', '');
|
||||
|
||||
let power_levels;
|
||||
if (power_levels_event) {
|
||||
power_levels = power_levels_event.getContent();
|
||||
}
|
||||
|
||||
let required_level = power_levels.state_default || 50;
|
||||
if (power_levels[type] !== undefined) {
|
||||
required_level = power_levels[type];
|
||||
}
|
||||
|
||||
return member.powerLevel >= required_level;
|
||||
};
|
||||
|
||||
/**
|
||||
* Short-form for maySendEvent('m.room.message', userId)
|
||||
* @param {string} userId The user ID of the user to test permission for
|
||||
@@ -269,7 +310,6 @@ RoomState.prototype.maySendEvent = function(eventType, userId) {
|
||||
return this._maySendEventOfType(eventType, userId, false);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the given MatrixClient has permission to send a state
|
||||
* event of type `stateEventType` into this room.
|
||||
|
||||
Reference in New Issue
Block a user