From 0e8cd5badd1f348a0bb706453a1bb7dbd4deacb8 Mon Sep 17 00:00:00 2001 From: ElementRobot Date: Fri, 13 Sep 2024 01:18:17 -0500 Subject: [PATCH 1/6] [create-pull-request] automated change (#38) Co-authored-by: dbkr --- src/i18n/strings/pl.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/i18n/strings/pl.json b/src/i18n/strings/pl.json index b8cdf36676..7b14bbaf1d 100644 --- a/src/i18n/strings/pl.json +++ b/src/i18n/strings/pl.json @@ -1968,8 +1968,6 @@ "few": "%(count)s osoby proszą o dołączenie", "many": "%(count)s osób prosi o dołączenie" }, - "release_announcement_description": "Ciesz się prostszym, bardziej przystosowanym nagłówkiem pokoju.", - "release_announcement_header": "Nowy design!", "room_is_public": "Ten pokój jest publiczny", "show_widgets_button": "Pokaż widżety", "video_call_button_ec": "Rozmowa wideo (%(brand)s)", From 5740bdbd38c3da9cd719a0954c2914da8eb49d4f Mon Sep 17 00:00:00 2001 From: ElementRobot Date: Fri, 13 Sep 2024 01:20:25 -0500 Subject: [PATCH 2/6] [create-pull-request] automated change (#39) Co-authored-by: dbkr <986903+dbkr@users.noreply.github.com> --- playwright/plugins/homeserver/synapse/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright/plugins/homeserver/synapse/index.ts b/playwright/plugins/homeserver/synapse/index.ts index a2d8138b52..becfffaa19 100644 --- a/playwright/plugins/homeserver/synapse/index.ts +++ b/playwright/plugins/homeserver/synapse/index.ts @@ -20,7 +20,7 @@ import { randB64Bytes } from "../../utils/rand"; // Docker tag to use for synapse docker image. // We target a specific digest as every now and then a Synapse update will break our CI. // This digest is updated by the playwright-image-updates.yaml workflow periodically. -const DOCKER_TAG = "develop@sha256:5f8d9e0d8c34dd3af23a3b8f2d30223710bccd657f86384803ce4c1cf2fa7263"; +const DOCKER_TAG = "develop@sha256:e69f01d085a69269c892dfa899cb274a593f0fbb4c518eac2b530319fa43c7cb"; async function cfgDirFromTemplate(opts: StartHomeserverOpts): Promise> { const templateDir = path.join(__dirname, "templates", opts.template); From 6b384fe9c1f28645601c55856d6e242900934086 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Fri, 13 Sep 2024 09:47:22 +0200 Subject: [PATCH 3/6] Fix huge usage bandwidth and performance issue of pinned message banner. (#37) * Return only the first 100 pinned messages * Execute pinned message 10 by 10 --- src/hooks/usePinnedEvents.ts | 20 ++++--- src/utils/promise.ts | 15 +++++ .../right_panel/PinnedMessagesCard-test.tsx | 15 +++++ .../PinnedMessagesCard-test.tsx.snap | 4 +- test/utils/promise-test.ts | 57 +++++++++++++++++++ 5 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 test/utils/promise-test.ts diff --git a/src/hooks/usePinnedEvents.ts b/src/hooks/usePinnedEvents.ts index dd01ecb6ad..a29c65625c 100644 --- a/src/hooks/usePinnedEvents.ts +++ b/src/hooks/usePinnedEvents.ts @@ -24,19 +24,22 @@ import { ReadPinsEventId } from "../components/views/right_panel/types"; import { useMatrixClientContext } from "../contexts/MatrixClientContext"; import { useAsyncMemo } from "./useAsyncMemo"; import PinningUtils from "../utils/PinningUtils"; +import { batch } from "../utils/promise.ts"; /** * Get the pinned event IDs from a room. + * The number of pinned events is limited to 100. * @param room */ function getPinnedEventIds(room?: Room): string[] { - return ( + const eventIds: string[] = room ?.getLiveTimeline() .getState(EventTimeline.FORWARDS) ?.getStateEvents(EventType.RoomPinnedEvents, "") - ?.getContent()?.pinned ?? [] - ); + ?.getContent()?.pinned ?? []; + // Limit the number of pinned events to 100 + return eventIds.slice(0, 100); } /** @@ -173,12 +176,11 @@ export function useFetchedPinnedEvents(room: Room, pinnedEventIds: string[]): Ar const cli = useMatrixClientContext(); return useAsyncMemo( - () => - Promise.all( - pinnedEventIds.map( - async (eventId): Promise => fetchPinnedEvent(room, eventId, cli), - ), - ), + () => { + const fetchPromises = pinnedEventIds.map((eventId) => () => fetchPinnedEvent(room, eventId, cli)); + // Fetch the pinned events in batches of 10 + return batch(fetchPromises, 10); + }, [cli, room, pinnedEventIds], null, ); diff --git a/src/utils/promise.ts b/src/utils/promise.ts index bceb2cc3cc..58dfdc8cd9 100644 --- a/src/utils/promise.ts +++ b/src/utils/promise.ts @@ -40,3 +40,18 @@ export async function retry( } throw lastErr; } + +/** + * Batch promises into groups of a given size. + * Execute the promises in parallel, but wait for all promises in a batch to resolve before moving to the next batch. + * @param funcs - The promises to batch + * @param batchSize - The number of promises to execute in parallel + */ +export async function batch(funcs: Array<() => Promise>, batchSize: number): Promise { + const results: T[] = []; + for (let i = 0; i < funcs.length; i += batchSize) { + const batch = funcs.slice(i, i + batchSize); + results.push(...(await Promise.all(batch.map((f) => f())))); + } + return results; +} diff --git a/test/components/views/right_panel/PinnedMessagesCard-test.tsx b/test/components/views/right_panel/PinnedMessagesCard-test.tsx index 9fd212b43c..8f8ffa3520 100644 --- a/test/components/views/right_panel/PinnedMessagesCard-test.tsx +++ b/test/components/views/right_panel/PinnedMessagesCard-test.tsx @@ -196,6 +196,21 @@ describe("", () => { expect(asFragment()).toMatchSnapshot(); }); + it("should not show more than 100 messages", async () => { + const events = Array.from({ length: 120 }, (_, i) => + mkMessage({ + event: true, + room: "!room:example.org", + user: "@alice:example.org", + msg: `The message ${i}`, + ts: i, + }), + ); + await initPinnedMessagesCard(events, []); + + expect(screen.queryAllByRole("listitem")).toHaveLength(100); + }); + it("should updates when messages are pinned", async () => { // Start with nothing pinned const { addLocalPinEvent, addNonLocalPinEvent } = await initPinnedMessagesCard([], []); diff --git a/test/components/views/right_panel/__snapshots__/PinnedMessagesCard-test.tsx.snap b/test/components/views/right_panel/__snapshots__/PinnedMessagesCard-test.tsx.snap index a055fdcca8..95573aa55e 100644 --- a/test/components/views/right_panel/__snapshots__/PinnedMessagesCard-test.tsx.snap +++ b/test/components/views/right_panel/__snapshots__/PinnedMessagesCard-test.tsx.snap @@ -358,7 +358,7 @@ exports[` unpin all should not allow to unpinall 1`] = ` aria-label="Open menu" class="_icon-button_bh2qc_17" data-state="closed" - id="radix-18" + id="radix-218" role="button" style="--cpd-icon-button-size: 24px;" tabindex="0" @@ -424,7 +424,7 @@ exports[` unpin all should not allow to unpinall 1`] = ` aria-label="Open menu" class="_icon-button_bh2qc_17" data-state="closed" - id="radix-19" + id="radix-219" role="button" style="--cpd-icon-button-size: 24px;" tabindex="0" diff --git a/test/utils/promise-test.ts b/test/utils/promise-test.ts new file mode 100644 index 0000000000..6733c2ae99 --- /dev/null +++ b/test/utils/promise-test.ts @@ -0,0 +1,57 @@ +/* + * Copyright 2024 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only + * Please see LICENSE files in the repository root for full details. + * + */ + +import { batch } from "../../src/utils/promise.ts"; + +describe("promise.ts", () => { + describe("batch", () => { + afterEach(() => jest.useRealTimers()); + + it("should batch promises into groups of a given size", async () => { + const promises = [() => Promise.resolve(1), () => Promise.resolve(2), () => Promise.resolve(3)]; + const batchSize = 2; + const result = await batch(promises, batchSize); + expect(result).toEqual([1, 2, 3]); + }); + + it("should wait for the current batch to finish to request the next one", async () => { + jest.useFakeTimers(); + + let promise1Called = false; + const promise1 = () => + new Promise((resolve) => { + promise1Called = true; + resolve(1); + }); + let promise2Called = false; + const promise2 = () => + new Promise((resolve) => { + promise2Called = true; + setTimeout(() => { + resolve(2); + }, 10); + }); + + let promise3Called = false; + const promise3 = () => + new Promise((resolve) => { + promise3Called = true; + resolve(3); + }); + const batchSize = 2; + const batchPromise = batch([promise1, promise2, promise3], batchSize); + + expect(promise1Called).toBe(true); + expect(promise2Called).toBe(true); + expect(promise3Called).toBe(false); + + jest.advanceTimersByTime(11); + expect(await batchPromise).toEqual([1, 2, 3]); + }); + }); +}); From b5058286e0e57b8e23bf75eb883f749c21f0d7a2 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Fri, 13 Sep 2024 07:29:25 -0400 Subject: [PATCH 4/6] update test to work with newer Rust crypto (#32) --- playwright/e2e/crypto/event-shields.spec.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/playwright/e2e/crypto/event-shields.spec.ts b/playwright/e2e/crypto/event-shields.spec.ts index 077d9126fa..3a85d06333 100644 --- a/playwright/e2e/crypto/event-shields.spec.ts +++ b/playwright/e2e/crypto/event-shields.spec.ts @@ -41,7 +41,12 @@ test.describe("Cryptography", function () { }); }); - test("should show the correct shield on e2e events", async ({ page, app, bot: bob, homeserver }) => { + test("should show the correct shield on e2e events", async ({ + page, + app, + bot: bob, + homeserver, + }, workerInfo) => { // Bob has a second, not cross-signed, device const bobSecondDevice = new Bot(page, homeserver, { bootstrapSecretStorage: false, @@ -117,7 +122,10 @@ test.describe("Cryptography", function () { await lastTileE2eIcon.focus(); await expect(page.getByRole("tooltip")).toContainText("Encrypted by a device not verified by its owner."); - /* Should show a grey padlock for a message from an unknown device */ + /* In legacy crypto: should show a grey padlock for a message from a deleted device. + * In rust crypto: should show a red padlock for a message from an unverified device. + * Rust crypto remembers the verification state of the sending device, so it will know that the device was + * unverified, even if it gets deleted. */ // bob deletes his second device await bobSecondDevice.evaluate((cli) => cli.logout(true)); @@ -148,7 +156,11 @@ test.describe("Cryptography", function () { await expect(last).toContainText("test encrypted from unverified"); await expect(lastE2eIcon).toHaveClass(/mx_EventTile_e2eIcon_warning/); await lastE2eIcon.focus(); - await expect(page.getByRole("tooltip")).toContainText("Encrypted by an unknown or deleted device."); + await expect(page.getByRole("tooltip")).toContainText( + workerInfo.project.name === "Legacy Crypto" + ? "Encrypted by an unknown or deleted device." + : "Encrypted by a device not verified by its owner.", + ); }); test("Should show a grey padlock for a key restored from backup", async ({ From be59791db1605e136814d37d29dc9f6b68dcb440 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 13 Sep 2024 12:49:19 +0100 Subject: [PATCH 5/6] Add support for `org.matrix.cross_signing_reset` UIA stage flow (#34) * Soften UIA fallback postMessage check to work cross-origin Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Do the same for the SSO UIA flow Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add support for `org.matrix.cross_signing_reset` UIA stage flow Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Check against MessageEvent::source instead Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * i18n Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Remove protected method Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/InteractiveAuth.tsx | 5 +- .../auth/InteractiveAuthEntryComponents.tsx | 59 +++++++++++++++++-- src/i18n/strings/en_EN.json | 2 + .../InteractiveAuthEntryComponents-test.tsx | 48 ++++++++++++++- ...teractiveAuthEntryComponents-test.tsx.snap | 50 ++++++++++++++++ 5 files changed, 155 insertions(+), 9 deletions(-) diff --git a/src/components/structures/InteractiveAuth.tsx b/src/components/structures/InteractiveAuth.tsx index 86cf6af665..91e52a1905 100644 --- a/src/components/structures/InteractiveAuth.tsx +++ b/src/components/structures/InteractiveAuth.tsx @@ -20,6 +20,7 @@ import { logger } from "matrix-js-sdk/src/logger"; import getEntryComponentForLoginType, { ContinueKind, + CustomAuthType, IStageComponent, } from "../views/auth/InteractiveAuthEntryComponents"; import Spinner from "../views/elements/Spinner"; @@ -75,11 +76,11 @@ export interface InteractiveAuthProps { // Called when the stage changes, or the stage's phase changes. First // argument is the stage, second is the phase. Some stages do not have // phases and will be counted as 0 (numeric). - onStagePhaseChange?(stage: AuthType | null, phase: number): void; + onStagePhaseChange?(stage: AuthType | CustomAuthType | null, phase: number): void; } interface IState { - authStage?: AuthType; + authStage?: CustomAuthType | AuthType; stageState?: IStageStatus; busy: boolean; errorText?: string; diff --git a/src/components/views/auth/InteractiveAuthEntryComponents.tsx b/src/components/views/auth/InteractiveAuthEntryComponents.tsx index a0946564aa..7a15ee2095 100644 --- a/src/components/views/auth/InteractiveAuthEntryComponents.tsx +++ b/src/components/views/auth/InteractiveAuthEntryComponents.tsx @@ -11,6 +11,8 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix"; import { AuthType, AuthDict, IInputs, IStageStatus } from "matrix-js-sdk/src/interactive-auth"; import { logger } from "matrix-js-sdk/src/logger"; import React, { ChangeEvent, createRef, FormEvent, Fragment } from "react"; +import { Button, Text } from "@vector-im/compound-web"; +import PopOutIcon from "@vector-im/compound-design-tokens/assets/web/icons/pop-out"; import EmailPromptIcon from "../../../../res/img/element-icons/email-prompt.svg"; import { _t } from "../../../languageHandler"; @@ -21,6 +23,7 @@ import AccessibleButton, { AccessibleButtonKind, ButtonEvent } from "../elements import Field from "../elements/Field"; import Spinner from "../elements/Spinner"; import CaptchaForm from "./CaptchaForm"; +import { Flex } from "../../utils/Flex"; /* This file contains a collection of components which are used by the * InteractiveAuth to prompt the user to enter the information needed @@ -905,11 +908,11 @@ export class SSOAuthEntry extends React.Component { - private popupWindow: Window | null; - private fallbackButton = createRef(); +export class FallbackAuthEntry extends React.Component { + protected popupWindow: Window | null; + protected fallbackButton = createRef(); - public constructor(props: IAuthEntryProps) { + public constructor(props: IAuthEntryProps & T) { super(props); // we have to make the user click a button, as browsers will block @@ -967,6 +970,50 @@ export class FallbackAuthEntry extends React.Component { } } +export enum CustomAuthType { + // Workaround for MAS requiring non-UIA authentication for resetting cross-signing. + MasCrossSigningReset = "org.matrix.cross_signing_reset", +} + +export class MasUnlockCrossSigningAuthEntry extends FallbackAuthEntry<{ + stageParams?: { + url?: string; + }; +}> { + public static LOGIN_TYPE = CustomAuthType.MasCrossSigningReset; + + private onGoToAccountClick = (): void => { + if (!this.props.stageParams?.url) return; + this.popupWindow = window.open(this.props.stageParams.url, "_blank"); + }; + + private onRetryClick = (): void => { + this.props.submitAuthDict({}); + }; + + public render(): React.ReactNode { + return ( +
+ {_t("auth|uia|mas_cross_signing_reset_description")} + + + + +
+ ); + } +} + export interface IStageComponentProps extends IAuthEntryProps { stageParams?: Record; inputs?: IInputs; @@ -983,8 +1030,10 @@ export interface IStageComponent extends React.ComponentClassResend it", "email_resent": "Resent!", "fallback_button": "Start authentication", + "mas_cross_signing_reset_cta": "Go to your account", + "mas_cross_signing_reset_description": "Reset your identity through your account provider and then come back and click “Retry”.", "msisdn": "A text message has been sent to %(msisdn)s", "msisdn_token_incorrect": "Token incorrect", "msisdn_token_prompt": "Please enter the code it contains:", diff --git a/test/components/views/auth/InteractiveAuthEntryComponents-test.tsx b/test/components/views/auth/InteractiveAuthEntryComponents-test.tsx index 62c02b0d58..1cbf799af7 100644 --- a/test/components/views/auth/InteractiveAuthEntryComponents-test.tsx +++ b/test/components/views/auth/InteractiveAuthEntryComponents-test.tsx @@ -7,11 +7,14 @@ */ import React from "react"; -import { render, screen, waitFor, act } from "@testing-library/react"; +import { render, screen, waitFor, act, fireEvent } from "@testing-library/react"; import { AuthType } from "matrix-js-sdk/src/interactive-auth"; import userEvent from "@testing-library/user-event"; -import { EmailIdentityAuthEntry } from "../../../../src/components/views/auth/InteractiveAuthEntryComponents"; +import { + EmailIdentityAuthEntry, + MasUnlockCrossSigningAuthEntry, +} from "../../../../src/components/views/auth/InteractiveAuthEntryComponents"; import { createTestClient } from "../../../test-utils"; describe("", () => { @@ -55,3 +58,44 @@ describe("", () => { await waitFor(() => expect(screen.queryByRole("button", { name: "Resend" })).toBeInTheDocument()); }); }); + +describe("", () => { + const renderAuth = (props = {}) => { + const matrixClient = createTestClient(); + + return render( + , + ); + }; + + test("should render", () => { + const { container } = renderAuth(); + expect(container).toMatchSnapshot(); + }); + + test("should open idp in new tab on click", async () => { + const spy = jest.spyOn(global.window, "open"); + renderAuth(); + + fireEvent.click(screen.getByRole("button", { name: "Go to your account" })); + expect(spy).toHaveBeenCalledWith("https://example.com", "_blank"); + }); + + test("should retry uia request on click", async () => { + const submitAuthDict = jest.fn(); + renderAuth({ submitAuthDict }); + + fireEvent.click(screen.getByRole("button", { name: "Retry" })); + expect(submitAuthDict).toHaveBeenCalledWith({}); + }); +}); diff --git a/test/components/views/auth/__snapshots__/InteractiveAuthEntryComponents-test.tsx.snap b/test/components/views/auth/__snapshots__/InteractiveAuthEntryComponents-test.tsx.snap index 65f86a35d2..16e5b3abc2 100644 --- a/test/components/views/auth/__snapshots__/InteractiveAuthEntryComponents-test.tsx.snap +++ b/test/components/views/auth/__snapshots__/InteractiveAuthEntryComponents-test.tsx.snap @@ -32,3 +32,53 @@ exports[` should render 1`] = ` `; + +exports[` should render 1`] = ` +
+
+

+ Reset your identity through your account provider and then come back and click “Retry”. +

+
+ + +
+
+
+`; From 9426fec8c7bb2bd5f5045603a0016428e89f1ac1 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 13 Sep 2024 14:15:10 +0100 Subject: [PATCH 6/6] Fix timeout type (#40) In the user profile timezone code, which was failing a ts check. --- src/hooks/useUserTimezone.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useUserTimezone.ts b/src/hooks/useUserTimezone.ts index 11198be1fa..686679bb90 100644 --- a/src/hooks/useUserTimezone.ts +++ b/src/hooks/useUserTimezone.ts @@ -29,7 +29,7 @@ import { MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix"; */ export const useUserTimezone = (cli: MatrixClient, userId: string): { timezone: string; friendly: string } | null => { const [timezone, setTimezone] = useState(); - const [updateInterval, setUpdateInterval] = useState(); + const [updateInterval, setUpdateInterval] = useState>(); const [friendly, setFriendly] = useState(); const [supported, setSupported] = useState();