You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Function for working out notif trigger permission
And make pushprocessor use this function
This commit is contained in:
@@ -393,6 +393,37 @@ RoomState.prototype._maySendEventOfType = function(eventType, userId, state) {
|
|||||||
return member.powerLevel >= required_level;
|
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.
|
* The RoomState class.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -145,28 +145,10 @@ function PushProcessor(client) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const powerLevels = room.currentState.getStateEvents('m.room.power_levels', '');
|
// Note that this should not be the current state of the room but the state at
|
||||||
if (!powerLevels || !powerLevels.getContent()) {
|
// the point the event is in the DAG. Unfortunately the js-sdk does not store
|
||||||
return false;
|
// this.
|
||||||
}
|
return room.currentState.mayTriggerNotifOfType(notifLevelKey, ev.getSender());
|
||||||
|
|
||||||
let notifLevel = 50;
|
|
||||||
if (
|
|
||||||
powerLevels.getContent().notifications &&
|
|
||||||
powerLevels.getContent().notifications[notifLevelKey]
|
|
||||||
) {
|
|
||||||
notifLevel = powerLevels.getContent().notifications[notifLevelKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
// This cannot be assumed to always be set for state events
|
|
||||||
// (in particular it is never set for the room creation event
|
|
||||||
// because it preceeds the join event of the sender).
|
|
||||||
// In these cases, this condition cannot match.
|
|
||||||
if (ev.sender === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ev.sender.powerLevel >= notifLevel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const eventFulfillsRoomMemberCountCondition = function(cond, ev) {
|
const eventFulfillsRoomMemberCountCondition = function(cond, ev) {
|
||||||
|
|||||||
Reference in New Issue
Block a user