Skip to content

Commit

Permalink
fix(#81): room name getter (#89)
Browse files Browse the repository at this point in the history
* fix(#81): room name getter

* chore: sync compoments
  • Loading branch information
ifaouibadi authored Apr 1, 2024
1 parent dcfc8e1 commit 5bda245
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/components/views/elements/RoomName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import React, { useCallback, useMemo } from "react";

import { Icon as TokenGatedRoomIcon } from "../../../../res/themes/superhero/img/icons/tokengated-room.svg";
import { Icon as CommunityRoomIcon } from "../../../../res/themes/superhero/img/icons/community-room.svg";
import { useRoomName } from "../../../hooks/useRoomName";
import { getRoomName } from "../../../hooks/useRoomName";
import { useVerifiedRoom } from "../../../hooks/useVerifiedRoom";
import { UserVerifiedBadge } from "./UserVerifiedBadge";
import { BotVerifiedBadge } from "./BotVerifiedBadge";
Expand All @@ -31,7 +31,7 @@ interface IProps {
}

export const RoomName = ({ room, children, maxLength }: IProps): JSX.Element => {
const roomName = useRoomName(room);
const roomName = getRoomName(room);
const { isTokenGatedRoom, isCommunityRoom } = useVerifiedRoom(room);

const roomUser: string | undefined = useMemo(() => {
Expand Down
13 changes: 4 additions & 9 deletions src/components/views/right_panel/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ const MuteToggleButton: React.FC<IBaseRoomProps> = ({
return;
}

cli.setPowerLevel(roomId, target, level, powerLevelEvent)
cli.setPowerLevel(roomId, target, level)
.then(
() => {
// NO-OP; rely on the m.room.member event coming down else we could
Expand Down Expand Up @@ -1123,13 +1123,8 @@ export const PowerLevelEditor: React.FC<{
async (powerLevel: number) => {
setSelectedPowerLevel(powerLevel);

const applyPowerChange = (
roomId: string,
target: string,
powerLevel: number,
powerLevelEvent: MatrixEvent,
): Promise<unknown> => {
return cli.setPowerLevel(roomId, target, powerLevel, powerLevelEvent).then(
const applyPowerChange = (roomId: string, target: string, powerLevel: number): Promise<unknown> => {
return cli.setPowerLevel(roomId, target, powerLevel).then(
function () {
// NO-OP; rely on the m.room.member event coming down else we could
// get out of sync if we force setState here!
Expand Down Expand Up @@ -1177,7 +1172,7 @@ export const PowerLevelEditor: React.FC<{
}
}

await applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
await applyPowerChange(roomId, target, powerLevel);
},
[user.roomId, user.userId, cli, room],
);
Expand Down
15 changes: 15 additions & 0 deletions src/components/views/spaces/SpacePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ const OrphansButton: React.FC<MetaSpaceButtonProps> = ({ selected, isPanelCollap
);
};

const VideoRoomsButton: React.FC<MetaSpaceButtonProps> = ({ selected, isPanelCollapsed }) => {
return (
<MetaSpaceButton
spaceKey={MetaSpace.VideoRooms}
className="mx_SpaceButton_videoRooms"
selected={selected}
isPanelCollapsed={isPanelCollapsed}
label={getMetaSpaceName(MetaSpace.VideoRooms)}
notificationState={SpaceStore.instance.getNotificationState(MetaSpace.VideoRooms)}
size="32px"
/>
);
};

const CreateSpaceButton: React.FC<Pick<IInnerSpacePanelProps, "isPanelCollapsed" | "setPanelCollapsed">> = ({
isPanelCollapsed,
setPanelCollapsed,
Expand Down Expand Up @@ -264,6 +278,7 @@ const metaSpaceComponentMap: Record<MetaSpace, typeof HomeButton> = {
[MetaSpace.Favourites]: FavouritesButton,
[MetaSpace.People]: PeopleButton,
[MetaSpace.Orphans]: OrphansButton,
[MetaSpace.VideoRooms]: VideoRoomsButton,
};

interface IInnerSpacePanelProps extends DroppableProvidedProps {
Expand Down
18 changes: 0 additions & 18 deletions src/hooks/useRoomName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 @@ -33,20 +32,3 @@ 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 5bda245

Please sign in to comment.