From b978b538eba4170d9bffd8cd2ae08e5de989fe85 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 12 Nov 2020 10:30:46 -0700 Subject: [PATCH] Misc cleanup --- src/ClientWidgetApi.ts | 2 +- src/models/WidgetEventCapability.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ClientWidgetApi.ts b/src/ClientWidgetApi.ts index f3318f5..0bce8b2 100644 --- a/src/ClientWidgetApi.ts +++ b/src/ClientWidgetApi.ts @@ -170,7 +170,7 @@ export class ClientWidgetApi extends EventEmitter { }).then(allowedCaps => { console.log(`Widget ${this.widget.id} is allowed capabilities:`, Array.from(allowedCaps)); this.allowedCapabilities = allowedCaps; - this.allowedEvents = Array.from(new Set(WidgetEventCapability.findEventCapabilities(allowedCaps))); + this.allowedEvents = WidgetEventCapability.findEventCapabilities(allowedCaps); this.capabilitiesFinished = true; this.emit("ready"); }); diff --git a/src/models/WidgetEventCapability.ts b/src/models/WidgetEventCapability.ts index 8dfe6dd..fc1ea01 100644 --- a/src/models/WidgetEventCapability.ts +++ b/src/models/WidgetEventCapability.ts @@ -92,11 +92,15 @@ export class WidgetEventCapability { if (direction === null) continue; + // The capability uses `#` as a separator between event type and state key/msgtype, + // so we split on that. However, a # is also valid in either one of those so we + // join accordingly. + // Eg: `m.room.message##m.text` is "m.room.message" event with msgtype "#m.text". let keyStr: string = null; if (eventSegment.includes('#')) { - const p = eventSegment.split('#'); - eventSegment = p[0]; - keyStr = p.slice(1).join('#'); + const parts = eventSegment.split('#'); + eventSegment = parts[0]; + keyStr = parts.slice(1).join('#'); } parsed.push(new WidgetEventCapability(direction, eventSegment, isState, keyStr, cap));