Review changes
This commit is contained in:
@@ -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.
|
||||
|
||||
3
src/@types/matrix-js-sdk.d.ts
vendored
3
src/@types/matrix-js-sdk.d.ts
vendored
@@ -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": {
|
||||
|
||||
@@ -29,5 +29,5 @@ export interface MediaPreviewConfig extends Record<string, unknown> {
|
||||
/**
|
||||
* Media preview settings for avatars of rooms we have been invited to.
|
||||
*/
|
||||
invite_avatars: MediaPreviewValue;
|
||||
invite_avatars: MediaPreviewValue.On | MediaPreviewValue.Off;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ interface IProps extends Omit<ComponentProps<typeof BaseAvatar>, "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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<JoinRule> {
|
||||
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<JoinRule> {
|
||||
setJoinRule(room?.getJoinRule());
|
||||
}, [room]);
|
||||
|
||||
return topic;
|
||||
return joinRule;
|
||||
}
|
||||
|
||||
@@ -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<string> {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user