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

pull/21833/head
Dominik Henneke 2021-12-13 11:34:04 +01:00 committed by GitHub
parent 3b3776222b
commit 908e938996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -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 { Room } from "matrix-js-sdk/src/models/room";
import { logger } from "matrix-js-sdk/src/logger"; 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 { MatrixClientPeg } from "../../MatrixClientPeg";
import ActiveRoomObserver from "../../ActiveRoomObserver"; import ActiveRoomObserver from "../../ActiveRoomObserver";
import Modal from "../../Modal"; 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) { if (rememberApproved) {
setRememberedCapabilitiesForWidget(this.forWidget, Array.from(allAllowed)); setRememberedCapabilitiesForWidget(this.forWidget, Array.from(allAllowed));

View File

@ -14,7 +14,11 @@
* limitations under the License. * 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> { export function iterableUnion<T>(a: Iterable<T>, b: Iterable<T>): Iterable<T> {
return arrayUnion(Array.from(a), Array.from(b)); return arrayUnion(Array.from(a), Array.from(b));

View File

@ -14,9 +14,20 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { iterableDiff, iterableUnion } from "../../src/utils/iterables"; import { iterableDiff, iterableMerge, iterableUnion } from "../../src/utils/iterables";
describe('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', () => { describe('iterableUnion', () => {
it('should return a union', () => { it('should return a union', () => {
const a = [1, 2, 3]; const a = [1, 2, 3];