Merge branch 'develop' into dbkr/sss
This commit is contained in:
commit
797ef2d053
23 changed files with 697 additions and 182 deletions
|
@ -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<T> {
|
|||
// 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;
|
||||
|
|
|
@ -131,6 +131,7 @@ class LoggedInView extends React.Component<IProps, IState> {
|
|||
protected layoutWatcherRef?: string;
|
||||
protected compactLayoutWatcherRef?: string;
|
||||
protected backgroundImageWatcherRef?: string;
|
||||
protected timezoneProfileUpdateRef?: string[];
|
||||
protected resizer?: Resizer<ICollapseConfig, CollapseItem>;
|
||||
|
||||
public constructor(props: IProps) {
|
||||
|
@ -182,6 +183,11 @@ class LoggedInView extends React.Component<IProps, IState> {
|
|||
this.refreshBackgroundImage,
|
||||
);
|
||||
|
||||
this.timezoneProfileUpdateRef = [
|
||||
SettingsStore.watchSetting("userTimezonePublish", null, this.onTimezoneUpdate),
|
||||
SettingsStore.watchSetting("userTimezone", null, this.onTimezoneUpdate),
|
||||
];
|
||||
|
||||
this.resizer = this.createResizer();
|
||||
this.resizer.attach();
|
||||
|
||||
|
@ -190,6 +196,31 @@ class LoggedInView extends React.Component<IProps, IState> {
|
|||
this.refreshBackgroundImage();
|
||||
}
|
||||
|
||||
private onTimezoneUpdate = async (): Promise<void> => {
|
||||
if (!SettingsStore.getValue("userTimezonePublish")) {
|
||||
// Ensure it's deleted
|
||||
try {
|
||||
await this._matrixClient.deleteExtendedProfileProperty("us.cloke.msc4175.tz");
|
||||
} catch (ex) {
|
||||
console.warn("Failed to delete timezone from user profile", ex);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const currentTimezone =
|
||||
SettingsStore.getValue("userTimezone") ||
|
||||
// If the timezone is empty, then use the browser timezone.
|
||||
// eslint-disable-next-line new-cap
|
||||
Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
if (!currentTimezone || typeof currentTimezone !== "string") {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this._matrixClient.setExtendedProfileProperty("us.cloke.msc4175.tz", currentTimezone);
|
||||
} catch (ex) {
|
||||
console.warn("Failed to update user profile with current timezone", ex);
|
||||
}
|
||||
};
|
||||
|
||||
public componentWillUnmount(): void {
|
||||
document.removeEventListener("keydown", this.onNativeKeyDown, false);
|
||||
LegacyCallHandler.instance.removeListener(LegacyCallHandlerEvent.CallState, this.onCallState);
|
||||
|
@ -200,6 +231,7 @@ class LoggedInView extends React.Component<IProps, IState> {
|
|||
if (this.layoutWatcherRef) SettingsStore.unwatchSetting(this.layoutWatcherRef);
|
||||
if (this.compactLayoutWatcherRef) SettingsStore.unwatchSetting(this.compactLayoutWatcherRef);
|
||||
if (this.backgroundImageWatcherRef) SettingsStore.unwatchSetting(this.backgroundImageWatcherRef);
|
||||
this.timezoneProfileUpdateRef?.forEach((s) => SettingsStore.unwatchSetting(s));
|
||||
this.resizer?.detach();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ISSOAuthEntryProps, ISSOAuthEn
|
|||
}
|
||||
}
|
||||
|
||||
export class FallbackAuthEntry extends React.Component<IAuthEntryProps> {
|
||||
private popupWindow: Window | null;
|
||||
private fallbackButton = createRef<HTMLButtonElement>();
|
||||
export class FallbackAuthEntry<T = {}> extends React.Component<IAuthEntryProps & T> {
|
||||
protected popupWindow: Window | null;
|
||||
protected fallbackButton = createRef<HTMLButtonElement>();
|
||||
|
||||
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<IAuthEntryProps> {
|
|||
}
|
||||
}
|
||||
|
||||
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 (
|
||||
<div>
|
||||
<Text>{_t("auth|uia|mas_cross_signing_reset_description")}</Text>
|
||||
<Flex gap="var(--cpd-space-4x)">
|
||||
<Button
|
||||
Icon={PopOutIcon}
|
||||
onClick={this.onGoToAccountClick}
|
||||
autoFocus
|
||||
kind="primary"
|
||||
className="mx_Dialog_nonDialogButton"
|
||||
>
|
||||
{_t("auth|uia|mas_cross_signing_reset_cta")}
|
||||
</Button>
|
||||
<Button onClick={this.onRetryClick} kind="secondary" className="mx_Dialog_nonDialogButton">
|
||||
{_t("action|retry")}
|
||||
</Button>
|
||||
</Flex>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export interface IStageComponentProps extends IAuthEntryProps {
|
||||
stageParams?: Record<string, any>;
|
||||
inputs?: IInputs;
|
||||
|
@ -983,8 +1030,10 @@ export interface IStageComponent extends React.ComponentClass<React.PropsWithRef
|
|||
focus?(): void;
|
||||
}
|
||||
|
||||
export default function getEntryComponentForLoginType(loginType: AuthType): IStageComponent {
|
||||
export default function getEntryComponentForLoginType(loginType: AuthType | CustomAuthType): IStageComponent {
|
||||
switch (loginType) {
|
||||
case CustomAuthType.MasCrossSigningReset:
|
||||
return MasUnlockCrossSigningAuthEntry;
|
||||
case AuthType.Password:
|
||||
return PasswordAuthEntry;
|
||||
case AuthType.Recaptcha:
|
||||
|
|
|
@ -26,7 +26,7 @@ import { KnownMembership } from "matrix-js-sdk/src/types";
|
|||
import { UserVerificationStatus, VerificationRequest } from "matrix-js-sdk/src/crypto-api";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
||||
import { Heading, MenuItem, Text } from "@vector-im/compound-web";
|
||||
import { Heading, MenuItem, Text, Tooltip } from "@vector-im/compound-web";
|
||||
import ChatIcon from "@vector-im/compound-design-tokens/assets/web/icons/chat";
|
||||
import CheckIcon from "@vector-im/compound-design-tokens/assets/web/icons/check";
|
||||
import ShareIcon from "@vector-im/compound-design-tokens/assets/web/icons/share";
|
||||
|
@ -85,7 +85,7 @@ import { SdkContextClass } from "../../../contexts/SDKContext";
|
|||
import { asyncSome } from "../../../utils/arrays";
|
||||
import { Flex } from "../../utils/Flex";
|
||||
import CopyableText from "../elements/CopyableText";
|
||||
|
||||
import { useUserTimezone } from "../../../hooks/useUserTimezone";
|
||||
export interface IDevice extends Device {
|
||||
ambiguous?: boolean;
|
||||
}
|
||||
|
@ -1694,6 +1694,8 @@ export const UserInfoHeader: React.FC<{
|
|||
);
|
||||
}
|
||||
|
||||
const timezoneInfo = useUserTimezone(cli, member.userId);
|
||||
|
||||
const e2eIcon = e2eStatus ? <E2EIcon size={18} status={e2eStatus} isUser={true} /> : null;
|
||||
const userIdentifier = UserIdentifierCustomisations.getDisplayUserIdentifier?.(member.userId, {
|
||||
roomId,
|
||||
|
@ -1727,6 +1729,15 @@ export const UserInfoHeader: React.FC<{
|
|||
</Flex>
|
||||
</Heading>
|
||||
{presenceLabel}
|
||||
{timezoneInfo && (
|
||||
<Tooltip label={timezoneInfo?.timezone ?? ""}>
|
||||
<span className="mx_UserInfo_timezone">
|
||||
<Text size="sm" weight="regular">
|
||||
{timezoneInfo?.friendly ?? ""}
|
||||
</Text>
|
||||
</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Text size="sm" weight="semibold" className="mx_UserInfo_profile_mxid">
|
||||
<CopyableText getTextToCopy={() => userIdentifier} border={false}>
|
||||
{userIdentifier}
|
||||
|
|
|
@ -302,6 +302,7 @@ export default class PreferencesUserSettingsTab extends React.Component<IProps,
|
|||
</div>
|
||||
|
||||
{this.renderGroup(PreferencesUserSettingsTab.TIME_SETTINGS)}
|
||||
<SettingsFlag name="userTimezonePublish" level={SettingLevel.DEVICE} />
|
||||
</SettingsSubsection>
|
||||
|
||||
<SettingsSubsection
|
||||
|
|
|
@ -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<MatrixEvent | null> => 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,
|
||||
);
|
||||
|
|
106
src/hooks/useUserTimezone.ts
Normal file
106
src/hooks/useUserTimezone.ts
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
Copyright 2024 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { useEffect, useState } from "react";
|
||||
import { MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
/**
|
||||
* Fetch a user's delclared timezone through their profile, and return
|
||||
* a friendly string of the current time for that user. This will keep
|
||||
* in sync with the current time, and will be refreshed once a minute.
|
||||
*
|
||||
* @param cli The Matrix Client instance.
|
||||
* @param userId The userID to fetch the timezone for.
|
||||
* @returns A timezone name and friendly string for the user's timezone, or
|
||||
* null if the user has no timezone or the timezone was not recognised
|
||||
* by the browser.
|
||||
*/
|
||||
export const useUserTimezone = (cli: MatrixClient, userId: string): { timezone: string; friendly: string } | null => {
|
||||
const [timezone, setTimezone] = useState<string>();
|
||||
const [updateInterval, setUpdateInterval] = useState<ReturnType<typeof setTimeout>>();
|
||||
const [friendly, setFriendly] = useState<string>();
|
||||
const [supported, setSupported] = useState<boolean>();
|
||||
|
||||
useEffect(() => {
|
||||
if (!cli || supported !== undefined) {
|
||||
return;
|
||||
}
|
||||
cli.doesServerSupportExtendedProfiles()
|
||||
.then(setSupported)
|
||||
.catch((ex) => {
|
||||
console.warn("Unable to determine if extended profiles are supported", ex);
|
||||
});
|
||||
}, [supported, cli]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (updateInterval) {
|
||||
clearInterval(updateInterval);
|
||||
}
|
||||
};
|
||||
}, [updateInterval]);
|
||||
|
||||
useEffect(() => {
|
||||
if (supported !== true) {
|
||||
return;
|
||||
}
|
||||
(async () => {
|
||||
console.log("Trying to fetch TZ");
|
||||
try {
|
||||
const tz = await cli.getExtendedProfileProperty(userId, "us.cloke.msc4175.tz");
|
||||
if (typeof tz !== "string") {
|
||||
// Err, definitely not a tz.
|
||||
throw Error("Timezone value was not a string");
|
||||
}
|
||||
// This will validate the timezone for us.
|
||||
// eslint-disable-next-line new-cap
|
||||
Intl.DateTimeFormat(undefined, { timeZone: tz });
|
||||
|
||||
const updateTime = (): void => {
|
||||
const currentTime = new Date();
|
||||
const friendly = currentTime.toLocaleString(undefined, {
|
||||
timeZone: tz,
|
||||
hour12: true,
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
timeZoneName: "shortOffset",
|
||||
});
|
||||
setTimezone(tz);
|
||||
setFriendly(friendly);
|
||||
setUpdateInterval(setTimeout(updateTime, (60 - currentTime.getSeconds()) * 1000));
|
||||
};
|
||||
updateTime();
|
||||
} catch (ex) {
|
||||
setTimezone(undefined);
|
||||
setFriendly(undefined);
|
||||
setUpdateInterval(undefined);
|
||||
if (ex instanceof MatrixError && ex.errcode === "M_NOT_FOUND") {
|
||||
// No timezone set, ignore.
|
||||
return;
|
||||
}
|
||||
console.error("Could not render current timezone for user", ex);
|
||||
}
|
||||
})();
|
||||
}, [supported, userId, cli]);
|
||||
|
||||
if (!timezone || !friendly) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
friendly,
|
||||
timezone,
|
||||
};
|
||||
};
|
|
@ -369,6 +369,8 @@
|
|||
"email_resend_prompt": "Did not receive it? <a>Resend it</a>",
|
||||
"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:",
|
||||
|
@ -1426,6 +1428,7 @@
|
|||
"element_call_video_rooms": "Element Call video rooms",
|
||||
"experimental_description": "Feeling experimental? Try out our latest ideas in development. These features are not finalised; they may be unstable, may change, or may be dropped altogether. <a>Learn more</a>.",
|
||||
"experimental_section": "Early previews",
|
||||
"extended_profiles_msc_support": "Requires your server to support MSC4133",
|
||||
"feature_disable_call_per_sender_encryption": "Disable per-sender encryption for Element Call",
|
||||
"feature_wysiwyg_composer_description": "Use rich text instead of Markdown in the message composer.",
|
||||
"group_calls": "New group call experience",
|
||||
|
@ -2719,6 +2722,7 @@
|
|||
"keyboard_view_shortcuts_button": "To view all keyboard shortcuts, <a>click here</a>.",
|
||||
"media_heading": "Images, GIFs and videos",
|
||||
"presence_description": "Share your activity and status with others.",
|
||||
"publish_timezone": "Publish timezone on public profile",
|
||||
"rm_lifetime": "Read Marker lifetime (ms)",
|
||||
"rm_lifetime_offscreen": "Read Marker off-screen lifetime (ms)",
|
||||
"room_directory_heading": "Room directory",
|
||||
|
|
|
@ -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)",
|
||||
|
|
|
@ -8,6 +8,7 @@ Please see LICENSE files in the repository root for full details.
|
|||
*/
|
||||
|
||||
import React, { ReactNode } from "react";
|
||||
import { UNSTABLE_MSC4133_EXTENDED_PROFILES } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { _t, _td, TranslationKey } from "../languageHandler";
|
||||
import {
|
||||
|
@ -641,6 +642,19 @@ export const SETTINGS: { [setting: string]: ISetting } = {
|
|||
displayName: _td("settings|preferences|user_timezone"),
|
||||
default: "",
|
||||
},
|
||||
"userTimezonePublish": {
|
||||
// This is per-device so you can avoid having devices overwrite each other.
|
||||
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
|
||||
displayName: _td("settings|preferences|publish_timezone"),
|
||||
default: false,
|
||||
controller: new ServerSupportUnstableFeatureController(
|
||||
"userTimezonePublish",
|
||||
defaultWatchManager,
|
||||
[[UNSTABLE_MSC4133_EXTENDED_PROFILES]],
|
||||
undefined,
|
||||
_td("labs|extended_profiles_msc_support"),
|
||||
),
|
||||
},
|
||||
"autoplayGifs": {
|
||||
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
||||
displayName: _td("settings|autoplay_gifs"),
|
||||
|
|
|
@ -40,3 +40,18 @@ export async function retry<T, E extends Error>(
|
|||
}
|
||||
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<T>(funcs: Array<() => Promise<T>>, batchSize: number): Promise<T[]> {
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue