feat: Ignore unsupported notifications features in subscriptions

This commit is contained in:
Joachim Van Herwegen
2023-02-03 13:48:46 +01:00
parent 65860f77da
commit 67d1ff4ac0
2 changed files with 34 additions and 11 deletions

View File

@@ -223,18 +223,21 @@ export abstract class BaseChannelType implements NotificationChannelType {
// Apply the values for all present features that are enabled
for (const feature of DEFAULT_NOTIFICATION_FEATURES) {
const objects = data.getObjects(subject, feature, null);
if (objects.length === 1) {
// Will always succeed since we are iterating over a list which was built using `featureDefinitions`
const { dataType, key } = featureDefinitions.find((feat): boolean => feat.predicate.value === feature)!;
let val: string | number = objects[0].value;
if (dataType === XSD.dateTime) {
val = Date.parse(val);
} else if (dataType === XSD.duration) {
val = toSeconds(parse(val)) * 1000;
const featNode = this.features.find((node): boolean => node.value === feature);
if (featNode) {
const objects = data.getObjects(subject, feature, null);
if (objects.length === 1) {
// Will always succeed since we are iterating over a list which was built using `featureDefinitions`
const { dataType, key } = featureDefinitions.find((feat): boolean => feat.predicate.value === feature)!;
let val: string | number = objects[0].value;
if (dataType === XSD.dateTime) {
val = Date.parse(val);
} else if (dataType === XSD.duration) {
val = toSeconds(parse(val)) * 1000;
}
// Need to convince TS that we can assign `string | number` to this key
(channel as Record<typeof key, string | number>)[key] = val;
}
// Need to convince TS that we can assign `string | number` to this key
(channel as Record<typeof key, string | number>)[key] = val;
}
}