From 0202ef7bd82fad027a5ed9948750a80821403369 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Fri, 11 Apr 2025 10:50:21 +0100 Subject: [PATCH] Review changes --- .../e2e/timeline/media-preview-settings.spec.ts | 3 +-- src/@types/matrix-js-sdk.d.ts | 3 ++- src/@types/media_preview.ts | 2 +- src/components/views/avatars/RoomAvatar.tsx | 2 +- src/components/views/messages/EventContentBody.tsx | 2 +- src/hooks/room/useJoinRule.ts | 8 ++++---- src/hooks/room/useRoomAvatar.ts | 11 +++++------ src/hooks/useMediaVisible.ts | 2 +- .../controllers/MediaPreviewConfigController.ts | 11 ++++++----- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/playwright/e2e/timeline/media-preview-settings.spec.ts b/playwright/e2e/timeline/media-preview-settings.spec.ts index 04e8f46e8d..1d241bd0a1 100644 --- a/playwright/e2e/timeline/media-preview-settings.spec.ts +++ b/playwright/e2e/timeline/media-preview-settings.spec.ts @@ -1,6 +1,5 @@ /* -Copyright 2024, 2025 New Vector Ltd. -Copyright 2022, 2023 The Matrix.org Foundation C.I.C. +Copyright 2025 New Vector Ltd. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial Please see LICENSE files in the repository root for full details. diff --git a/src/@types/matrix-js-sdk.d.ts b/src/@types/matrix-js-sdk.d.ts index dfd46237f4..c81c5377bf 100644 --- a/src/@types/matrix-js-sdk.d.ts +++ b/src/@types/matrix-js-sdk.d.ts @@ -1,5 +1,5 @@ /* -Copyright 2025 New Vector Ltd. +Copyright 2024, 2025 New Vector Ltd. Copyright 2024 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial @@ -60,6 +60,7 @@ declare module "matrix-js-sdk/src/types" { }; }; } + export interface AccountDataEvents { // Analytics account data event "im.vector.analytics": { diff --git a/src/@types/media_preview.ts b/src/@types/media_preview.ts index f0f2ce006f..d340e64caf 100644 --- a/src/@types/media_preview.ts +++ b/src/@types/media_preview.ts @@ -29,5 +29,5 @@ export interface MediaPreviewConfig extends Record { /** * Media preview settings for avatars of rooms we have been invited to. */ - invite_avatars: MediaPreviewValue; + invite_avatars: MediaPreviewValue.On | MediaPreviewValue.Off; } diff --git a/src/components/views/avatars/RoomAvatar.tsx b/src/components/views/avatars/RoomAvatar.tsx index e2b6add884..4d07b6adb3 100644 --- a/src/components/views/avatars/RoomAvatar.tsx +++ b/src/components/views/avatars/RoomAvatar.tsx @@ -27,7 +27,7 @@ interface IProps extends Omit, "name" | "idNam // oobData.avatarUrl should be set (else there // would be nowhere to get the avatar from) room?: Room; - oobData: IOOBData & { + oobData?: IOOBData & { roomId?: string; }; viewAvatarOnClick?: boolean; diff --git a/src/components/views/messages/EventContentBody.tsx b/src/components/views/messages/EventContentBody.tsx index 5bbe9fc3c7..66ff7915ea 100644 --- a/src/components/views/messages/EventContentBody.tsx +++ b/src/components/views/messages/EventContentBody.tsx @@ -171,7 +171,7 @@ const EventContentBody = memo( stripReplyFallback: stripReply, mediaIsVisible, }), - [content, enableBigEmoji, highlights, isEmote, stripReply], + [content, mediaIsVisible, enableBigEmoji, highlights, isEmote, stripReply], ); if (as === "div") includeDir = true; // force dir="auto" on divs diff --git a/src/hooks/room/useJoinRule.ts b/src/hooks/room/useJoinRule.ts index f027ffe4cd..3e66f3beeb 100644 --- a/src/hooks/room/useJoinRule.ts +++ b/src/hooks/room/useJoinRule.ts @@ -7,7 +7,6 @@ Please see LICENSE files in the repository root for full details. import { useEffect, useState } from "react"; import { EventType, type MatrixEvent, type Room, RoomStateEvent, type JoinRule } from "matrix-js-sdk/src/matrix"; -import { type Optional } from "matrix-events-sdk"; import { useTypedEventEmitter } from "../useEventEmitter"; @@ -16,8 +15,9 @@ import { useTypedEventEmitter } from "../useEventEmitter"; * @param room * @returns the current join rule */ -export function useJoinRule(room?: Room): Optional { - const [topic, setJoinRule] = useState(room?.getJoinRule()); + +export function useJoinRule(room?: Room): JoinRule | undefined { + const [joinRule, setJoinRule] = useState(room?.getJoinRule()); useTypedEventEmitter(room?.currentState, RoomStateEvent.Events, (ev: MatrixEvent) => { if (ev.getType() !== EventType.RoomJoinRules) return; setJoinRule(room?.getJoinRule()); @@ -26,5 +26,5 @@ export function useJoinRule(room?: Room): Optional { setJoinRule(room?.getJoinRule()); }, [room]); - return topic; + return joinRule; } diff --git a/src/hooks/room/useRoomAvatar.ts b/src/hooks/room/useRoomAvatar.ts index 9236654cca..850f699739 100644 --- a/src/hooks/room/useRoomAvatar.ts +++ b/src/hooks/room/useRoomAvatar.ts @@ -7,7 +7,6 @@ Please see LICENSE files in the repository root for full details. import { useEffect, useState } from "react"; import { EventType, type MatrixEvent, type Room, RoomStateEvent } from "matrix-js-sdk/src/matrix"; -import { type Optional } from "matrix-events-sdk"; import { useTypedEventEmitter } from "../useEventEmitter"; @@ -16,15 +15,15 @@ import { useTypedEventEmitter } from "../useEventEmitter"; * @param room * @returns the current avatar */ -export function useRoomAvatar(room?: Room): Optional { - const [topic, setAvatar] = useState(room?.getMxcAvatarUrl()); +export function useRoomAvatar(room?: Room): string | undefined { + const [avatarMxc, setAvatar] = useState(room?.getMxcAvatarUrl() ?? undefined); useTypedEventEmitter(room?.currentState, RoomStateEvent.Events, (ev: MatrixEvent) => { if (ev.getType() !== EventType.RoomAvatar) return; - setAvatar(room?.getMxcAvatarUrl()); + setAvatar(room?.getMxcAvatarUrl() ?? undefined); }); useEffect(() => { - setAvatar(room?.getMxcAvatarUrl()); + setAvatar(room?.getMxcAvatarUrl() ?? undefined); }, [room]); - return topic; + return avatarMxc; } diff --git a/src/hooks/useMediaVisible.ts b/src/hooks/useMediaVisible.ts index 5626c30bc3..f7f5e487af 100644 --- a/src/hooks/useMediaVisible.ts +++ b/src/hooks/useMediaVisible.ts @@ -26,7 +26,7 @@ export function useMediaVisible(eventId?: string, roomId?: string): [boolean, (v const mediaPreviewSetting = useSettingValue("mediaPreviewConfig", roomId); const client = useMatrixClientContext(); const eventVisibility = useSettingValue("showMediaEventIds"); - const joinRule = useJoinRule(client.getRoom(roomId) ?? undefined); + const joinRule = useJoinRule(client?.getRoom(roomId) ?? undefined); const setMediaVisible = useCallback( (visible: boolean) => { SettingsStore.setValue("showMediaEventIds", null, SettingLevel.DEVICE, { diff --git a/src/settings/controllers/MediaPreviewConfigController.ts b/src/settings/controllers/MediaPreviewConfigController.ts index ec9a234aaa..52ff9e032e 100644 --- a/src/settings/controllers/MediaPreviewConfigController.ts +++ b/src/settings/controllers/MediaPreviewConfigController.ts @@ -27,14 +27,15 @@ export default class MediaPreviewConfigController extends MatrixClientBackedCont }; private static getValidSettingData(content: IContent): MediaPreviewConfig { - const mediaPreviews: MediaPreviewValue = content.media_previews; - const inviteAvatars: MediaPreviewValue = content.invite_avatars; - const validValues = Object.values(MediaPreviewValue); + const mediaPreviews: MediaPreviewConfig["media_previews"] = content.media_previews; + const inviteAvatars: MediaPreviewConfig["invite_avatars"] = content.invite_avatars; + const validMediaPreviews = Object.values(MediaPreviewValue); + const validInviteAvatars = [MediaPreviewValue.Off, MediaPreviewValue.On]; return { - invite_avatars: validValues.includes(inviteAvatars) + invite_avatars: validMediaPreviews.includes(inviteAvatars) ? inviteAvatars : MediaPreviewConfigController.default.invite_avatars, - media_previews: validValues.includes(mediaPreviews) + media_previews: validInviteAvatars.includes(mediaPreviews) ? mediaPreviews : MediaPreviewConfigController.default.media_previews, };