Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Keep all previously approved widget capabilities when requesting new capabilities #7340

Merged
merged 1 commit into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/stores/widgets/StopGapWidgetDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 5 additions & 1 deletion src/utils/iterables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*/

import { arrayDiff, arrayUnion } from "./arrays";
import { arrayDiff, arrayMerge, arrayUnion } from "./arrays";

export function iterableMerge<T>(a: Iterable<T>, b: Iterable<T>): Iterable<T> {
return arrayMerge(Array.from(a), Array.from(b));
}

export function iterableUnion<T>(a: Iterable<T>, b: Iterable<T>): Iterable<T> {
return arrayUnion(Array.from(a), Array.from(b));
Expand Down
13 changes: 12 additions & 1 deletion test/utils/iterables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down