From da123e53d670d1b2154ed32871de4638d9a910d7 Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Wed, 12 Aug 2026 23:33:41 +0200 Subject: [PATCH] fix: adapt forum view to current dev APIs --- src/app/components/message/modals/Options.tsx | 32 ++++++++------- .../components/upload-board/UploadBoard.tsx | 5 +-- src/app/features/forum/ForumHeader.tsx | 8 +++- src/app/features/forum/ForumMenu.tsx | 41 +------------------ src/app/features/forum/ForumThreadItem.tsx | 4 +- src/app/features/forum/ForumView.tsx | 7 ++-- src/app/features/lobby/SpaceItem.tsx | 10 ----- src/app/features/room/ThreadRootItem.tsx | 3 +- src/app/pages/pathUtils.ts | 14 +++++++ 9 files changed, 49 insertions(+), 75 deletions(-) diff --git a/src/app/components/message/modals/Options.tsx b/src/app/components/message/modals/Options.tsx index a245bd096..25489401b 100644 --- a/src/app/components/message/modals/Options.tsx +++ b/src/app/components/message/modals/Options.tsx @@ -598,6 +598,7 @@ export type OptionMenuProps = { onEditId?: (eventId?: string) => void; onReproxyId?: (profileId?: string) => void; hideReadReceipts?: boolean; + hideReplyButton?: boolean; showDeveloperTools?: boolean; canPinEvent?: boolean; canDelete?: boolean; @@ -622,6 +623,7 @@ function OptionMenu({ onReplyClick, onEditId, hideReadReceipts, + hideReplyButton, showDeveloperTools, canPinEvent, canDelete, @@ -808,20 +810,22 @@ function OptionMenu({ {isGif && isModal && ( )} - { - onReplyClick(evt); - onTotalClose(); - }} - > - - Reply - - + {!hideReplyButton && ( + { + onReplyClick(evt); + onTotalClose(); + }} + > + + Reply + + + )} {!isThreadedMessage && ( ( ({ header, showUploadCardBottom, children, ...props }, ref) => ( - + {children} diff --git a/src/app/features/forum/ForumHeader.tsx b/src/app/features/forum/ForumHeader.tsx index a0c60da68..6175469fb 100644 --- a/src/app/features/forum/ForumHeader.tsx +++ b/src/app/features/forum/ForumHeader.tsx @@ -35,11 +35,17 @@ import { BackRouteHandler } from '$components/BackRouteHandler'; import { mxcUrlToHttp } from '$utils/matrix'; import { useMediaAuthentication } from '$hooks/useMediaAuthentication'; import { useRoomPinnedEvents } from '$hooks/useRoomPinnedEvents'; -import { getPinsHash } from '$utils/room'; import { RoomPinMenu } from '$features/room/room-pin-menu'; import { ForumMenu } from './ForumMenu'; import * as css from './ForumView.css'; +const getPinsHash = async (pinnedIds: string[]): Promise => + crypto.subtle + .digest('SHA-256', new TextEncoder().encode(pinnedIds.join())) + .then((hash) => + Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, '0')).join('') + ); + type ForumHeaderProps = { room: Room; showProfile?: boolean; diff --git a/src/app/features/forum/ForumMenu.tsx b/src/app/features/forum/ForumMenu.tsx index b63234868..cb30d21d1 100644 --- a/src/app/features/forum/ForumMenu.tsx +++ b/src/app/features/forum/ForumMenu.tsx @@ -2,8 +2,6 @@ import { forwardRef, useState } from 'react'; import { Box, Line, Menu, MenuItem, Text, config, toRem } from 'folds'; import type { Room } from 'matrix-js-sdk'; import { useNavigate } from 'react-router-dom'; -import { UseStateProvider } from '$components/UseStateProvider'; -import { LeaveRoomPrompt } from '$components/leave-room-prompt'; import { InviteUserPrompt } from '$components/invite-user-prompt'; import { useMatrixClient } from '$hooks/useMatrixClient'; import { useIsDirectRoom } from '$hooks/useRoom'; @@ -20,15 +18,7 @@ import { getCanonicalAliasOrRoomId, isRoomAlias } from '$utils/matrix'; import { getHomeRoomPath, getDirectRoomPath, getSpaceRoomPath } from '$pages/pathUtils'; import { getMatrixToRoom } from '$plugins/matrix-to'; import { getViaServers } from '$plugins/via-servers'; -import { - Checks, - GearSix, - Link, - menuIcon, - SignOut, - Terminal, - UserPlus, -} from '$components/icons/phosphor'; +import { Checks, GearSix, Link, menuIcon, Terminal, UserPlus } from '$components/icons/phosphor'; type ForumMenuProps = { room: Room; @@ -141,35 +131,6 @@ export const ForumMenu = forwardRef( )} - - - - {(promptLeave, setPromptLeave) => ( - <> - setPromptLeave(true)} - variant="Critical" - fill="None" - size="300" - after={menuIcon(SignOut)} - radii="300" - aria-pressed={promptLeave} - > - - Leave Room - - - {promptLeave && ( - setPromptLeave(false)} - /> - )} - - )} - - ); } diff --git a/src/app/features/forum/ForumThreadItem.tsx b/src/app/features/forum/ForumThreadItem.tsx index 192f02e1a..d63fc07ba 100644 --- a/src/app/features/forum/ForumThreadItem.tsx +++ b/src/app/features/forum/ForumThreadItem.tsx @@ -3,13 +3,13 @@ import type { Thread } from 'matrix-js-sdk/lib/models/thread'; import { useAtomValue } from 'jotai'; import { useMatrixClient } from '$hooks/useMatrixClient'; import { useMediaAuthentication } from '$hooks/useMediaAuthentication'; -import { getMemberAvatarMxc, getMemberDisplayName } from '$utils/room'; +import { getMemberAvatarMxc, getMemberDisplayName } from '$utils/room/display'; import { getMxIdLocalPart, mxcUrlToHttp } from '$utils/matrix'; import { UserAvatar } from '$components/user-avatar'; import { nicknamesAtom } from '$state/nicknames'; import type { ThreadRootItemProps } from '$features/room/ThreadRootItem'; import { ThreadRootItem } from '$features/room/ThreadRootItem'; -import { getThreadReplyEvents } from '$features/room/ThreadDrawer'; +import { getThreadReplyEvents } from '$utils/room/relations'; import * as css from './ForumView.css'; type ForumThreadItemProps = ThreadRootItemProps & { diff --git a/src/app/features/forum/ForumView.tsx b/src/app/features/forum/ForumView.tsx index 5d908cbc6..da4402c33 100644 --- a/src/app/features/forum/ForumView.tsx +++ b/src/app/features/forum/ForumView.tsx @@ -14,7 +14,7 @@ import { useMatrixClient } from '$hooks/useMatrixClient'; import { Page, PageContent, PageContentCenter, PageHeroSection } from '$components/page'; import { CaretUp, Chats, composerIcon, sizedIcon } from '$components/icons/phosphor'; import { MembersDrawer } from '$features/room/MembersDrawer'; -import { ThreadDrawer, getThreadReplyEvents } from '$features/room/ThreadDrawer'; +import { ThreadDrawer } from '$features/room/ThreadDrawer'; import { useSetting } from '$state/hooks/settings'; import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize'; import { settingsAtom } from '$state/settings'; @@ -26,7 +26,7 @@ import { PowerLevelsContextProvider, usePowerLevels } from '$hooks/usePowerLevel import { roomIdToOpenThreadAtomFamily } from '$state/room/roomToOpenThread'; import { useMediaAuthentication } from '$hooks/useMediaAuthentication'; import { useRoomMembers } from '$hooks/useRoomMembers'; -import { reactionOrEditEvent } from '$utils/room'; +import { getThreadReplyEvents, reactionOrEditEvent } from '$utils/room/relations'; import { mxcUrlToHttp, toggleReaction } from '$utils/matrix'; import { useStateEvent } from '$hooks/useStateEvent'; import { useRoomCreators } from '$hooks/useRoomCreators'; @@ -341,6 +341,7 @@ export function ForumView() { room.roomId, undefined, userId, + undefined, evt.currentTarget.getBoundingClientRect() ); }, @@ -358,6 +359,7 @@ export function ForumView() { room.roomId, undefined, userId, + undefined, evt.currentTarget.getBoundingClientRect() ); }, @@ -467,7 +469,6 @@ export function ForumView() { editor={editor} roomId={room.roomId} fileDropContainerRef={roomViewRef} - showUploadCardBottom /> )} {!canMessage && ( diff --git a/src/app/features/lobby/SpaceItem.tsx b/src/app/features/lobby/SpaceItem.tsx index 84d1b11a2..b1219309d 100644 --- a/src/app/features/lobby/SpaceItem.tsx +++ b/src/app/features/lobby/SpaceItem.tsx @@ -270,16 +270,6 @@ function AddRoomButton({ item }: { item: HierarchyItem }) { > New Room - handleCreateRoom(CreateRoomType.ForumRoom)} - after={} - > - Forum Room - Existing Room diff --git a/src/app/features/room/ThreadRootItem.tsx b/src/app/features/room/ThreadRootItem.tsx index 84b139129..11697c54e 100644 --- a/src/app/features/room/ThreadRootItem.tsx +++ b/src/app/features/room/ThreadRootItem.tsx @@ -8,7 +8,8 @@ import type { HTMLReactParserOptions } from 'html-react-parser'; import type { Opts as LinkifyOpts } from 'linkifyjs'; import { Image } from '$components/media'; import { ImageViewer } from '$components/image-viewer'; -import { getEditedEvent, getEventReactions, getMemberDisplayName } from '$utils/room'; +import { getMemberDisplayName } from '$utils/room/display'; +import { getEditedEvent, getEventReactions } from '$utils/room/relations'; import { getMxIdLocalPart } from '$utils/matrix'; import { ImageContent, MSticker, RedactedContent, Reply } from '$components/message'; import { RenderMessageContent } from '$components/RenderMessageContent'; diff --git a/src/app/pages/pathUtils.ts b/src/app/pages/pathUtils.ts index 7cc514914..124201e4b 100644 --- a/src/app/pages/pathUtils.ts +++ b/src/app/pages/pathUtils.ts @@ -33,6 +33,9 @@ import { NAVIGATE_PATH, PROFILE_PATH, INBOX_BOOKMARKS_PATH, + HOME_ROOM_FORUM_PATH, + DIRECT_ROOM_FORUM_PATH, + SPACE_ROOM_FORUM_PATH, } from './paths'; export const joinPathComponent = (path: Path): string => path.pathname + path.search + path.hash; @@ -108,6 +111,9 @@ export const getHomeRoomPath = (roomIdOrAlias: string, eventId?: string): string return generatePath(HOME_ROOM_PATH, params); }; +export const getHomeForumPath = (roomIdOrAlias: string): string => + generatePath(HOME_ROOM_FORUM_PATH, { roomIdOrAlias: encodeURIComponent(roomIdOrAlias) }); + export const getDirectPath = (): string => DIRECT_PATH; export const getDirectCreatePath = (): string => DIRECT_CREATE_PATH; export const getDirectRoomPath = (roomIdOrAlias: string, eventId?: string): string => { @@ -119,6 +125,9 @@ export const getDirectRoomPath = (roomIdOrAlias: string, eventId?: string): stri return generatePath(DIRECT_ROOM_PATH, params); }; +export const getDirectForumPath = (roomIdOrAlias: string): string => + generatePath(DIRECT_ROOM_FORUM_PATH, { roomIdOrAlias: encodeURIComponent(roomIdOrAlias) }); + export const getSpacePath = (spaceIdOrAlias: string): string => { const params = { spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias), @@ -151,6 +160,11 @@ export const getSpaceRoomPath = ( return generatePath(SPACE_ROOM_PATH, params); }; +export const getSpaceForumPath = (spaceIdOrAlias: string, roomIdOrAlias: string): string => + generatePath(SPACE_ROOM_FORUM_PATH, { + spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias), + roomIdOrAlias: encodeURIComponent(roomIdOrAlias), + }); export const getExplorePath = (): string => EXPLORE_PATH; export const getExploreFeaturedPath = (): string => EXPLORE_FEATURED_PATH;