Skip to content

Commit

Permalink
chore: fix use room name
Browse files Browse the repository at this point in the history
  • Loading branch information
ifaouibadi committed Apr 15, 2024
1 parent 61cb051 commit 9273cc2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/hooks/useRoomName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IPublicRoomsChunkRoom, Room } from "matrix-js-sdk/src/matrix";
import { getDisplayAliasForAliasSet } from "matrix-react-sdk/src/Rooms";
import { _t } from "matrix-react-sdk/src/languageHandler";
import { IOOBData } from "matrix-react-sdk/src/stores/ThreepidInviteStore";
import { useMemo } from "react";

/**
* Removes the [TG] prefix and leading whitespace from a room name
Expand Down Expand Up @@ -32,3 +33,21 @@ export function getRoomName(room?: Room | IPublicRoomsChunkRoom, oobName?: IOOBD
(roomName || "").replace(":", ":\u200b"), // add a zero-width space to allow linewrapping after the colon (matrix defaults)
);
}


/**
* Determines the room name from a combination of the room model and potential
* out-of-band information
* @param room - The room model
* @param oobData - out-of-band information about the room
* @returns {string} the room name
*
* TODO: check if useTypedEventEmitter is needed
*/
export function useRoomName(room?: Room | IPublicRoomsChunkRoom, oobData?: IOOBData): string {
const name = useMemo(() => {
return getRoomName(room, oobData);
}, [room, oobData]);

return name;
}

0 comments on commit 9273cc2

Please sign in to comment.