1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Support room notifs

Specifically, add support for the sender_notification_permission
push rule condition. Also delays calculating notification events
until after they're added to the timeline, as per comment.
This commit is contained in:
David Baker
2017-10-23 16:02:06 +01:00
parent b0b50f4ef9
commit e33b786f65
2 changed files with 34 additions and 4 deletions

View File

@@ -123,6 +123,7 @@ function PushProcessor(client) {
"device": eventFulfillsDeviceCondition,
"contains_display_name": eventFulfillsDisplayNameCondition,
"room_member_count": eventFulfillsRoomMemberCountCondition,
"sender_notification_permission": eventFulfillsSenderNotificationPermCondition,
};
if (condition_functions[cond.kind]) {
return condition_functions[cond.kind](cond, ev);
@@ -133,6 +134,33 @@ function PushProcessor(client) {
return false;
};
const eventFulfillsSenderNotificationPermCondition = function(cond, ev) {
const notifLevelKey = cond['key'];
if (!notifLevelKey) {
return false;
}
const room = client.getRoom(ev.getRoomId());
if (!room || !room.currentState) {
return false;
}
const powerLevels = room.currentState.getStateEvents('m.room.power_levels', '');
if (!powerLevels || !powerLevels.getContent()) {
return false;
}
let notifLevel = 50;
if (
powerLevels.getContent().notifications &&
powerLevels.getContent().notifications[notifLevelKey]
) {
notifLevel = powerLevels.getContent().notifications[notifLevelKey];
}
return ev.sender.powerLevel >= notifLevel;
}
const eventFulfillsRoomMemberCountCondition = function(cond, ev) {
if (!cond.is) {
return false;