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

Linkify room topic #11631

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/views/rooms/RoomHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { useRoomState } from "../../../hooks/useRoomState";
import RoomAvatar from "../avatars/RoomAvatar";
import { formatCount } from "../../../utils/FormattingUtils";
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
import { Linkify, topicToHtml } from "../../../HtmlUtils";

/**
* A helper to transform a notification color to the what the Compound Icon Button
Expand Down Expand Up @@ -100,6 +101,11 @@ export default function RoomHeader({ room }: { room: Room }): JSX.Element {

const notificationsEnabled = useFeatureEnabled("feature_notifications");

const roomTopicBody = useMemo(
() => topicToHtml(roomTopic?.text, roomTopic?.html),
[roomTopic?.html, roomTopic?.text],
);

return (
<Flex
as="header"
Expand Down Expand Up @@ -159,7 +165,7 @@ export default function RoomHeader({ room }: { room: Room }): JSX.Element {
</BodyText>
{roomTopic && (
<BodyText as="div" size="sm" className="mx_RoomHeader_topic">
{roomTopic.text}
<Linkify>{roomTopicBody}</Linkify>
</BodyText>
)}
</Box>
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/room/useTopic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const getTopic = (room?: Room): Optional<ContentHelpers.TopicState> => {
return !!content ? ContentHelpers.parseTopicContent(content) : null;
};

/**
* Helper to retrieve the room topic for given room
* @param room
* @returns the raw text and an html parsion version of the room topic
*/
export function useTopic(room?: Room): Optional<ContentHelpers.TopicState> {
const [topic, setTopic] = useState(getTopic(room));
useTypedEventEmitter(room?.currentState, RoomStateEvent.Events, (ev: MatrixEvent) => {
Expand Down
4 changes: 3 additions & 1 deletion test/components/views/rooms/RoomHeader-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
fireEvent,
getAllByLabelText,
getByLabelText,
getByRole,
getByText,
render,
screen,
Expand Down Expand Up @@ -78,7 +79,7 @@ describe("RoomHeader", () => {
});

it("renders the room topic", async () => {
const TOPIC = "Hello World!";
const TOPIC = "Hello World! http://element.io";

const roomTopic = new MatrixEvent({
type: EventType.RoomTopic,
Expand All @@ -96,6 +97,7 @@ describe("RoomHeader", () => {
withClientContextRenderOptions(MatrixClientPeg.get()!),
);
expect(container).toHaveTextContent(TOPIC);
expect(getByRole(container, "link")).toHaveTextContent("http://element.io");
});

it("opens the room summary", async () => {
Expand Down
Loading