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

Commit

Permalink
Add safety around missing topics and space settings (#8957)
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live authored Jun 30, 2022
1 parent 3329b35 commit 924865b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/views/spaces/SpaceSettingsGeneralTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const SpaceSettingsGeneralTab = ({ matrixClient: cli, space, onFinished }: IProp
const canSetName = space.currentState.maySendStateEvent(EventType.RoomName, userId);
const nameChanged = name !== space.name;

const currentTopic = getTopic(space).text;
const currentTopic = getTopic(space)?.text;
const [topic, setTopic] = useState<string>(currentTopic);
const canSetTopic = space.currentState.maySendStateEvent(EventType.RoomTopic, userId);
const topicChanged = topic !== currentTopic;
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/room/useTopic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { parseTopicContent, TopicState } from "matrix-js-sdk/src/content-helpers";
import { MRoomTopicEventContent } from "matrix-js-sdk/src/@types/topic";
import { Optional } from "matrix-events-sdk";

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

export const getTopic = (room: Room) => {
export const getTopic = (room: Room): Optional<TopicState> => {
const content: MRoomTopicEventContent = room?.currentState?.getStateEvents(EventType.RoomTopic, "")?.getContent();
return !!content ? parseTopicContent(content) : null;
};
Expand Down

0 comments on commit 924865b

Please sign in to comment.