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
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:
@@ -123,6 +123,7 @@ function PushProcessor(client) {
|
|||||||
"device": eventFulfillsDeviceCondition,
|
"device": eventFulfillsDeviceCondition,
|
||||||
"contains_display_name": eventFulfillsDisplayNameCondition,
|
"contains_display_name": eventFulfillsDisplayNameCondition,
|
||||||
"room_member_count": eventFulfillsRoomMemberCountCondition,
|
"room_member_count": eventFulfillsRoomMemberCountCondition,
|
||||||
|
"sender_notification_permission": eventFulfillsSenderNotificationPermCondition,
|
||||||
};
|
};
|
||||||
if (condition_functions[cond.kind]) {
|
if (condition_functions[cond.kind]) {
|
||||||
return condition_functions[cond.kind](cond, ev);
|
return condition_functions[cond.kind](cond, ev);
|
||||||
@@ -133,6 +134,33 @@ function PushProcessor(client) {
|
|||||||
return false;
|
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) {
|
const eventFulfillsRoomMemberCountCondition = function(cond, ev) {
|
||||||
if (!cond.is) {
|
if (!cond.is) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
10
src/sync.js
10
src/sync.js
@@ -1277,6 +1277,12 @@ SyncApi.prototype._processRoomEvents = function(room, stateEventList,
|
|||||||
// may make notifications appear which should have the right name.
|
// may make notifications appear which should have the right name.
|
||||||
room.recalculate(this.client.credentials.userId);
|
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
|
// gather our notifications into this._notifEvents
|
||||||
if (client.getNotifTimelineSet()) {
|
if (client.getNotifTimelineSet()) {
|
||||||
for (let i = 0; i < timelineEventList.length; i++) {
|
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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user