1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-14 19:22:15 +03:00

Function for working out notif trigger permission

And make pushprocessor use this function
This commit is contained in:
David Baker
2017-11-02 12:04:55 +00:00
parent ff5f95227a
commit 978db89deb
2 changed files with 35 additions and 22 deletions

View File

@@ -393,6 +393,37 @@ RoomState.prototype._maySendEventOfType = function(eventType, userId, state) {
return member.powerLevel >= required_level;
};
/**
* Returns true if the given user ID has permission to trigger notification
* of type `notifLevelKey`
* @param {string} notifLevelKey The level of notification to test (eg. 'room')
* @param {string} userId The user ID of the user to test permission for
* @return {boolean} true if the given user ID has permission to trigger a
* notification of this type.
*/
RoomState.prototype.mayTriggerNotifOfType = function(notifLevelKey, userId) {
const member = this.getMember(userId);
if (!member || member.membership == 'leave') {
return false;
}
const powerLevelsEvent = this.getStateEvents('m.room.power_levels', '');
if (!powerLevelsEvent || !powerLevelsEvent.getContent()) {
return false;
}
let notifLevel = 50;
if (
powerLevelsEvent.getContent().notifications &&
powerLevelsEvent.getContent().notifications[notifLevelKey]
) {
notifLevel = powerLevelsEvent.getContent().notifications[notifLevelKey];
}
return member.powerLevel >= notifLevel;
};
/**
* The RoomState class.
*/