From 908e9389961d8a7cc3220dd5440c2f5151c40d4e Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Mon, 13 Dec 2021 11:34:04 +0100 Subject: [PATCH] Keep all previously approved widget capabilities when requesting new capabilities (#7340) --- src/stores/widgets/StopGapWidgetDriver.ts | 4 ++-- src/utils/iterables.ts | 6 +++++- test/utils/iterables-test.ts | 13 ++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/stores/widgets/StopGapWidgetDriver.ts b/src/stores/widgets/StopGapWidgetDriver.ts index 83b7dfb827..8946b1af86 100644 --- a/src/stores/widgets/StopGapWidgetDriver.ts +++ b/src/stores/widgets/StopGapWidgetDriver.ts @@ -34,7 +34,7 @@ import { IContent, IEvent, MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Room } from "matrix-js-sdk/src/models/room"; import { logger } from "matrix-js-sdk/src/logger"; -import { iterableDiff, iterableUnion } from "../../utils/iterables"; +import { iterableDiff, iterableMerge } from "../../utils/iterables"; import { MatrixClientPeg } from "../../MatrixClientPeg"; import ActiveRoomObserver from "../../ActiveRoomObserver"; import Modal from "../../Modal"; @@ -131,7 +131,7 @@ export class StopGapWidgetDriver extends WidgetDriver { } } - const allAllowed = new Set(iterableUnion(allowedSoFar, requested)); + const allAllowed = new Set(iterableMerge(allowedSoFar, requested)); if (rememberApproved) { setRememberedCapabilitiesForWidget(this.forWidget, Array.from(allAllowed)); diff --git a/src/utils/iterables.ts b/src/utils/iterables.ts index 7883b2257a..66cda8a693 100644 --- a/src/utils/iterables.ts +++ b/src/utils/iterables.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { arrayDiff, arrayUnion } from "./arrays"; +import { arrayDiff, arrayMerge, arrayUnion } from "./arrays"; + +export function iterableMerge(a: Iterable, b: Iterable): Iterable { + return arrayMerge(Array.from(a), Array.from(b)); +} export function iterableUnion(a: Iterable, b: Iterable): Iterable { return arrayUnion(Array.from(a), Array.from(b)); diff --git a/test/utils/iterables-test.ts b/test/utils/iterables-test.ts index 5c1e2241f4..4e3608c2a2 100644 --- a/test/utils/iterables-test.ts +++ b/test/utils/iterables-test.ts @@ -14,9 +14,20 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { iterableDiff, iterableUnion } from "../../src/utils/iterables"; +import { iterableDiff, iterableMerge, iterableUnion } from "../../src/utils/iterables"; describe('iterables', () => { + describe('iterableMerge', () => { + it('should return a merged array', () => { + const a = [1, 2, 3]; + const b = [1, 2, 4]; // note diff + const result = iterableMerge(a, b); + expect(result).toBeDefined(); + expect(result).toHaveLength(4); + expect(result).toEqual([1, 2, 3, 4]); + }); + }); + describe('iterableUnion', () => { it('should return a union', () => { const a = [1, 2, 3];