diff --git a/src/pushprocessor.js b/src/pushprocessor.js index e7b2ff4bc..9d514454c 100644 --- a/src/pushprocessor.js +++ b/src/pushprocessor.js @@ -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; diff --git a/src/sync.js b/src/sync.js index cc2d7a5f2..2de423b6f 100644 --- a/src/sync.js +++ b/src/sync.js @@ -1277,6 +1277,12 @@ SyncApi.prototype._processRoomEvents = function(room, stateEventList, // may make notifications appear which should have the right name. room.recalculate(this.client.credentials.userId); + // execute the timeline events, this will begin to diverge the current state + // if the timeline has any state events in it. + // This also needs to be done before running push rules on the events as they need + // to be decorated with sender etc. + room.addLiveEvents(timelineEventList); + // gather our notifications into this._notifEvents if (client.getNotifTimelineSet()) { for (let i = 0; i < timelineEventList.length; i++) { @@ -1287,10 +1293,6 @@ SyncApi.prototype._processRoomEvents = function(room, stateEventList, } } } - - // execute the timeline events, this will begin to diverge the current state - // if the timeline has any state events in it. - room.addLiveEvents(timelineEventList); }; /**