Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 924865b

Browse files
authored
Add safety around missing topics and space settings (#8957)
1 parent 3329b35 commit 924865b

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/components/views/spaces/SpaceSettingsGeneralTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const SpaceSettingsGeneralTab = ({ matrixClient: cli, space, onFinished }: IProp
4848
const canSetName = space.currentState.maySendStateEvent(EventType.RoomName, userId);
4949
const nameChanged = name !== space.name;
5050

51-
const currentTopic = getTopic(space).text;
51+
const currentTopic = getTopic(space)?.text;
5252
const [topic, setTopic] = useState<string>(currentTopic);
5353
const canSetTopic = space.currentState.maySendStateEvent(EventType.RoomTopic, userId);
5454
const topicChanged = topic !== currentTopic;

src/hooks/room/useTopic.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import { Room } from "matrix-js-sdk/src/models/room";
2121
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
2222
import { parseTopicContent, TopicState } from "matrix-js-sdk/src/content-helpers";
2323
import { MRoomTopicEventContent } from "matrix-js-sdk/src/@types/topic";
24+
import { Optional } from "matrix-events-sdk";
2425

2526
import { useTypedEventEmitter } from "../useEventEmitter";
2627

27-
export const getTopic = (room: Room) => {
28+
export const getTopic = (room: Room): Optional<TopicState> => {
2829
const content: MRoomTopicEventContent = room?.currentState?.getStateEvents(EventType.RoomTopic, "")?.getContent();
2930
return !!content ? parseTopicContent(content) : null;
3031
};

0 commit comments

Comments
 (0)