Merge branch 'dev' into add-black-theme
This commit is contained in:
45 files changed
+1618
-339
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Fix recieved encrypted message per-message profiles not triggering rerenders.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
# Fix cinny-dark-theme link colors being too dark
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
# Fix "Default" menu item height in room notification switcher.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
# Fixes width mismatch for the call chat view.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Fix messages sent from sable showing wrong on other client(s)
|
||||
@@ -1,5 +1,45 @@
|
||||
# Sable Client Changelog
|
||||
|
||||
## 1.11.1 (2026-03-21)
|
||||
|
||||
### Fixes
|
||||
|
||||
* Fix conditional memo in reply renderer leading to crashes. ([#453](https://github.com/SableClient/Sable/pull/453) by @7w1)
|
||||
|
||||
## 1.11.0 (2026-03-21)
|
||||
|
||||
### Features
|
||||
|
||||
* Implemented improved rendering for space hierarchies in nav bar and lobby. ([#252](https://github.com/SableClient/Sable/pull/252) by @KaceCottam)
|
||||
* Added styling for replies to non-messages. ([#416](https://github.com/SableClient/Sable/pull/416) by @nushea)
|
||||
|
||||
### Fixes
|
||||
|
||||
* Fix message composer clearing when edited messages are saved. ([#447](https://github.com/SableClient/Sable/pull/447) by @7w1)
|
||||
* Fix editor flowing off screen when editing large messages in compact and bubble layouts. ([#447](https://github.com/SableClient/Sable/pull/447) by @7w1)
|
||||
* Fix extra spacing in message editor. ([#447](https://github.com/SableClient/Sable/pull/447) by @7w1)
|
||||
* Fix menu items not clickable due to menu transform. ([#450](https://github.com/SableClient/Sable/pull/450) by @7w1)
|
||||
* Fix replies not rendering matrix.to links and opening them in new tabs instead of jumping to them. ([#448](https://github.com/SableClient/Sable/pull/448) by @7w1)
|
||||
* Fix per-message profile messages collapsing together when different profiles are used. ([#449](https://github.com/SableClient/Sable/pull/449) by @7w1)
|
||||
* Fix per-message profiles not updating avatar/name if edit events are recieved. ([#449](https://github.com/SableClient/Sable/pull/449) by @7w1)
|
||||
* Fix editing per-message profile messages injecting profile name into message. ([#451](https://github.com/SableClient/Sable/pull/451) by @7w1)
|
||||
* Fix per-message profiles not rendering in encrypted rooms. ([#449](https://github.com/SableClient/Sable/pull/449) by @7w1)
|
||||
* Fix thread chips not appearing on thread root messages. ([#446](https://github.com/SableClient/Sable/pull/446) by @7w1)
|
||||
* Fix up arrow to edit messages not editing messages. ([#447](https://github.com/SableClient/Sable/pull/447) by @7w1)
|
||||
|
||||
## 1.10.6 (2026-03-21)
|
||||
|
||||
### Fixes
|
||||
|
||||
* Change default notification server. ([#443](https://github.com/SableClient/Sable/pull/443) by @7w1)
|
||||
|
||||
## 1.10.5 (2026-03-20)
|
||||
|
||||
### Fixes
|
||||
|
||||
* Hide unread dot/highlight for rooms with notification mode set to Mute. ([#429](https://github.com/SableClient/Sable/pull/429) by @saschabuehrle)
|
||||
* Fix thread drawer flooding console with "Ignoring event" warnings when server-side thread support is enabled. ([#438](https://github.com/SableClient/Sable/pull/438) by @Just-Insane)
|
||||
|
||||
## 1.10.4 (2026-03-20)
|
||||
|
||||
### Fixes
|
||||
|
||||
+3
-3
@@ -8,9 +8,9 @@
|
||||
"hideUsernamePasswordFields": false,
|
||||
|
||||
"pushNotificationDetails": {
|
||||
"pushNotifyUrl": "https://sygnal.cloudhub.social/_matrix/push/v1/notify",
|
||||
"vapidPublicKey": "BCAlXMEViGKDCqCIAxYfj2esZXvbbYTUqWxHpb7kHmBiEVGYHdUmkxoCIkY9zjw6gaJ-ovbxyHGJN8XyiyNqhmM",
|
||||
"webPushAppID": "social.cloudhub.sable.web"
|
||||
"pushNotifyUrl": "https://sygnal.sable.moe/_matrix/push/v1/notify",
|
||||
"vapidPublicKey": "BCnS4SbHjeOaqVFW4wjt5xDt_pYIL62qMzKePfYF9fl9PQU14RieIaObh7nLR_9dQf4sykZa-CTrcjkgMIE1mcg",
|
||||
"webPushAppID": "moe.sable.app.sygnal"
|
||||
},
|
||||
|
||||
"slidingSync": {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sable",
|
||||
"version": "1.10.4",
|
||||
"version": "1.11.1",
|
||||
"description": "An almost stable Matrix client",
|
||||
"type": "module",
|
||||
"packageManager": "[email protected]+sha512.a706938f0e89ac1456b6563eab4edf1d1faf3368d1191fc5c59790e96dc918e4456ab2e67d613de1043d2e8c81f87303e6b40d4ffeca9df15ef1ad567348f2be",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Box, config, Icon, Menu, MenuItem, PopOut, RectCords, Text } from 'folds';
|
||||
import { Box, config, Icon, Menu, MenuItem, PopOut, RectCords, Text, toRem } from 'folds';
|
||||
import { MouseEventHandler, ReactNode, useMemo, useState } from 'react';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
@@ -93,6 +93,7 @@ export function RoomNotificationModeSwitcher({
|
||||
size="300"
|
||||
variant="Surface"
|
||||
aria-pressed={mode === value}
|
||||
style={mode === RoomNotificationMode.Unset ? { height: toRem(48) } : undefined}
|
||||
radii="300"
|
||||
disabled={changing}
|
||||
onClick={() => handleSelect(mode)}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Box, Chip, Icon, Icons, Text, as, color, toRem } from 'folds';
|
||||
import { EventTimelineSet, Room } from '$types/matrix-sdk';
|
||||
import { Box, Chip, Icon, IconSrc, Icons, Text, as, color, toRem } from 'folds';
|
||||
import { EventTimelineSet, Room, SessionMembershipData } from '$types/matrix-sdk';
|
||||
import { MouseEventHandler, ReactNode, useCallback, useMemo } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import classNames from 'classnames';
|
||||
@@ -12,6 +12,9 @@ import {
|
||||
getReactCustomHtmlParser,
|
||||
scaleSystemEmoji,
|
||||
LINKIFY_OPTS,
|
||||
makeMentionCustomProps,
|
||||
factoryRenderLinkifyWithMention,
|
||||
renderMatrixMention,
|
||||
} from '$plugins/react-custom-html-parser';
|
||||
import { useRoomEvent } from '$hooks/useRoomEvent';
|
||||
import { useSableCosmetics } from '$hooks/useSableCosmetics';
|
||||
@@ -19,6 +22,11 @@ import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { useIgnoredUsers } from '$hooks/useIgnoredUsers';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useMemberEventParser } from '$hooks/useMemberEventParser';
|
||||
import { StateEvent, MessageEvent } from '$types/matrix/room';
|
||||
import { useMentionClickHandler } from '$hooks/useMentionClickHandler';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import * as customHtmlCss from '$styles/CustomHtml.css';
|
||||
import {
|
||||
MessageBadEncryptedContent,
|
||||
MessageBlockedContent,
|
||||
@@ -31,9 +39,10 @@ import { LinePlaceholder } from './placeholder';
|
||||
type ReplyLayoutProps = {
|
||||
userColor?: string;
|
||||
username?: ReactNode;
|
||||
icon?: IconSrc;
|
||||
};
|
||||
export const ReplyLayout = as<'div', ReplyLayoutProps>(
|
||||
({ username, userColor, className, children, ...props }, ref) => (
|
||||
({ username, userColor, icon, className, children, ...props }, ref) => (
|
||||
<Box
|
||||
className={classNames(css.Reply, className)}
|
||||
alignItems="Center"
|
||||
@@ -41,8 +50,11 @@ export const ReplyLayout = as<'div', ReplyLayoutProps>(
|
||||
{...props}
|
||||
ref={ref}
|
||||
>
|
||||
<Box style={{ color: userColor, maxWidth: toRem(200) }} alignItems="Center" shrink="No">
|
||||
<Box style={{ color: userColor }} alignItems="Center" shrink="No">
|
||||
<Icon size="100" src={Icons.ReplyArrow} />
|
||||
</Box>
|
||||
{!!icon && <Icon style={{ opacity: 0.6 }} size="50" src={icon} />}
|
||||
<Box style={{ color: userColor, maxWidth: toRem(200) }} alignItems="Center" shrink="No">
|
||||
{username}
|
||||
</Box>
|
||||
<Box grow="Yes" className={css.ReplyContent}>
|
||||
@@ -88,21 +100,23 @@ export const Reply = as<'div', ReplyProps>(
|
||||
|
||||
const { body, formatted_body: formattedBody, format } = replyEvent?.getContent() ?? {};
|
||||
const sender = replyEvent?.getSender();
|
||||
const eventType = replyEvent?.getType();
|
||||
|
||||
const ignoredUsers = useIgnoredUsers();
|
||||
const isBlockedSender = !!sender && ignoredUsers.includes(sender);
|
||||
const { t } = useTranslation();
|
||||
const isRedacted = replyEvent?.isRedacted() === true;
|
||||
|
||||
const parseMemberEvent = useMemberEventParser();
|
||||
|
||||
const { color: usernameColor, font: usernameFont } = useSableCosmetics(sender ?? '', room);
|
||||
const nicknames = useAtomValue(nicknamesAtom);
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
|
||||
const fallbackBody = replyEvent?.isRedacted() ? (
|
||||
<MessageDeletedContent />
|
||||
) : (
|
||||
<MessageFailedContent />
|
||||
);
|
||||
const fallbackBody = isRedacted ? <MessageDeletedContent /> : <MessageFailedContent />;
|
||||
|
||||
const badEncryption = replyEvent?.getContent().msgtype === 'm.bad.encrypted';
|
||||
const mentionClickHandler = useMentionClickHandler(room.roomId);
|
||||
|
||||
// An encrypted event that hasn't been decrypted yet (keys pending) has an
|
||||
// empty result from getClearContent(). Treat it as still-loading rather
|
||||
@@ -116,6 +130,23 @@ export const Reply = as<'div', ReplyProps>(
|
||||
!replyEvent.getClearContent();
|
||||
|
||||
let bodyJSX: ReactNode = fallbackBody;
|
||||
let image: IconSrc | undefined;
|
||||
|
||||
const replyLinkifyOpts = useMemo(
|
||||
() => ({
|
||||
...LINKIFY_OPTS,
|
||||
render: factoryRenderLinkifyWithMention((href) =>
|
||||
renderMatrixMention(
|
||||
mx,
|
||||
room.roomId,
|
||||
href,
|
||||
makeMentionCustomProps(mentionClickHandler),
|
||||
nicknames
|
||||
)
|
||||
),
|
||||
}),
|
||||
[mx, room.roomId, mentionClickHandler, nicknames]
|
||||
);
|
||||
|
||||
if (format === 'org.matrix.custom.html' && formattedBody) {
|
||||
const strippedHtml = trimReplyFromFormattedBody(formattedBody)
|
||||
@@ -126,16 +157,42 @@ export const Reply = as<'div', ReplyProps>(
|
||||
.replaceAll(/<\/?(ul|ol|li|blockquote|h[1-6]|pre|div)[^>]*>/gi, '')
|
||||
.replaceAll(/(?:\r\n|\r|\n)/g, ' ');
|
||||
const parserOpts = getReactCustomHtmlParser(mx, room.roomId, {
|
||||
linkifyOpts: LINKIFY_OPTS,
|
||||
linkifyOpts: replyLinkifyOpts,
|
||||
useAuthentication,
|
||||
nicknames,
|
||||
handleMentionClick: mentionClickHandler,
|
||||
});
|
||||
bodyJSX = parse(strippedHtml, parserOpts) as JSX.Element;
|
||||
} else if (body) {
|
||||
const strippedBody = trimReplyFromBody(body).replaceAll(/(?:\r\n|\r|\n)/g, ' ');
|
||||
bodyJSX = scaleSystemEmoji(strippedBody);
|
||||
} else if (eventType === StateEvent.RoomMember && !!replyEvent) {
|
||||
const parsedMemberEvent = parseMemberEvent(replyEvent);
|
||||
image = parsedMemberEvent.icon;
|
||||
bodyJSX = parsedMemberEvent.body;
|
||||
} else if (eventType === StateEvent.RoomName) {
|
||||
image = Icons.Hash;
|
||||
bodyJSX = t('Organisms.RoomCommon.changed_room_name');
|
||||
} else if (eventType === StateEvent.RoomTopic) {
|
||||
image = Icons.Hash;
|
||||
bodyJSX = ' changed room topic';
|
||||
} else if (eventType === StateEvent.RoomAvatar) {
|
||||
image = Icons.Hash;
|
||||
bodyJSX = ' changed room avatar';
|
||||
} else if (eventType === StateEvent.GroupCallMemberPrefix && !!replyEvent) {
|
||||
const callJoined = replyEvent.getContent<SessionMembershipData>().application;
|
||||
image = callJoined ? Icons.Phone : Icons.PhoneDown;
|
||||
bodyJSX = callJoined ? ' joined the call' : ' ended the call';
|
||||
} else if (Object.values(MessageEvent).every((v) => v !== eventType)) {
|
||||
image = Icons.Code;
|
||||
bodyJSX = (
|
||||
<>
|
||||
{' sent '}
|
||||
<code className={customHtmlCss.Code}>{eventType}</code>
|
||||
{' state event'}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box direction="Row" gap="200" alignItems="Center" {...props} ref={ref}>
|
||||
{threadRootId && (
|
||||
@@ -144,8 +201,10 @@ export const Reply = as<'div', ReplyProps>(
|
||||
<ReplyLayout
|
||||
as="button"
|
||||
userColor={usernameColor}
|
||||
icon={image}
|
||||
username={
|
||||
sender && (
|
||||
sender &&
|
||||
eventType !== StateEvent.RoomMember && (
|
||||
<Text size="T300" truncate style={{ fontFamily: usernameFont }}>
|
||||
<b>{getMemberDisplayName(room, sender, nicknames) ?? getMxIdLocalPart(sender)}</b>
|
||||
</Text>
|
||||
@@ -163,13 +222,15 @@ export const Reply = as<'div', ReplyProps>(
|
||||
})()}
|
||||
</Text>
|
||||
) : (
|
||||
<LinePlaceholder
|
||||
style={{
|
||||
backgroundColor: color.SurfaceVariant.ContainerActive,
|
||||
width: toRem(placeholderWidth),
|
||||
maxWidth: '100%',
|
||||
}}
|
||||
/>
|
||||
(isRedacted && <MessageDeletedContent />) || (
|
||||
<LinePlaceholder
|
||||
style={{
|
||||
backgroundColor: color.SurfaceVariant.ContainerActive,
|
||||
width: toRem(placeholderWidth),
|
||||
maxWidth: '100%',
|
||||
}}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</ReplyLayout>
|
||||
{replyEvent === null && (
|
||||
|
||||
@@ -83,13 +83,39 @@ export function AddExistingModal({ parentId, space, requestClose }: AddExistingM
|
||||
const allRoomsSet = useAllJoinedRoomsSet();
|
||||
const getRoom = useGetRoom(allRoomsSet);
|
||||
|
||||
/**
|
||||
* Recursively checks if a given sourceId room is an ancestor to the targetId space.
|
||||
*
|
||||
* @param sourceId - The room to check.
|
||||
* @param targetId - The space ID to check against.
|
||||
* @param visited - Set used to prevent recursion errors.
|
||||
* @returns True if rId is an ancestor of targetId.
|
||||
*/
|
||||
const isAncestor = useCallback(
|
||||
(sourceId: string, targetId: string, visited: Set<string> = new Set()): boolean => {
|
||||
// Prevent infinite recursion
|
||||
if (visited.has(targetId)) return false;
|
||||
visited.add(targetId);
|
||||
|
||||
const parentIds = roomIdToParents.get(targetId);
|
||||
if (!parentIds) return false;
|
||||
|
||||
if (parentIds.has(sourceId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Array.from(parentIds).some((id) => isAncestor(sourceId, id, visited));
|
||||
},
|
||||
[roomIdToParents]
|
||||
);
|
||||
|
||||
const allItems: string[] = useMemo(() => {
|
||||
const rIds = space ? [...spaces] : [...rooms, ...directs];
|
||||
|
||||
return rIds
|
||||
.filter((rId) => rId !== parentId && !roomIdToParents.get(rId)?.has(parentId))
|
||||
.filter((rId) => rId !== parentId && !isAncestor(rId, parentId))
|
||||
.sort(factoryRoomIdByAtoZ(mx));
|
||||
}, [spaces, rooms, directs, space, parentId, roomIdToParents, mx]);
|
||||
}, [space, spaces, rooms, directs, mx, parentId, isAncestor]);
|
||||
|
||||
const getRoomNameStr: SearchItemStrGetter<string> = useCallback(
|
||||
(rId) => getRoom(rId)?.name ?? rId,
|
||||
|
||||
@@ -11,7 +11,7 @@ export const ItemDraggableTarget = style([
|
||||
top: 0,
|
||||
zIndex: 1,
|
||||
cursor: 'grab',
|
||||
borderRadius: config.radii.R400,
|
||||
borderRadius: 0,
|
||||
opacity: config.opacity.P300,
|
||||
|
||||
':active': {
|
||||
|
||||
@@ -30,6 +30,9 @@ import { IPowerLevels } from '$hooks/usePowerLevels';
|
||||
import { getRoomCreatorsForRoomId } from '$hooks/useRoomCreators';
|
||||
import { getRoomPermissionsAPI } from '$hooks/useRoomPermissions';
|
||||
import { InviteUserPrompt } from '$components/invite-user-prompt';
|
||||
import { getCanonicalAliasOrRoomId } from '$utils/matrix';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { getSpaceLobbyPath } from '$pages/pathUtils';
|
||||
|
||||
type HierarchyItemWithParent = HierarchyItem & {
|
||||
parentId: string;
|
||||
@@ -227,6 +230,7 @@ export function HierarchyItemMenu({
|
||||
};
|
||||
|
||||
const handleRequestClose = useCallback(() => setMenuAnchor(undefined), []);
|
||||
const navigate = useNavigate();
|
||||
|
||||
if (!joined && !canEditChild) {
|
||||
return null;
|
||||
@@ -278,6 +282,17 @@ export function HierarchyItemMenu({
|
||||
</Text>
|
||||
</MenuItem>
|
||||
)}
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => {
|
||||
navigate(getSpaceLobbyPath(getCanonicalAliasOrRoomId(mx, item.roomId)));
|
||||
}}
|
||||
>
|
||||
<Text as="span" size="T300" truncate>
|
||||
Open Lobby
|
||||
</Text>
|
||||
</MenuItem>
|
||||
<InviteMenuItem
|
||||
item={item}
|
||||
requestClose={handleRequestClose}
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
import { MouseEventHandler, useCallback, useMemo, useRef, useState } from 'react';
|
||||
import { Box, Chip, Icon, IconButton, Icons, Line, Scroll, Spinner, Text, config } from 'folds';
|
||||
import { useVirtualizer } from '@tanstack/react-virtual';
|
||||
import {
|
||||
MouseEventHandler,
|
||||
ReactElement,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import {
|
||||
Box,
|
||||
Chip,
|
||||
Icon,
|
||||
IconButton,
|
||||
Icons,
|
||||
Line,
|
||||
Scroll,
|
||||
Spinner,
|
||||
Text,
|
||||
color,
|
||||
config,
|
||||
} from 'folds';
|
||||
import { useVirtualizer, VirtualItem } from '@tanstack/react-virtual';
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
@@ -28,7 +48,7 @@ import {
|
||||
useRoomsPowerLevels,
|
||||
} from '$hooks/usePowerLevels';
|
||||
import { mDirectAtom } from '$state/mDirectList';
|
||||
import { makeLobbyCategoryId } from '$state/closedLobbyCategories';
|
||||
import { makeLobbyCategoryId, getLobbyCategoryIdParts } from '$state/closedLobbyCategories';
|
||||
import { useCategoryHandler } from '$hooks/useCategoryHandler';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { allRoomsAtom } from '$state/room-list/roomList';
|
||||
@@ -52,10 +72,11 @@ import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { getRoomPermissionsAPI } from '$hooks/useRoomPermissions';
|
||||
import { getRoomCreatorsForRoomId } from '$hooks/useRoomCreators';
|
||||
import { MembersDrawer } from '$features/room/MembersDrawer';
|
||||
import { SpaceHierarchy } from './SpaceHierarchy';
|
||||
import { SpaceHierarchyItem } from './SpaceHierarchyItem';
|
||||
import { CanDropCallback, useDnDMonitor } from './DnD';
|
||||
import { LobbyHero } from './LobbyHero';
|
||||
import { LobbyHeader } from './LobbyHeader';
|
||||
import { SpaceHierarchyNavItem } from './SpaceHierarchyNavItem';
|
||||
|
||||
const useCanDropLobbyItem = (
|
||||
space: Room,
|
||||
@@ -74,6 +95,11 @@ const useCanDropLobbyItem = (
|
||||
|
||||
const containerSpaceId = space.roomId;
|
||||
|
||||
// only allow to be dropped in parent space
|
||||
if (item.parentId !== container.item.roomId && item.parentId !== container.item.parentId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const powerLevels = roomsPowerLevels.get(containerSpaceId) ?? {};
|
||||
const creators = getRoomCreatorsForRoomId(mx, containerSpaceId);
|
||||
const permissions = getRoomPermissionsAPI(creators, powerLevels);
|
||||
@@ -167,6 +193,7 @@ export function Lobby() {
|
||||
const screenSize = useScreenSizeContext();
|
||||
const [onTop, setOnTop] = useState(true);
|
||||
const [closedCategories, setClosedCategories] = useAtom(useClosedLobbyCategoriesAtom());
|
||||
const roomToParents = useAtomValue(roomToParentsAtom);
|
||||
const [sidebarItems] = useSidebarItems(
|
||||
useOrphanSpaces(mx, allRoomsAtom, useAtomValue(roomToParentsAtom))
|
||||
);
|
||||
@@ -188,16 +215,100 @@ export function Lobby() {
|
||||
|
||||
const getRoom = useGetRoom(allJoinedRooms);
|
||||
|
||||
const closedCategoriesCache = useRef(new Map());
|
||||
useEffect(() => {
|
||||
closedCategoriesCache.current.clear();
|
||||
}, [closedCategories, roomToParents, getRoom]);
|
||||
|
||||
/**
|
||||
* Recursively checks if a given parentId (or all its ancestors) is in a closed category.
|
||||
*
|
||||
* @param spaceId - The root space ID.
|
||||
* @param parentId - The parent space ID to start the check from.
|
||||
* @param previousId - The last ID checked, only used to ignore root collapse state.
|
||||
* @param visited - Set used to prevent recursion errors.
|
||||
* @returns True if parentId or all ancestors is in a closed category.
|
||||
*/
|
||||
const getInClosedCategories = useCallback(
|
||||
(
|
||||
spaceId: string,
|
||||
parentId: string,
|
||||
previousId?: string,
|
||||
visited: Set<string> = new Set()
|
||||
): boolean => {
|
||||
// Ignore root space being collapsed if in a subspace,
|
||||
// this is due to many spaces dumping all rooms in the top-level space.
|
||||
if (parentId === spaceId && previousId) {
|
||||
if (spaceRooms.has(previousId) || getRoom(previousId)?.isSpaceRoom()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const categoryId = makeLobbyCategoryId(spaceId, parentId);
|
||||
|
||||
// Prevent infinite recursion
|
||||
if (visited.has(categoryId)) return false;
|
||||
visited.add(categoryId);
|
||||
|
||||
if (closedCategoriesCache.current.has(categoryId)) {
|
||||
return closedCategoriesCache.current.get(categoryId);
|
||||
}
|
||||
|
||||
if (closedCategories.has(categoryId)) {
|
||||
closedCategoriesCache.current.set(categoryId, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
const parentParentIds = roomToParents.get(parentId);
|
||||
if (!parentParentIds || parentParentIds.size === 0) {
|
||||
closedCategoriesCache.current.set(categoryId, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// As a subspace can be in multiple spaces,
|
||||
// only return true if all parent spaces are closed.
|
||||
const allClosed = !Array.from(parentParentIds).some(
|
||||
(id) => !getInClosedCategories(spaceId, id, parentId, visited)
|
||||
);
|
||||
visited.delete(categoryId);
|
||||
closedCategoriesCache.current.set(categoryId, allClosed);
|
||||
return allClosed;
|
||||
},
|
||||
[closedCategories, getRoom, roomToParents, spaceRooms]
|
||||
);
|
||||
|
||||
/**
|
||||
* Determines whether all parent categories are collapsed.
|
||||
*
|
||||
* @param spaceId - The root space ID.
|
||||
* @param roomId - The room ID to start the check from.
|
||||
* @returns True if every parent category is collapsed; false otherwise.
|
||||
*/
|
||||
const getAllAncestorsCollapsed = (spaceId: string, roomId: string): boolean => {
|
||||
const parentIds = roomToParents.get(roomId);
|
||||
|
||||
if (!parentIds || parentIds.size === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !Array.from(parentIds).some((id) => !getInClosedCategories(spaceId, id, roomId));
|
||||
};
|
||||
|
||||
const [subspaceHierarchyLimit] = useSetting(settingsAtom, 'subspaceHierarchyLimit');
|
||||
const [draggingItem, setDraggingItem] = useState<HierarchyItem>();
|
||||
const hierarchy = useSpaceHierarchy(
|
||||
space.roomId,
|
||||
spaceRooms,
|
||||
getRoom,
|
||||
useCallback(
|
||||
(_childId, _spaceId, depth) => depth >= subspaceHierarchyLimit,
|
||||
[subspaceHierarchyLimit]
|
||||
),
|
||||
useCallback(
|
||||
(childId) =>
|
||||
closedCategories.has(makeLobbyCategoryId(space.roomId, childId)) ||
|
||||
getInClosedCategories(space.roomId, childId) ||
|
||||
(draggingItem ? 'space' in draggingItem : false),
|
||||
[closedCategories, space.roomId, draggingItem]
|
||||
[draggingItem, getInClosedCategories, space.roomId]
|
||||
)
|
||||
);
|
||||
|
||||
@@ -298,7 +409,7 @@ export function Lobby() {
|
||||
|
||||
// remove from current space
|
||||
if (item.parentId !== containerParentId) {
|
||||
mx.sendStateEvent(item.parentId, StateEvent.SpaceChild as any, {}, item.roomId);
|
||||
await mx.sendStateEvent(item.parentId, StateEvent.SpaceChild as any, {}, item.roomId);
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -317,7 +428,7 @@ export function Lobby() {
|
||||
joinRuleContent.allow?.filter((allowRule) => allowRule.room_id !== item.parentId) ??
|
||||
[];
|
||||
allow.push({ type: RestrictedAllowType.RoomMembership, room_id: containerParentId });
|
||||
mx.sendStateEvent(itemRoom.roomId, StateEvent.RoomJoinRules as any, {
|
||||
await mx.sendStateEvent(itemRoom.roomId, StateEvent.RoomJoinRules as any, {
|
||||
...joinRuleContent,
|
||||
allow,
|
||||
});
|
||||
@@ -403,9 +514,18 @@ export function Lobby() {
|
||||
[setSpaceRooms]
|
||||
);
|
||||
|
||||
const handleCategoryClick = useCategoryHandler(setClosedCategories, (categoryId) =>
|
||||
closedCategories.has(categoryId)
|
||||
);
|
||||
const handleCategoryClick = useCategoryHandler(setClosedCategories, (categoryId) => {
|
||||
const collapsed = closedCategories.has(categoryId);
|
||||
const [spaceId, roomId] = getLobbyCategoryIdParts(categoryId);
|
||||
|
||||
// Prevent collapsing if all parents are collapsed
|
||||
const toggleable = !getAllAncestorsCollapsed(spaceId, roomId);
|
||||
|
||||
if (toggleable) {
|
||||
return collapsed;
|
||||
}
|
||||
return !collapsed;
|
||||
});
|
||||
|
||||
const handleOpenRoom: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
const rId = evt.currentTarget.getAttribute('data-room-id');
|
||||
@@ -426,6 +546,77 @@ export function Lobby() {
|
||||
[mx, sidebarItems, sidebarSpaces]
|
||||
);
|
||||
|
||||
const getPaddingTop = (vItem: VirtualItem) => {
|
||||
if (vItem.index === 0) return 0;
|
||||
const prevDepth = hierarchy[vItem.index - 1]?.space.depth ?? 0;
|
||||
const { depth } = hierarchy[vItem.index].space;
|
||||
if (depth !== 1 && depth >= prevDepth) return config.space.S200;
|
||||
return config.space.S500;
|
||||
};
|
||||
|
||||
const getConnectorSVG = useCallback(
|
||||
(virtualizedItems: VirtualItem[]): ReactElement => {
|
||||
const PADDING_LEFT_DEPTH_OFFSET = 15.75;
|
||||
const PADDING_LEFT_DEPTH_OFFSET_START = -15;
|
||||
|
||||
let aY = 0;
|
||||
// Holder for the paths
|
||||
const pathHolder: ReactElement[] = [];
|
||||
virtualizedItems.forEach((vItem) => {
|
||||
const { depth } = hierarchy[vItem.index].space ?? {};
|
||||
|
||||
// We will render spaces at a level above their normal depth, since we want their children to be "under" them
|
||||
// for the root items, we are not doing anything with it.
|
||||
if (depth < 1) {
|
||||
return;
|
||||
}
|
||||
// for the sub-root items, we will not draw any arcs from root to it.
|
||||
// however, we should capture the aX and aY to draw starter arcs for next depths.
|
||||
if (depth === 1) {
|
||||
aY = vItem.end;
|
||||
return;
|
||||
}
|
||||
|
||||
const pathStrings: string[] = [];
|
||||
|
||||
for (let iDepth = 0; iDepth < depth; iDepth += 1) {
|
||||
const X = iDepth * PADDING_LEFT_DEPTH_OFFSET + PADDING_LEFT_DEPTH_OFFSET_START;
|
||||
|
||||
const bY = vItem.end;
|
||||
|
||||
pathStrings.push(`M ${X} ${aY} L ${X} ${bY}`);
|
||||
}
|
||||
|
||||
pathHolder.push(
|
||||
<path
|
||||
d={pathStrings.join(' ')}
|
||||
fill="none"
|
||||
stroke={color.Surface.ContainerLine}
|
||||
strokeWidth={config.borderWidth.B300}
|
||||
display="block"
|
||||
/>
|
||||
);
|
||||
|
||||
aY = vItem.end;
|
||||
});
|
||||
|
||||
return (
|
||||
<svg
|
||||
style={{
|
||||
position: 'absolute',
|
||||
inset: 0,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
>
|
||||
{pathHolder}
|
||||
</svg>
|
||||
);
|
||||
},
|
||||
[hierarchy]
|
||||
);
|
||||
|
||||
return (
|
||||
<PowerLevelsContextProvider value={spacePowerLevels}>
|
||||
<Box grow="Yes">
|
||||
@@ -467,45 +658,69 @@ export function Lobby() {
|
||||
const item = hierarchy[vItem.index];
|
||||
if (!item) return null;
|
||||
const nextSpaceId = hierarchy[vItem.index + 1]?.space.roomId;
|
||||
|
||||
const categoryId = makeLobbyCategoryId(space.roomId, item.space.roomId);
|
||||
const inClosedCategory = getInClosedCategories(
|
||||
space.roomId,
|
||||
item.space.roomId
|
||||
);
|
||||
|
||||
const paddingLeft = `calc((${item.space.depth} - 1) * ${config.space.S400})`;
|
||||
|
||||
return (
|
||||
<VirtualTile
|
||||
virtualItem={vItem}
|
||||
style={{
|
||||
paddingTop: vItem.index === 0 ? 0 : config.space.S500,
|
||||
paddingTop: getPaddingTop(vItem),
|
||||
paddingLeft,
|
||||
}}
|
||||
ref={virtualizer.measureElement}
|
||||
key={vItem.index}
|
||||
>
|
||||
<SpaceHierarchy
|
||||
spaceItem={item.space}
|
||||
summary={spacesItems.get(item.space.roomId)}
|
||||
roomItems={item.rooms}
|
||||
allJoinedRooms={allJoinedRooms}
|
||||
mDirects={mDirects}
|
||||
roomsPowerLevels={roomsPowerLevels}
|
||||
categoryId={categoryId}
|
||||
closed={
|
||||
closedCategories.has(categoryId) ||
|
||||
(draggingItem ? 'space' in draggingItem : false)
|
||||
}
|
||||
handleClose={handleCategoryClick}
|
||||
draggingItem={draggingItem}
|
||||
onDragging={setDraggingItem}
|
||||
canDrop={canDrop}
|
||||
disabledReorder={reordering}
|
||||
nextSpaceId={nextSpaceId}
|
||||
getRoom={getRoom}
|
||||
pinned={sidebarSpaces.has(item.space.roomId)}
|
||||
togglePinToSidebar={togglePinToSidebar}
|
||||
onSpacesFound={handleSpacesFound}
|
||||
onOpenRoom={handleOpenRoom}
|
||||
/>
|
||||
{item.space.depth !== subspaceHierarchyLimit ? (
|
||||
<SpaceHierarchyItem
|
||||
spaceItem={item.space}
|
||||
roomItems={item.rooms}
|
||||
summary={spacesItems.get(item.space.roomId)}
|
||||
allJoinedRooms={allJoinedRooms}
|
||||
mDirects={mDirects}
|
||||
roomsPowerLevels={roomsPowerLevels}
|
||||
categoryId={categoryId}
|
||||
closed={
|
||||
inClosedCategory || (draggingItem ? 'space' in draggingItem : false)
|
||||
}
|
||||
handleClose={handleCategoryClick}
|
||||
draggingItem={draggingItem}
|
||||
onDragging={setDraggingItem}
|
||||
canDrop={canDrop}
|
||||
disabledReorder={reordering}
|
||||
nextSpaceId={nextSpaceId}
|
||||
getRoom={getRoom}
|
||||
pinned={sidebarSpaces.has(item.space.roomId)}
|
||||
togglePinToSidebar={togglePinToSidebar}
|
||||
onSpacesFound={handleSpacesFound}
|
||||
onOpenRoom={handleOpenRoom}
|
||||
/>
|
||||
) : (
|
||||
<SpaceHierarchyNavItem
|
||||
spaceItem={item.space}
|
||||
summary={spacesItems.get(item.space.roomId)}
|
||||
allJoinedRooms={allJoinedRooms}
|
||||
roomsPowerLevels={roomsPowerLevels}
|
||||
categoryId={categoryId}
|
||||
draggingItem={draggingItem}
|
||||
onDragging={setDraggingItem}
|
||||
canDrop={canDrop}
|
||||
disabledReorder={reordering}
|
||||
nextSpaceId={nextSpaceId}
|
||||
pinned={sidebarSpaces.has(item.space.roomId)}
|
||||
togglePinToSidebar={togglePinToSidebar}
|
||||
getRoom={getRoom}
|
||||
/>
|
||||
)}
|
||||
</VirtualTile>
|
||||
);
|
||||
})}
|
||||
{getConnectorSVG(vItems)}
|
||||
</div>
|
||||
{reordering && (
|
||||
<Box
|
||||
|
||||
@@ -2,7 +2,10 @@ import { style } from '@vanilla-extract/css';
|
||||
import { config, toRem } from 'folds';
|
||||
|
||||
export const RoomItemCard = style({
|
||||
padding: config.space.S400,
|
||||
paddingLeft: config.space.S400,
|
||||
paddingRight: config.space.S400,
|
||||
paddingTop: config.space.S300,
|
||||
paddingBottom: config.space.S300,
|
||||
borderRadius: 0,
|
||||
position: 'relative',
|
||||
selectors: {
|
||||
|
||||
+10
-11
@@ -18,7 +18,7 @@ import { AfterItemDropTarget, CanDropCallback } from './DnD';
|
||||
import { HierarchyItemMenu } from './HierarchyItemMenu';
|
||||
import { RoomItemCard } from './RoomItem';
|
||||
|
||||
type SpaceHierarchyProps = {
|
||||
type SpaceHierarchyItemProps = {
|
||||
summary: IHierarchyRoom | undefined;
|
||||
spaceItem: HierarchyItemSpace;
|
||||
roomItems?: HierarchyItemRoom[];
|
||||
@@ -39,7 +39,7 @@ type SpaceHierarchyProps = {
|
||||
onSpacesFound: (spaceItems: IHierarchyRoom[]) => void;
|
||||
onOpenRoom: MouseEventHandler<HTMLButtonElement>;
|
||||
};
|
||||
export const SpaceHierarchy = forwardRef<HTMLDivElement, SpaceHierarchyProps>(
|
||||
export const SpaceHierarchyItem = forwardRef<HTMLDivElement, SpaceHierarchyItemProps>(
|
||||
(
|
||||
{
|
||||
summary,
|
||||
@@ -98,7 +98,9 @@ export const SpaceHierarchy = forwardRef<HTMLDivElement, SpaceHierarchyProps>(
|
||||
onSpacesFound(Array.from(subspaces.values()));
|
||||
}, [subspaces, onSpacesFound]);
|
||||
|
||||
let childItems = roomItems?.filter((i) => !subspaces.has(i.roomId));
|
||||
let childItems: HierarchyItemRoom[] | undefined = roomItems?.filter(
|
||||
(i) => !subspaces.has(i.roomId)
|
||||
);
|
||||
if (!spacePermissions?.stateEvent(StateEvent.SpaceChild, mx.getSafeUserId())) {
|
||||
// hide unknown rooms for normal user
|
||||
childItems = childItems?.filter((i) => {
|
||||
@@ -109,7 +111,7 @@ export const SpaceHierarchy = forwardRef<HTMLDivElement, SpaceHierarchyProps>(
|
||||
}
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100" ref={ref}>
|
||||
<Box direction="Column" gap="0" ref={ref}>
|
||||
<SpaceItemCard
|
||||
summary={rooms.get(spaceItem.roomId) ?? summary}
|
||||
loading={fetching}
|
||||
@@ -152,7 +154,7 @@ export const SpaceHierarchy = forwardRef<HTMLDivElement, SpaceHierarchyProps>(
|
||||
data-dragging={draggingSpace}
|
||||
/>
|
||||
{childItems && childItems.length > 0 ? (
|
||||
<Box direction="Column" gap="100">
|
||||
<Box direction="Column" gap="0">
|
||||
{childItems.map((roomItem, index) => {
|
||||
const roomSummary = rooms.get(roomItem.roomId);
|
||||
|
||||
@@ -204,22 +206,19 @@ export const SpaceHierarchy = forwardRef<HTMLDivElement, SpaceHierarchyProps>(
|
||||
</Box>
|
||||
) : (
|
||||
childItems && (
|
||||
<SequenceCard variant="SurfaceVariant" gap="300" alignItems="Center">
|
||||
<SequenceCard variant="SurfaceVariant" gap="300" alignItems="Center" radii="300">
|
||||
<Box
|
||||
grow="Yes"
|
||||
style={{
|
||||
padding: config.space.S700,
|
||||
padding: config.space.S100,
|
||||
}}
|
||||
direction="Column"
|
||||
alignItems="Center"
|
||||
justifyContent="Center"
|
||||
gap="100"
|
||||
>
|
||||
<Text size="H5" align="Center">
|
||||
No Rooms
|
||||
</Text>
|
||||
<Text align="Center" size="T300" priority="300">
|
||||
This space does not contains rooms yet.
|
||||
This space does not contain any rooms.
|
||||
</Text>
|
||||
</Box>
|
||||
</SequenceCard>
|
||||
@@ -0,0 +1,105 @@
|
||||
import { forwardRef } from 'react';
|
||||
import { Room, IHierarchyRoom } from '$types/matrix-sdk';
|
||||
import { Box } from 'folds';
|
||||
import { HierarchyItem, HierarchyItemSpace } from '$hooks/useSpaceHierarchy';
|
||||
import { IPowerLevels } from '$hooks/usePowerLevels';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { StateEvent } from '$types/matrix/room';
|
||||
import { getRoomCreatorsForRoomId } from '$hooks/useRoomCreators';
|
||||
import { getRoomPermissionsAPI } from '$hooks/useRoomPermissions';
|
||||
import { AfterItemDropTarget, CanDropCallback } from './DnD';
|
||||
import { HierarchyItemMenu } from './HierarchyItemMenu';
|
||||
import { SpaceNavItemCard } from './SpaceNavItem';
|
||||
|
||||
type SpaceHierarchyNavItemProps = {
|
||||
summary: IHierarchyRoom | undefined;
|
||||
spaceItem: HierarchyItemSpace;
|
||||
allJoinedRooms: Set<string>;
|
||||
roomsPowerLevels: Map<string, IPowerLevels>;
|
||||
categoryId: string;
|
||||
draggingItem?: HierarchyItem;
|
||||
onDragging: (item?: HierarchyItem) => void;
|
||||
canDrop: CanDropCallback;
|
||||
disabledReorder?: boolean;
|
||||
nextSpaceId?: string;
|
||||
pinned: boolean;
|
||||
togglePinToSidebar: (roomId: string) => void;
|
||||
getRoom: (roomId: string) => Room | undefined;
|
||||
};
|
||||
export const SpaceHierarchyNavItem = forwardRef<HTMLDivElement, SpaceHierarchyNavItemProps>(
|
||||
(
|
||||
{
|
||||
summary,
|
||||
spaceItem,
|
||||
allJoinedRooms,
|
||||
roomsPowerLevels,
|
||||
categoryId,
|
||||
draggingItem,
|
||||
onDragging,
|
||||
canDrop,
|
||||
disabledReorder,
|
||||
nextSpaceId,
|
||||
pinned,
|
||||
togglePinToSidebar,
|
||||
getRoom,
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const spacePowerLevels = roomsPowerLevels.get(spaceItem.roomId);
|
||||
|
||||
const draggingSpace =
|
||||
draggingItem?.roomId === spaceItem.roomId && draggingItem.parentId === spaceItem.parentId;
|
||||
|
||||
const { parentId } = spaceItem;
|
||||
const parentPowerLevels = parentId ? roomsPowerLevels.get(parentId) : undefined;
|
||||
const parentCreators = parentId ? getRoomCreatorsForRoomId(mx, parentId) : undefined;
|
||||
const parentPermissions =
|
||||
parentCreators &&
|
||||
parentPowerLevels &&
|
||||
getRoomPermissionsAPI(parentCreators, parentPowerLevels);
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="0" ref={ref}>
|
||||
<SpaceNavItemCard
|
||||
summary={summary}
|
||||
item={spaceItem}
|
||||
joined={allJoinedRooms.has(spaceItem.roomId)}
|
||||
categoryId={categoryId}
|
||||
canReorder={
|
||||
parentPowerLevels && !disabledReorder && parentPermissions
|
||||
? parentPermissions.stateEvent(StateEvent.SpaceChild, mx.getSafeUserId())
|
||||
: false
|
||||
}
|
||||
options={
|
||||
parentId &&
|
||||
parentPowerLevels && (
|
||||
<HierarchyItemMenu
|
||||
item={{ ...spaceItem, parentId }}
|
||||
powerLevels={spacePowerLevels}
|
||||
joined={allJoinedRooms.has(spaceItem.roomId)}
|
||||
canEditChild={
|
||||
!!parentPermissions?.stateEvent(StateEvent.SpaceChild, mx.getSafeUserId())
|
||||
}
|
||||
pinned={pinned}
|
||||
onTogglePin={togglePinToSidebar}
|
||||
/>
|
||||
)
|
||||
}
|
||||
getRoom={getRoom}
|
||||
after={
|
||||
<AfterItemDropTarget
|
||||
item={spaceItem}
|
||||
nextRoomId={nextSpaceId}
|
||||
afterSpace
|
||||
canDrop={canDrop}
|
||||
/>
|
||||
}
|
||||
onDragging={onDragging}
|
||||
data-dragging={draggingSpace}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
);
|
||||
@@ -11,12 +11,11 @@ import {
|
||||
toRem,
|
||||
Spinner,
|
||||
PopOut,
|
||||
config,
|
||||
Menu,
|
||||
MenuItem,
|
||||
RectCords,
|
||||
config,
|
||||
} from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import classNames from 'classnames';
|
||||
import { MatrixError, Room, IHierarchyRoom } from '$types/matrix-sdk';
|
||||
import { HierarchyItem } from '$hooks/useSpaceHierarchy';
|
||||
@@ -26,17 +25,18 @@ import { nameInitials } from '$utils/common';
|
||||
import { LocalRoomSummaryLoader } from '$components/RoomSummaryLoader';
|
||||
import { getRoomAvatarUrl } from '$utils/room';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { mxcUrlToHttp } from '$utils/matrix';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { BetaNoticeBadge } from '$components/BetaNoticeBadge';
|
||||
import { CreateRoomType } from '$components/create-room';
|
||||
import { AddExistingModal } from '$features/add-existing';
|
||||
import { useOpenCreateRoomModal } from '$state/hooks/createRoomModal';
|
||||
import { useOpenCreateSpaceModal } from '$state/hooks/createSpaceModal';
|
||||
import { CreateRoomType } from '$components/create-room/types';
|
||||
import { AddExistingModal } from '$features/add-existing';
|
||||
import { BetaNoticeBadge } from '$components/BetaNoticeBadge';
|
||||
import { useDraggableItem } from './DnD';
|
||||
import * as styleCss from './style.css';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import * as css from './SpaceItem.css';
|
||||
import * as styleCss from './style.css';
|
||||
import { useDraggableItem } from './DnD';
|
||||
|
||||
function SpaceProfileLoading() {
|
||||
return (
|
||||
@@ -57,7 +57,7 @@ type InaccessibleSpaceProfileProps = {
|
||||
roomId: string;
|
||||
suggested?: boolean;
|
||||
};
|
||||
function InaccessibleSpaceProfile({ roomId, suggested }: InaccessibleSpaceProfileProps) {
|
||||
export function InaccessibleSpaceProfile({ roomId, suggested }: InaccessibleSpaceProfileProps) {
|
||||
return (
|
||||
<Chip
|
||||
as="span"
|
||||
@@ -102,7 +102,7 @@ type UnjoinedSpaceProfileProps = {
|
||||
avatarUrl?: string;
|
||||
suggested?: boolean;
|
||||
};
|
||||
function UnjoinedSpaceProfile({
|
||||
export function UnjoinedSpaceProfile({
|
||||
roomId,
|
||||
via,
|
||||
name,
|
||||
@@ -303,15 +303,17 @@ function AddRoomButton({ item }: { item: HierarchyItem }) {
|
||||
</FocusTrap>
|
||||
}
|
||||
>
|
||||
<Chip
|
||||
variant="Primary"
|
||||
radii="Pill"
|
||||
before={<Icon src={Icons.Plus} size="50" />}
|
||||
onClick={handleAddRoom}
|
||||
aria-pressed={!!cords}
|
||||
>
|
||||
<Text size="B300">Add Room</Text>
|
||||
</Chip>
|
||||
{item.parentId === undefined && (
|
||||
<Chip
|
||||
variant="Primary"
|
||||
radii="Pill"
|
||||
before={<Icon src={Icons.Plus} size="50" />}
|
||||
onClick={handleAddRoom}
|
||||
aria-pressed={!!cords}
|
||||
>
|
||||
<Text size="B300">Add Room</Text>
|
||||
</Chip>
|
||||
)}
|
||||
{addExisting && (
|
||||
<AddExistingModal parentId={item.roomId} requestClose={() => setAddExisting(false)} />
|
||||
)}
|
||||
@@ -370,15 +372,17 @@ function AddSpaceButton({ item }: { item: HierarchyItem }) {
|
||||
</FocusTrap>
|
||||
}
|
||||
>
|
||||
<Chip
|
||||
variant="SurfaceVariant"
|
||||
radii="Pill"
|
||||
before={<Icon src={Icons.Plus} size="50" />}
|
||||
onClick={handleAddSpace}
|
||||
aria-pressed={!!cords}
|
||||
>
|
||||
<Text size="B300">Add Space</Text>
|
||||
</Chip>
|
||||
{item.parentId === undefined && (
|
||||
<Chip
|
||||
variant="SurfaceVariant"
|
||||
radii="Pill"
|
||||
before={<Icon src={Icons.Plus} size="50" />}
|
||||
onClick={handleAddSpace}
|
||||
aria-pressed={!!cords}
|
||||
>
|
||||
<Text size="B300">Add Space</Text>
|
||||
</Chip>
|
||||
)}
|
||||
{addExisting && (
|
||||
<AddExistingModal space parentId={item.roomId} requestClose={() => setAddExisting(false)} />
|
||||
)}
|
||||
@@ -502,7 +506,7 @@ export const SpaceItemCard = as<'div', SpaceItemCardProps>(
|
||||
{space && canEditChild && (
|
||||
<Box shrink="No" alignItems="Inherit" gap="200">
|
||||
<AddRoomButton item={item} />
|
||||
{item.parentId === undefined && <AddSpaceButton item={item} />}
|
||||
<AddSpaceButton item={item} />
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { style } from '@vanilla-extract/css';
|
||||
import { config, toRem } from 'folds';
|
||||
import { recipe } from '@vanilla-extract/recipes';
|
||||
|
||||
export const SpaceItemCard = recipe({
|
||||
base: {
|
||||
paddingBottom: config.space.S100,
|
||||
borderBottom: `${config.borderWidth.B300} solid transparent`,
|
||||
position: 'relative',
|
||||
selectors: {
|
||||
'&[data-dragging=true]': {
|
||||
opacity: config.opacity.Disabled,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
export const HeaderChip = style({
|
||||
paddingLeft: config.space.S200,
|
||||
selectors: {
|
||||
[`&[data-ui-before="true"]`]: {
|
||||
paddingLeft: config.space.S100,
|
||||
},
|
||||
},
|
||||
});
|
||||
export const HeaderChipPlaceholder = style([
|
||||
{
|
||||
borderRadius: config.radii.R400,
|
||||
paddingLeft: config.space.S100,
|
||||
paddingRight: config.space.S300,
|
||||
height: toRem(32),
|
||||
},
|
||||
]);
|
||||
@@ -0,0 +1,173 @@
|
||||
import { ReactNode, useRef } from 'react';
|
||||
import { Avatar, Badge, Box, Chip, Icon, Icons, as, Text } from 'folds';
|
||||
import classNames from 'classnames';
|
||||
import { IHierarchyRoom, MatrixClient, Room } from '$types/matrix-sdk';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { getCanonicalAliasOrRoomId, mxcUrlToHttp } from '$utils/matrix';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { HierarchyItem } from '$hooks/useSpaceHierarchy';
|
||||
import { LocalRoomSummaryLoader } from '$components/RoomSummaryLoader';
|
||||
import { getRoomAvatarUrl } from '$utils/room';
|
||||
import { RoomAvatar } from '$components/room-avatar';
|
||||
import { nameInitials } from '$utils/common';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { getSpaceLobbyPath } from '$pages/pathUtils';
|
||||
import { InaccessibleSpaceProfile, UnjoinedSpaceProfile } from './SpaceItem';
|
||||
import * as css from './SpaceNavItem.css';
|
||||
import { useDraggableItem } from './DnD';
|
||||
|
||||
type SpaceProfileProps = {
|
||||
roomId: string;
|
||||
name: string;
|
||||
avatarUrl?: string;
|
||||
suggested?: boolean;
|
||||
categoryId: string;
|
||||
mx: MatrixClient;
|
||||
};
|
||||
function SpaceNavProfile({
|
||||
roomId,
|
||||
name,
|
||||
avatarUrl,
|
||||
suggested,
|
||||
categoryId,
|
||||
mx,
|
||||
}: SpaceProfileProps) {
|
||||
const navigate = useNavigate();
|
||||
return (
|
||||
<Chip
|
||||
data-category-id={categoryId}
|
||||
className={css.HeaderChip}
|
||||
variant="Surface"
|
||||
size="500"
|
||||
onClick={() => navigate(getSpaceLobbyPath(getCanonicalAliasOrRoomId(mx, roomId)))}
|
||||
before={
|
||||
<Avatar size="200" radii="300">
|
||||
<RoomAvatar
|
||||
roomId={roomId}
|
||||
src={avatarUrl}
|
||||
alt={name}
|
||||
renderFallback={() => (
|
||||
<Text as="span" size="H6">
|
||||
{nameInitials(name)}
|
||||
</Text>
|
||||
)}
|
||||
/>
|
||||
</Avatar>
|
||||
}
|
||||
after={<Icon src={Icons.Space} size="50" />}
|
||||
>
|
||||
<Box alignItems="Center" gap="200">
|
||||
<Text size="H4" truncate>
|
||||
{name}
|
||||
</Text>
|
||||
{suggested && (
|
||||
<Badge variant="Success" fill="Soft" radii="Pill" outlined>
|
||||
<Text size="L400">Suggested</Text>
|
||||
</Badge>
|
||||
)}
|
||||
</Box>
|
||||
</Chip>
|
||||
);
|
||||
}
|
||||
|
||||
type SpaceNavItemCardProps = {
|
||||
summary: IHierarchyRoom | undefined;
|
||||
item: HierarchyItem;
|
||||
joined?: boolean;
|
||||
categoryId: string;
|
||||
options?: ReactNode;
|
||||
before?: ReactNode;
|
||||
after?: ReactNode;
|
||||
canReorder: boolean;
|
||||
getRoom: (roomId: string) => Room | undefined;
|
||||
onDragging: (item?: HierarchyItem) => void;
|
||||
};
|
||||
export const SpaceNavItemCard = as<'div', SpaceNavItemCardProps>(
|
||||
(
|
||||
{
|
||||
className,
|
||||
summary,
|
||||
joined,
|
||||
categoryId,
|
||||
item,
|
||||
options,
|
||||
before,
|
||||
after,
|
||||
canReorder,
|
||||
onDragging,
|
||||
getRoom,
|
||||
...props
|
||||
},
|
||||
ref
|
||||
) => {
|
||||
const mx = useMatrixClient();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const { roomId, content } = item;
|
||||
// const spaceNav = getRoom(roomId);
|
||||
const targetRef = useRef<HTMLDivElement>(null);
|
||||
useDraggableItem(item, targetRef, onDragging);
|
||||
const space = getRoom(item.roomId);
|
||||
|
||||
return (
|
||||
<Box
|
||||
shrink="No"
|
||||
alignItems="Center"
|
||||
gap="200"
|
||||
className={classNames(css.SpaceItemCard(), className)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
>
|
||||
{before}
|
||||
<Box grow="Yes" gap="100" alignItems="Inherit" justifyContent="SpaceBetween">
|
||||
<Box ref={canReorder ? targetRef : null}>
|
||||
{space ? (
|
||||
<LocalRoomSummaryLoader room={space}>
|
||||
{(localSummary) => (
|
||||
<SpaceNavProfile
|
||||
roomId={roomId}
|
||||
name={localSummary.name}
|
||||
avatarUrl={getRoomAvatarUrl(mx, space, 96, useAuthentication)}
|
||||
suggested={content.suggested}
|
||||
categoryId={categoryId}
|
||||
mx={mx}
|
||||
/>
|
||||
)}
|
||||
</LocalRoomSummaryLoader>
|
||||
) : (
|
||||
<>
|
||||
{!summary && (
|
||||
<InaccessibleSpaceProfile
|
||||
roomId={item.roomId}
|
||||
suggested={item.content.suggested}
|
||||
/>
|
||||
)}
|
||||
{summary && (
|
||||
<UnjoinedSpaceProfile
|
||||
roomId={roomId}
|
||||
via={item.content.via}
|
||||
name={summary.name || summary.canonical_alias || roomId}
|
||||
avatarUrl={
|
||||
summary?.avatar_url
|
||||
? (mxcUrlToHttp(
|
||||
mx,
|
||||
summary.avatar_url,
|
||||
useAuthentication,
|
||||
96,
|
||||
96,
|
||||
'crop'
|
||||
) ?? undefined)
|
||||
: undefined
|
||||
}
|
||||
suggested={content.suggested}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
{options}
|
||||
{after}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
);
|
||||
@@ -7,8 +7,8 @@ export const RoomNavCategoryButton = as<'button', { closed?: boolean }>(
|
||||
<Chip
|
||||
className={classNames(css.CategoryButton, className)}
|
||||
variant="Background"
|
||||
radii="Pill"
|
||||
before={
|
||||
radii="400"
|
||||
after={
|
||||
<Icon
|
||||
className={css.CategoryButtonIcon}
|
||||
size="50"
|
||||
@@ -18,7 +18,7 @@ export const RoomNavCategoryButton = as<'button', { closed?: boolean }>(
|
||||
{...props}
|
||||
ref={ref}
|
||||
>
|
||||
<Text size="O400" priority="300" truncate>
|
||||
<Text size="B400" priority="300" truncate>
|
||||
{children}
|
||||
</Text>
|
||||
</Chip>
|
||||
|
||||
@@ -343,6 +343,9 @@ export function RoomNavItem({
|
||||
};
|
||||
|
||||
const optionsVisible = hover || !!menuAnchor;
|
||||
const isMutedRoom = notificationMode === RoomNotificationMode.Mute;
|
||||
const shouldShowUnreadIndicator = !isMutedRoom && (!!unread || hasRoomUnread);
|
||||
|
||||
let unreadCount = 0;
|
||||
if (unread) {
|
||||
unreadCount = unread.highlight > 0 ? unread.highlight : unread.total;
|
||||
@@ -368,7 +371,7 @@ export function RoomNavItem({
|
||||
<NavItem
|
||||
variant="Background"
|
||||
radii="400"
|
||||
highlight={unread !== undefined || hasRoomUnread}
|
||||
highlight={shouldShowUnreadIndicator}
|
||||
aria-selected={selected}
|
||||
data-hover={!!menuAnchor}
|
||||
onContextMenu={handleContextMenu}
|
||||
@@ -425,7 +428,7 @@ export function RoomNavItem({
|
||||
<TypingIndicator size="300" disableAnimation />
|
||||
</Badge>
|
||||
)}
|
||||
{!optionsVisible && (unread || hasRoomUnread) && (
|
||||
{!optionsVisible && shouldShowUnreadIndicator && (
|
||||
<UnreadBadgeCenter>
|
||||
<UnreadBadge
|
||||
highlight={!!unread && unread.highlight > 0}
|
||||
|
||||
@@ -16,7 +16,7 @@ export function CallChatView() {
|
||||
return (
|
||||
<Page
|
||||
style={{
|
||||
width: screenSize === ScreenSize.Desktop ? toRem(456) : '100%',
|
||||
width: screenSize === ScreenSize.Desktop ? toRem(399) : '100%',
|
||||
flexShrink: 0,
|
||||
flexGrow: 0,
|
||||
}}
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
KeyboardEventHandler,
|
||||
MouseEvent,
|
||||
RefObject,
|
||||
ReactNode,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
@@ -44,13 +43,6 @@ import {
|
||||
toRem,
|
||||
} from 'folds';
|
||||
|
||||
import parse from 'html-react-parser';
|
||||
import {
|
||||
getReactCustomHtmlParser,
|
||||
LINKIFY_OPTS,
|
||||
scaleSystemEmoji,
|
||||
} from '$plugins/react-custom-html-parser';
|
||||
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import {
|
||||
AutocompletePrefix,
|
||||
@@ -83,7 +75,6 @@ import {
|
||||
TUploadContent,
|
||||
encryptFile,
|
||||
getImageInfo,
|
||||
getMxIdLocalPart,
|
||||
mxcUrlToHttp,
|
||||
toggleReaction,
|
||||
} from '$utils/matrix';
|
||||
@@ -113,23 +104,16 @@ import { safeFile } from '$utils/mimeTypes';
|
||||
import { fulfilledPromiseSettledResult } from '$utils/common';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import {
|
||||
getMemberDisplayName,
|
||||
getMentionContent,
|
||||
reactionOrEditEvent,
|
||||
trimReplyFromBody,
|
||||
trimReplyFromFormattedBody,
|
||||
} from '$utils/room';
|
||||
import { getMentionContent, reactionOrEditEvent } from '$utils/room';
|
||||
import { Command, SHRUG, TABLEFLIP, UNFLIP, useCommands } from '$hooks/useCommands';
|
||||
import { mobileOrTablet } from '$utils/user-agent';
|
||||
import { useElementSizeObserver } from '$hooks/useElementSizeObserver';
|
||||
import { ReplyLayout, ThreadIndicator } from '$components/message';
|
||||
import { Reply, ThreadIndicator } from '$components/message';
|
||||
import { roomToParentsAtom } from '$state/room/roomToParents';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { useImagePackRooms } from '$hooks/useImagePackRooms';
|
||||
import { useComposingCheck } from '$hooks/useComposingCheck';
|
||||
import { useSableCosmetics } from '$hooks/useSableCosmetics';
|
||||
import { createLogger } from '$utils/debug';
|
||||
import { createDebugLogger } from '$utils/debugLogger';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
@@ -247,9 +231,10 @@ interface RoomInputProps {
|
||||
roomId: string;
|
||||
room: Room;
|
||||
threadRootId?: string;
|
||||
onEditLastMessage?: () => void;
|
||||
}
|
||||
export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
({ editor, fileDropContainerRef, roomId, room, threadRootId }, ref) => {
|
||||
({ editor, fileDropContainerRef, roomId, room, threadRootId, onEditLastMessage }, ref) => {
|
||||
// When in thread mode, isolate drafts by thread root ID so thread replies
|
||||
// don't clobber the main room draft (and vice versa).
|
||||
const draftKey = threadRootId ?? roomId;
|
||||
@@ -276,12 +261,6 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
|
||||
const [msgDraft, setMsgDraft] = useAtom(roomIdToMsgDraftAtomFamily(draftKey));
|
||||
const [replyDraft, setReplyDraft] = useAtom(roomIdToReplyDraftAtomFamily(draftKey));
|
||||
const replyUserID = replyDraft?.userId;
|
||||
|
||||
const { color: replyUsernameColor, font: replyUsernameFont } = useSableCosmetics(
|
||||
replyUserID ?? '',
|
||||
room
|
||||
);
|
||||
|
||||
const [uploadBoard, setUploadBoard] = useState(true);
|
||||
const [selectedFiles, setSelectedFiles] = useAtom(roomIdToUploadItemsAtomFamily(draftKey));
|
||||
@@ -374,41 +353,6 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
);
|
||||
|
||||
const replyEvent = replyDraft ? room.findEventById(replyDraft.eventId) : undefined;
|
||||
const {
|
||||
body: replyBody,
|
||||
formatted_body: replyFormattedBody,
|
||||
format: replyFormat,
|
||||
} = replyEvent?.getContent() ?? {};
|
||||
|
||||
// Prefer the live event content; fall back to what was snapshotted in the
|
||||
// draft when the user hit Reply (the event may not be in SDK state if it
|
||||
// was redacted or evicted, but the draft always carries the original body).
|
||||
const htmlBody =
|
||||
replyFormat === 'org.matrix.custom.html' ? replyFormattedBody : replyDraft?.formattedBody;
|
||||
const plainBody = replyBody ?? replyDraft?.body;
|
||||
|
||||
let replyBodyJSX: ReactNode = replyDraft ? trimReplyFromBody(replyDraft.body) : null;
|
||||
|
||||
if (htmlBody) {
|
||||
/**
|
||||
* message with linebreaks, etc stripped
|
||||
*/
|
||||
const strippedHtml = trimReplyFromFormattedBody(htmlBody)
|
||||
.replaceAll(/<br\s*\/?>/gi, ' ')
|
||||
.replaceAll(/<\/p>\s*<p[^>]*>/gi, ' ')
|
||||
.replaceAll(/<\/?p[^>]*>/gi, '')
|
||||
.replaceAll(/(?:\r\n|\r|\n)/g, ' ')
|
||||
.trim();
|
||||
const parserOpts = getReactCustomHtmlParser(mx, roomId, {
|
||||
linkifyOpts: LINKIFY_OPTS,
|
||||
useAuthentication,
|
||||
nicknames,
|
||||
});
|
||||
replyBodyJSX = parse(strippedHtml, parserOpts);
|
||||
} else if (plainBody) {
|
||||
const strippedBody = trimReplyFromBody(plainBody).replaceAll(/(?:\r\n|\r|\n)/g, ' ');
|
||||
replyBodyJSX = scaleSystemEmoji(strippedBody);
|
||||
}
|
||||
|
||||
// Seed the reply draft with the thread relation whenever we're in thread
|
||||
// mode (e.g. on first render or when the thread root changes). We use the
|
||||
@@ -948,6 +892,15 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
}
|
||||
}
|
||||
|
||||
if (isKeyHotkey('arrowup', evt) && isEmptyEditor(editor)) {
|
||||
const { selection } = editor;
|
||||
if (selection && Editor.isStart(editor, selection.anchor, [])) {
|
||||
evt.preventDefault();
|
||||
onEditLastMessage?.();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
(isKeyHotkey('mod+enter', evt) || (!enterForNewline && isKeyHotkey('enter', evt))) &&
|
||||
!isComposing(evt)
|
||||
@@ -979,6 +932,8 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
autocompleteQuery,
|
||||
isComposing,
|
||||
showAudioRecorder,
|
||||
editor,
|
||||
onEditLastMessage,
|
||||
]
|
||||
);
|
||||
|
||||
@@ -1261,22 +1216,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
{replyDraft.relation?.rel_type === RelationType.Thread && !threadRootId && (
|
||||
<ThreadIndicator />
|
||||
)}
|
||||
<ReplyLayout
|
||||
userColor={replyUsernameColor}
|
||||
username={
|
||||
<Text size="T300" truncate style={{ fontFamily: replyUsernameFont }}>
|
||||
<b>
|
||||
{getMemberDisplayName(room, replyDraft.userId, nicknames) ??
|
||||
getMxIdLocalPart(replyDraft.userId) ??
|
||||
replyDraft.userId}
|
||||
</b>
|
||||
</Text>
|
||||
}
|
||||
>
|
||||
<Text size="T300" truncate>
|
||||
{replyBodyJSX}
|
||||
</Text>
|
||||
</ReplyLayout>
|
||||
<Reply room={room} replyEventId={replyDraft.eventId} />
|
||||
</Box>
|
||||
<IconButton
|
||||
variant="SurfaceVariant"
|
||||
|
||||
@@ -109,6 +109,7 @@ export type RoomTimelineProps = {
|
||||
eventId?: string;
|
||||
editor: Editor;
|
||||
onEditorReset?: () => void;
|
||||
onEditLastMessageRef?: React.MutableRefObject<(() => void) | undefined>;
|
||||
};
|
||||
|
||||
export function RoomTimeline({
|
||||
@@ -116,6 +117,7 @@ export function RoomTimeline({
|
||||
eventId,
|
||||
editor,
|
||||
onEditorReset,
|
||||
onEditLastMessageRef,
|
||||
}: Readonly<RoomTimelineProps>) {
|
||||
const mx = useMatrixClient();
|
||||
const alive = useAlive();
|
||||
@@ -660,6 +662,23 @@ export function RoomTimeline({
|
||||
|
||||
processedEventsRef.current = processedEvents;
|
||||
|
||||
useEffect(() => {
|
||||
if (!onEditLastMessageRef) return;
|
||||
const ref = onEditLastMessageRef;
|
||||
ref.current = () => {
|
||||
const myUserId = mx.getUserId();
|
||||
const found = [...processedEventsRef.current]
|
||||
.reverse()
|
||||
.find(
|
||||
(e) =>
|
||||
e.mEvent.getSender() === myUserId &&
|
||||
e.mEvent.getType() === 'm.room.message' &&
|
||||
!e.mEvent.isRedacted()
|
||||
);
|
||||
if (found?.mEvent.getId()) actions.handleEdit(found.mEvent.getId());
|
||||
};
|
||||
}, [onEditLastMessageRef, mx, actions]);
|
||||
|
||||
useEffect(() => {
|
||||
const v = vListRef.current;
|
||||
if (!v) return;
|
||||
|
||||
@@ -73,6 +73,7 @@ const shouldFocusMessageField = (evt: KeyboardEvent): boolean => {
|
||||
export function RoomView({ eventId }: { eventId?: string }) {
|
||||
const roomInputRef = useRef<HTMLDivElement>(null);
|
||||
const roomViewRef = useRef<HTMLDivElement>(null);
|
||||
const editLastMessageRef = useRef<(() => void) | undefined>();
|
||||
|
||||
const [hideReads] = useSetting(settingsAtom, 'hideReads');
|
||||
const screenSize = useScreenSizeContext();
|
||||
@@ -161,6 +162,7 @@ export function RoomView({ eventId }: { eventId?: string }) {
|
||||
eventId={eventId}
|
||||
editor={editor}
|
||||
onEditorReset={handleResetEditor}
|
||||
onEditLastMessageRef={editLastMessageRef}
|
||||
/>
|
||||
<RoomViewTyping room={room} />
|
||||
<GlobalModalManager />
|
||||
@@ -186,6 +188,7 @@ export function RoomView({ eventId }: { eventId?: string }) {
|
||||
roomId={roomId}
|
||||
fileDropContainerRef={roomViewRef}
|
||||
ref={roomInputRef}
|
||||
onEditLastMessage={() => editLastMessageRef.current?.()}
|
||||
/>
|
||||
)}
|
||||
{!canMessage && (
|
||||
|
||||
@@ -428,13 +428,25 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
|
||||
|
||||
const rootEvent = room.findEventById(threadRootId);
|
||||
|
||||
// When the drawer is opened with classic sync, room.createThread() may have
|
||||
// been called with empty initialEvents so thread.events only has the root.
|
||||
// Backfill events from the main room timeline into the Thread object so the
|
||||
// authoritative source is populated for subsequent renders and receipts.
|
||||
// When the drawer is opened with classic sync (no server-side thread support),
|
||||
// room.createThread() may have been called with empty initialEvents so
|
||||
// thread.events only has the root. Backfill events from the main room
|
||||
// timeline so the authoritative source is populated for subsequent renders.
|
||||
//
|
||||
// IMPORTANT: skip this backfill when server-side thread support is active
|
||||
// (initialEventsFetched starts false). In that case the SDK will call
|
||||
// updateThreadMetadata() → resetLiveTimeline() + paginateEventTimeline()
|
||||
// automatically. Calling thread.addEvents() ourselves first would trigger
|
||||
// that same cascade prematurely and cause a flood of
|
||||
// "EventTimelineSet.addEventToTimeline: Ignoring event=…" warnings because
|
||||
// canContain() fails while the timeline is in the middle of being reset and
|
||||
// repopulated.
|
||||
useEffect(() => {
|
||||
const thread = room.getThread(threadRootId);
|
||||
if (!thread) return;
|
||||
// initialEventsFetched === false ↔ Thread.hasServerSideSupport is set.
|
||||
// The SDK handles initialization itself; our manual backfill must not run.
|
||||
if (!thread.initialEventsFetched) return;
|
||||
const hasRepliesInThread = thread.events.some(
|
||||
(ev) => ev.getId() !== threadRootId && !reactionOrEditEvent(ev)
|
||||
);
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
as,
|
||||
config,
|
||||
} from 'folds';
|
||||
|
||||
import {
|
||||
MouseEventHandler,
|
||||
MouseEvent,
|
||||
@@ -35,6 +34,7 @@ import {
|
||||
Room,
|
||||
Relations,
|
||||
RoomPinnedEventsEventContent,
|
||||
MatrixEventEvent,
|
||||
} from '$types/matrix-sdk';
|
||||
import classNames from 'classnames';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
@@ -49,7 +49,7 @@ import {
|
||||
Username,
|
||||
UsernameBold,
|
||||
} from '$components/message';
|
||||
import { canEditEvent, getEventEdits, getMemberAvatarMxc } from '$utils/room';
|
||||
import { canEditEvent, getEditedEvent, getEventEdits, getMemberAvatarMxc } from '$utils/room';
|
||||
import { mxcUrlToHttp } from '$utils/matrix';
|
||||
import { getSettings, MessageLayout, MessageSpacing, settingsAtom } from '$state/settings';
|
||||
import { nicknamesAtom, setNicknameAtom } from '$state/nicknames';
|
||||
@@ -380,18 +380,40 @@ function MessageInternal(
|
||||
const mx = useMatrixClient();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
|
||||
const [contentVersion, setContentVersion] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const onUpdate = () => setContentVersion((v) => v + 1);
|
||||
mEvent.on(MatrixEventEvent.Decrypted, onUpdate);
|
||||
mEvent.on(MatrixEventEvent.Replaced, onUpdate);
|
||||
return () => {
|
||||
mEvent.off(MatrixEventEvent.Decrypted, onUpdate);
|
||||
mEvent.off(MatrixEventEvent.Replaced, onUpdate);
|
||||
};
|
||||
}, [mEvent]);
|
||||
|
||||
/**
|
||||
* We read the per-message profile from the event content here.
|
||||
* We have to do this in the message component because the per-message profile can be different for each message, and we need to read it for each message individually.
|
||||
* We also want to avoid reading and parsing the per-message profile in a parent component like the timeline, because that would be inefficient and would cause unnecessary re-renders of the entire timeline whenever a per-message profile changes.
|
||||
*/
|
||||
const pmp: PerMessageProfileBeeperFormat | undefined = useMemo(
|
||||
() =>
|
||||
mEvent.event.content?.['com.beeper.per_message_profile'] as
|
||||
| PerMessageProfileBeeperFormat
|
||||
| undefined,
|
||||
[mEvent]
|
||||
);
|
||||
const pmp: PerMessageProfileBeeperFormat | undefined = useMemo(() => {
|
||||
const evtId = mEvent.getId();
|
||||
const evtTimeline = evtId ? room.getTimelineForEvent(evtId) : undefined;
|
||||
const editedEvent =
|
||||
evtTimeline && evtId
|
||||
? getEditedEvent(evtId, mEvent, evtTimeline.getTimelineSet())
|
||||
: undefined;
|
||||
|
||||
const resolvedContent = editedEvent
|
||||
? editedEvent.getContent()['m.new_content']
|
||||
: mEvent.getContent();
|
||||
|
||||
return resolvedContent?.['com.beeper.per_message_profile'] as
|
||||
| PerMessageProfileBeeperFormat
|
||||
| undefined;
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [mEvent, room, contentVersion]);
|
||||
|
||||
/**
|
||||
* We convert the per-message profile from the Beeper format to our internal format here in the message component
|
||||
@@ -683,7 +705,7 @@ function MessageInternal(
|
||||
<MessageEditor
|
||||
style={{
|
||||
maxWidth: '100%',
|
||||
width: '100vw',
|
||||
width: '100%',
|
||||
}}
|
||||
roomId={room.roomId}
|
||||
room={room}
|
||||
@@ -1335,6 +1357,25 @@ export const Event = as<'div', EventProps>(
|
||||
>
|
||||
<Menu {...props} ref={ref}>
|
||||
<Box direction="Column" gap="100" className={css.MessageMenuGroup}>
|
||||
<MenuItem
|
||||
size="300"
|
||||
after={<Icon size="100" src={Icons.ReplyArrow} />}
|
||||
radii="300"
|
||||
data-event-id={mEvent.getId()}
|
||||
onClick={(evt: any) => {
|
||||
onReplyClick(evt);
|
||||
closeMenu();
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
className={css.MessageMenuItemText}
|
||||
as="span"
|
||||
size="T300"
|
||||
truncate
|
||||
>
|
||||
Reply
|
||||
</Text>
|
||||
</MenuItem>
|
||||
{!hideReadReceipts && (
|
||||
<MessageReadReceiptItem room={room} eventId={mEvent.getId() ?? ''} />
|
||||
)}
|
||||
|
||||
@@ -72,6 +72,7 @@ import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
import { GetContentCallback } from '$types/matrix/room';
|
||||
import { sanitizeCustomHtml } from '$utils/sanitize';
|
||||
|
||||
type MessageEditorProps = {
|
||||
roomId: string;
|
||||
@@ -105,10 +106,33 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
evtTimeline && getEditedEvent(evtId, mEvent, evtTimeline.getTimelineSet());
|
||||
|
||||
const content: IContent = editedEvent?.getContent()['m.new_content'] ?? mEvent.getContent();
|
||||
const { body, formatted_body: customHtml }: Record<string, unknown> = content;
|
||||
|
||||
let { body, formatted_body: customHtml }: Record<string, unknown> = content;
|
||||
const mMentions: IMentions | undefined = content['m.mentions'];
|
||||
|
||||
const rawPmp = content['com.beeper.per_message_profile'];
|
||||
const pmpDisplayname =
|
||||
rawPmp !== null &&
|
||||
typeof rawPmp === 'object' &&
|
||||
'displayname' in rawPmp &&
|
||||
typeof rawPmp.displayname === 'string' &&
|
||||
rawPmp.displayname.length > 0
|
||||
? (rawPmp.displayname as string)
|
||||
: undefined;
|
||||
|
||||
if (pmpDisplayname && typeof body === 'string') {
|
||||
const bodyPrefix = `${pmpDisplayname}: `;
|
||||
if (body.startsWith(bodyPrefix)) {
|
||||
body = body.slice(bodyPrefix.length);
|
||||
}
|
||||
}
|
||||
|
||||
if (pmpDisplayname && typeof customHtml === 'string') {
|
||||
customHtml = customHtml.replace(
|
||||
/^<strong\s+data-mx-profile-fallback[^>]*>.*?<\/strong>/,
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
typeof body === 'string' ? body : undefined,
|
||||
typeof customHtml === 'string' ? customHtml : undefined,
|
||||
@@ -119,8 +143,8 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
const [saveState, save] = useAsyncCallback(
|
||||
useCallback(async () => {
|
||||
const oldContent = mEvent.getContent();
|
||||
const plainText = toPlainText(editor.children, isMarkdown).trim();
|
||||
const customHtml = trimCustomHtml(
|
||||
let plainText = toPlainText(editor.children, isMarkdown).trim();
|
||||
let customHtml = trimCustomHtml(
|
||||
toMatrixCustomHTML(editor.children, {
|
||||
allowTextFormatting: true,
|
||||
allowBlockMarkdown: isMarkdown,
|
||||
@@ -154,6 +178,41 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
body: plainText,
|
||||
};
|
||||
|
||||
const evtId = mEvent.getId();
|
||||
const evtTimeline = evtId ? room.getTimelineForEvent(evtId) : undefined;
|
||||
const editedEvent =
|
||||
evtTimeline && evtId
|
||||
? getEditedEvent(evtId, mEvent, evtTimeline.getTimelineSet())
|
||||
: undefined;
|
||||
|
||||
const rawPmp =
|
||||
editedEvent?.getContent()?.['m.new_content']?.['com.beeper.per_message_profile'] ??
|
||||
mEvent.getContent()?.['com.beeper.per_message_profile'];
|
||||
|
||||
const pmpDisplayname =
|
||||
rawPmp !== null &&
|
||||
typeof rawPmp === 'object' &&
|
||||
'displayname' in rawPmp &&
|
||||
typeof rawPmp.displayname === 'string' &&
|
||||
rawPmp.displayname.length > 0
|
||||
? (rawPmp.displayname as string)
|
||||
: undefined;
|
||||
|
||||
if (pmpDisplayname) {
|
||||
const bodyPrefix = `${pmpDisplayname}: `;
|
||||
if (!plainText.startsWith(bodyPrefix)) {
|
||||
plainText = bodyPrefix + plainText;
|
||||
}
|
||||
|
||||
const escapedName = sanitizeCustomHtml(pmpDisplayname);
|
||||
const htmlPrefix = `<strong data-mx-profile-fallback>${escapedName}: </strong>`;
|
||||
if (!customHtml.startsWith(htmlPrefix)) {
|
||||
customHtml = htmlPrefix + customHtml;
|
||||
}
|
||||
|
||||
newContent['com.beeper.per_message_profile'] = rawPmp;
|
||||
}
|
||||
|
||||
const contentBody: IContent & Omit<ReplacementEvent<IContent>, 'm.relates_to'> = {
|
||||
msgtype,
|
||||
body: `* ${plainText}`,
|
||||
@@ -206,7 +265,7 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
}
|
||||
|
||||
return mx.sendMessage(roomId, content as any);
|
||||
}, [mx, editor, roomId, mEvent, isMarkdown, getPrevBodyAndFormattedBody])
|
||||
}, [mx, editor, roomId, mEvent, isMarkdown, getPrevBodyAndFormattedBody, room])
|
||||
);
|
||||
|
||||
const handleSave = useCallback(() => {
|
||||
@@ -351,7 +410,16 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
<Box
|
||||
style={
|
||||
captionPosition !== CaptionPosition.Inline
|
||||
? { marginTop: config.space.S400, width: '100%' }
|
||||
? {
|
||||
marginTop:
|
||||
msgType === MsgType.Image ||
|
||||
msgType === MsgType.Video ||
|
||||
msgType === MsgType.Audio ||
|
||||
msgType === MsgType.File
|
||||
? config.space.S400
|
||||
: undefined,
|
||||
width: '100%',
|
||||
}
|
||||
: {
|
||||
padding: config.space.S200,
|
||||
wordBreak: 'break-word',
|
||||
|
||||
@@ -59,8 +59,6 @@ export const getImageMsgContent = async (
|
||||
msgtype: MsgType.Image,
|
||||
filename: file.name,
|
||||
body: file.name,
|
||||
format: 'org.matrix.custom.html',
|
||||
formatted_body: file.name,
|
||||
[MATRIX_SPOILER_PROPERTY_NAME]: metadata.markedAsSpoiler,
|
||||
};
|
||||
if (imgEl) {
|
||||
@@ -101,8 +99,6 @@ export const getVideoMsgContent = async (
|
||||
msgtype: MsgType.Video,
|
||||
filename: file.name,
|
||||
body: file.name,
|
||||
format: 'org.matrix.custom.html',
|
||||
formatted_body: file.name,
|
||||
[MATRIX_SPOILER_PROPERTY_NAME]: metadata.markedAsSpoiler,
|
||||
};
|
||||
if (videoEl) {
|
||||
@@ -155,8 +151,6 @@ export const getAudioMsgContent = (item: TUploadItem, mxc: string): AudioMsgCont
|
||||
msgtype: MsgType.Audio,
|
||||
filename: file.name,
|
||||
body: item.body && item.body.length > 0 ? item.body : 'a voice message',
|
||||
format: 'org.matrix.custom.html',
|
||||
formatted_body: item.body && item.body.length > 0 ? item.body : '<em>a voice message</em>',
|
||||
info: {
|
||||
mimetype: file.type,
|
||||
size: file.size,
|
||||
@@ -220,8 +214,6 @@ export const getFileMsgContent = (item: TUploadItem, mxc: string): IContent => {
|
||||
msgtype: MsgType.File,
|
||||
filename: file.name,
|
||||
body: file.name,
|
||||
format: 'org.matrix.custom.html',
|
||||
formatted_body: file.name,
|
||||
info: {
|
||||
mimetype: file.type,
|
||||
size: file.size,
|
||||
|
||||
@@ -343,6 +343,52 @@ function ThemeSettings() {
|
||||
);
|
||||
}
|
||||
|
||||
function SubnestedSpaceLinkDepthInput() {
|
||||
const [subspaceHierarchyLimit, setSubspaceHierarchyLimit] = useSetting(
|
||||
settingsAtom,
|
||||
'subspaceHierarchyLimit'
|
||||
);
|
||||
const [inputValue, setInputValue] = useState(subspaceHierarchyLimit.toString());
|
||||
|
||||
const handleChange: ChangeEventHandler<HTMLInputElement> = (evt) => {
|
||||
const val = evt.target.value;
|
||||
setInputValue(val);
|
||||
|
||||
const parsed = parseInt(val, 10);
|
||||
if (!Number.isNaN(parsed) && parsed >= 2 && parsed <= 10) {
|
||||
setSubspaceHierarchyLimit(parsed);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown: KeyboardEventHandler<HTMLInputElement> = (evt) => {
|
||||
if (isKeyHotkey('escape', evt)) {
|
||||
evt.stopPropagation();
|
||||
setInputValue(subspaceHierarchyLimit.toString());
|
||||
(evt.target as HTMLInputElement).blur();
|
||||
}
|
||||
|
||||
if (isKeyHotkey('enter', evt)) {
|
||||
(evt.target as HTMLInputElement).blur();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Input
|
||||
style={{ width: toRem(80) }}
|
||||
variant={parseInt(inputValue, 10) === subspaceHierarchyLimit ? 'Secondary' : 'Success'}
|
||||
size="300"
|
||||
radii="300"
|
||||
type="number"
|
||||
min="1"
|
||||
max="10"
|
||||
value={inputValue}
|
||||
onChange={handleChange}
|
||||
onKeyDown={handleKeyDown}
|
||||
outlined
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function PageZoomInput() {
|
||||
const [pageZoom, setPageZoom] = useSetting(settingsAtom, 'pageZoom');
|
||||
const [currentZoom, setCurrentZoom] = useState(`${pageZoom}`);
|
||||
@@ -407,6 +453,14 @@ export function Appearance() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile title="Page Zoom" after={<PageZoomInput />} />
|
||||
</SequenceCard>
|
||||
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Subspace Hierarchy Limit"
|
||||
description="The maximum nesting depth for Subspaces in the sidebar. Once this limit is reached, deeper Subspaces appear as links instead of nested folders."
|
||||
after={<SubnestedSpaceLinkDepthInput />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { MouseEventHandler, useState } from 'react';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import { Box, Icon, Icons, Text, config, RectCords, Avatar } from 'folds';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { NavButton, NavItem, NavItemContent } from '$components/nav';
|
||||
import { useRoomName } from '$hooks/useRoomMeta';
|
||||
|
||||
type SpaceNavItemProps = {
|
||||
room: Room;
|
||||
selected: boolean;
|
||||
linkPath: string;
|
||||
};
|
||||
|
||||
export function SpaceNavItem({ room, selected, linkPath }: SpaceNavItemProps) {
|
||||
const [menuAnchor, setMenuAnchor] = useState<RectCords>();
|
||||
|
||||
const matrixRoomName = useRoomName(room);
|
||||
const roomName = matrixRoomName;
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleContextMenu: MouseEventHandler<HTMLElement> = (evt) => {
|
||||
evt.preventDefault();
|
||||
setMenuAnchor({
|
||||
x: evt.clientX,
|
||||
y: evt.clientY,
|
||||
width: 0,
|
||||
height: 0,
|
||||
});
|
||||
};
|
||||
|
||||
const handleNavItemClick: MouseEventHandler<HTMLElement> = () => {
|
||||
navigate(linkPath);
|
||||
};
|
||||
|
||||
const ariaLabel = [roomName, 'Space'].flat().filter(Boolean).join(', ');
|
||||
|
||||
return (
|
||||
<Box direction="Column" grow="Yes">
|
||||
<NavItem
|
||||
variant="Background"
|
||||
radii="400"
|
||||
highlight={false}
|
||||
aria-selected={selected}
|
||||
data-hover={!!menuAnchor}
|
||||
onContextMenu={handleContextMenu}
|
||||
>
|
||||
<NavButton onClick={handleNavItemClick} aria-label={ariaLabel}>
|
||||
<NavItemContent>
|
||||
<Box as="span" grow="Yes" alignItems="Center" gap="200">
|
||||
<Avatar size="200" radii="400">
|
||||
<Icon
|
||||
src={Icons.Space}
|
||||
style={{ opacity: config.opacity.P300 }}
|
||||
filled={selected}
|
||||
size="100"
|
||||
/>
|
||||
</Avatar>
|
||||
<Box as="span" grow="Yes">
|
||||
<Text priority="300" as="span" size="Inherit" truncate>
|
||||
{roomName}
|
||||
</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
</NavItemContent>
|
||||
</NavButton>
|
||||
</NavItem>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './SpaceNavItem';
|
||||
@@ -143,8 +143,15 @@ export function useProcessedTimeline({
|
||||
const typeMatch =
|
||||
normalizeMessageType(getPrevType.call(prevEvent)) === normalizeMessageType(type);
|
||||
const dividerOk = !newDivider || eventSender === mxUserId;
|
||||
const getPmpId = (ev: MatrixEvent): string | null =>
|
||||
ev.getContent()?.['com.beeper.per_message_profile']?.id ?? null;
|
||||
|
||||
collapsed = dividerOk && senderMatch && typeMatch && withinTimeThreshold;
|
||||
collapsed =
|
||||
dividerOk &&
|
||||
senderMatch &&
|
||||
typeMatch &&
|
||||
withinTimeThreshold &&
|
||||
getPmpId(prevEvent) === getPmpId(mEvent);
|
||||
} else {
|
||||
const prevIsMessageEvent = MESSAGE_EVENT_TYPES.includes(getPrevType.call(prevEvent));
|
||||
collapsed = !prevIsMessageEvent;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ReactEditor } from 'slate-react';
|
||||
|
||||
import { getMxIdLocalPart, toggleReaction } from '$utils/matrix';
|
||||
import { getMemberDisplayName, getEditedEvent } from '$utils/room';
|
||||
import { createMentionElement, moveCursor } from '$components/editor';
|
||||
import { createMentionElement, isEmptyEditor, moveCursor } from '$components/editor';
|
||||
|
||||
export interface UseTimelineActionsOptions {
|
||||
room: Room;
|
||||
@@ -216,10 +216,10 @@ export function useTimelineActions({
|
||||
return;
|
||||
}
|
||||
setEditId(undefined);
|
||||
onEditorReset?.();
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
if (!alive()) return;
|
||||
if (isEmptyEditor(editor)) onEditorReset?.();
|
||||
ReactEditor.focus(editor);
|
||||
moveCursor(editor);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MouseEventHandler } from 'react';
|
||||
import { MouseEventHandler, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import {
|
||||
@@ -71,30 +71,25 @@ function ThreadReplyChip({
|
||||
const nicknames = useAtomValue(nicknamesAtom);
|
||||
|
||||
const thread = room.getThread(mEventId);
|
||||
let replyEvents: MatrixEvent[] = [];
|
||||
|
||||
if (thread) {
|
||||
replyEvents = thread.events.filter((ev) => {
|
||||
const { getId: getEvId } = ev;
|
||||
return getEvId.call(ev) !== mEventId && !reactionOrEditEvent(ev);
|
||||
});
|
||||
} else {
|
||||
const replyEvents = useMemo(() => {
|
||||
const linkedTimelines = getLinkedTimelines(getLiveTimeline(room));
|
||||
const allEvents = linkedTimelines.flatMap((tl) => tl.getEvents() || []);
|
||||
replyEvents = allEvents.filter((ev) => {
|
||||
const { getId: getEvId, threadRootId } = ev;
|
||||
return threadRootId === mEventId && getEvId.call(ev) !== mEventId && !reactionOrEditEvent(ev);
|
||||
});
|
||||
}
|
||||
return linkedTimelines
|
||||
.flatMap((tl) => tl.getEvents())
|
||||
.filter(
|
||||
(ev) => ev.threadRootId === mEventId && ev.getId() !== mEventId && !reactionOrEditEvent(ev)
|
||||
);
|
||||
}, [room, mEventId]);
|
||||
|
||||
const replyCount = replyEvents.length;
|
||||
if (!thread) return null;
|
||||
|
||||
const replyCount = thread.length ?? 0;
|
||||
if (replyCount === 0) return null;
|
||||
|
||||
const uniqueSenders: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
replyEvents.forEach((ev) => {
|
||||
const { getSender: getEvSender } = ev;
|
||||
const s = getEvSender.call(ev);
|
||||
const s = ev.getSender();
|
||||
if (s && !seen.has(s)) {
|
||||
seen.add(s);
|
||||
uniqueSenders.push(s);
|
||||
@@ -104,11 +99,9 @@ function ThreadReplyChip({
|
||||
const latestReply = replyEvents.at(-1);
|
||||
let latestSenderId = '';
|
||||
let latestBody = '';
|
||||
|
||||
if (latestReply) {
|
||||
const { getSender: getLatestSender, getContent: getLatestContent } = latestReply;
|
||||
latestSenderId = getLatestSender.call(latestReply) ?? '';
|
||||
latestBody = (getLatestContent.call(latestReply)?.body as string | undefined) ?? '';
|
||||
latestSenderId = latestReply.getSender() ?? '';
|
||||
latestBody = (latestReply.getContent()?.body as string | undefined) ?? '';
|
||||
}
|
||||
|
||||
const latestSenderName =
|
||||
@@ -124,32 +117,34 @@ function ThreadReplyChip({
|
||||
variant={isOpen ? 'Primary' : 'SurfaceVariant'}
|
||||
radii="300"
|
||||
before={
|
||||
<Box alignItems="Center" style={{ gap: 0 }}>
|
||||
{uniqueSenders.slice(0, 3).map((senderId, index) => {
|
||||
const avatarMxc = getMemberAvatarMxc(room, senderId);
|
||||
const avatarUrl = avatarMxc
|
||||
? (mxcUrlToHttp(mx, avatarMxc, useAuthentication, 20, 20, 'crop') ?? undefined)
|
||||
: undefined;
|
||||
const displayName =
|
||||
getMemberDisplayName(room, senderId, nicknames) ??
|
||||
getMxIdLocalPart(senderId) ??
|
||||
senderId;
|
||||
return (
|
||||
<Avatar key={senderId} size="200" style={{ marginLeft: index > 0 ? '-4px' : 0 }}>
|
||||
<UserAvatar
|
||||
userId={senderId}
|
||||
src={avatarUrl}
|
||||
alt={displayName}
|
||||
renderFallback={() => (
|
||||
<span style={{ fontSize: '10px', fontWeight: 'bold', lineHeight: 1 }}>
|
||||
{displayName[0]?.toUpperCase() ?? '?'}
|
||||
</span>
|
||||
)}
|
||||
/>
|
||||
</Avatar>
|
||||
);
|
||||
})}
|
||||
</Box>
|
||||
uniqueSenders.length > 0 ? (
|
||||
<Box alignItems="Center" style={{ gap: 0 }}>
|
||||
{uniqueSenders.slice(0, 3).map((senderId, index) => {
|
||||
const avatarMxc = getMemberAvatarMxc(room, senderId);
|
||||
const avatarUrl = avatarMxc
|
||||
? (mxcUrlToHttp(mx, avatarMxc, useAuthentication, 20, 20, 'crop') ?? undefined)
|
||||
: undefined;
|
||||
const displayName =
|
||||
getMemberDisplayName(room, senderId, nicknames) ??
|
||||
getMxIdLocalPart(senderId) ??
|
||||
senderId;
|
||||
return (
|
||||
<Avatar key={senderId} size="200" style={{ marginLeft: index > 0 ? '-4px' : 0 }}>
|
||||
<UserAvatar
|
||||
userId={senderId}
|
||||
src={avatarUrl}
|
||||
alt={displayName}
|
||||
renderFallback={() => (
|
||||
<span style={{ fontSize: '10px', fontWeight: 'bold', lineHeight: 1 }}>
|
||||
{displayName[0]?.toUpperCase() ?? '?'}
|
||||
</span>
|
||||
)}
|
||||
/>
|
||||
</Avatar>
|
||||
);
|
||||
})}
|
||||
</Box>
|
||||
) : undefined
|
||||
}
|
||||
onClick={onToggle}
|
||||
style={{ marginTop: config.space.S200 }}
|
||||
@@ -174,7 +169,6 @@ function ThreadReplyChip({
|
||||
</Chip>
|
||||
);
|
||||
}
|
||||
|
||||
export interface TimelineEventRendererOptions {
|
||||
room: Room;
|
||||
mx: MatrixClient;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { atom, useAtom, useAtomValue } from 'jotai';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { MatrixError, Room, IHierarchyRoom } from '$types/matrix-sdk';
|
||||
import { MatrixError, MatrixEvent, Room, IHierarchyRoom } from '$types/matrix-sdk';
|
||||
import { QueryFunction, useInfiniteQuery } from '@tanstack/react-query';
|
||||
import { MSpaceChildContent, StateEvent } from '$types/matrix/room';
|
||||
import { roomToParentsAtom } from '$state/room/roomToParents';
|
||||
@@ -8,6 +8,7 @@ import { getAllParents, getStateEvents, isValidChild } from '$utils/room';
|
||||
import { isRoomId } from '$utils/matrix';
|
||||
import { SortFunc, byOrderKey, byTsOldToNew, factoryRoomIdByActivity } from '$utils/sort';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { makeLobbyCategoryId } from '../state/closedLobbyCategories';
|
||||
import { useStateEventCallback } from './useStateEventCallback';
|
||||
import { ErrorCode } from '../cs-errorcode';
|
||||
|
||||
@@ -17,6 +18,7 @@ export type HierarchyItemSpace = {
|
||||
ts: number;
|
||||
space: true;
|
||||
parentId?: string;
|
||||
depth: number;
|
||||
};
|
||||
|
||||
export type HierarchyItemRoom = {
|
||||
@@ -24,6 +26,7 @@ export type HierarchyItemRoom = {
|
||||
content: MSpaceChildContent;
|
||||
ts: number;
|
||||
parentId: string;
|
||||
depth: number;
|
||||
};
|
||||
|
||||
export type HierarchyItem = HierarchyItemSpace | HierarchyItemRoom;
|
||||
@@ -34,9 +37,14 @@ const hierarchyItemTs: SortFunc<HierarchyItem> = (a, b) => byTsOldToNew(a.ts, b.
|
||||
const hierarchyItemByOrder: SortFunc<HierarchyItem> = (a, b) =>
|
||||
byOrderKey(a.content.order, b.content.order);
|
||||
|
||||
const childEventTs: SortFunc<MatrixEvent> = (a, b) => byTsOldToNew(a.getTs(), b.getTs());
|
||||
const childEventByOrder: SortFunc<MatrixEvent> = (a, b) =>
|
||||
byOrderKey(a.getContent<MSpaceChildContent>().order, b.getContent<MSpaceChildContent>().order);
|
||||
|
||||
const getHierarchySpaces = (
|
||||
rootSpaceId: string,
|
||||
getRoom: GetRoomCallback,
|
||||
excludeRoom: (parentId: string, roomId: string, depth: number) => boolean,
|
||||
spaceRooms: Set<string>
|
||||
): HierarchyItemSpace[] => {
|
||||
const rootSpaceItem: HierarchyItemSpace = {
|
||||
@@ -44,46 +52,56 @@ const getHierarchySpaces = (
|
||||
content: { via: [] },
|
||||
ts: 0,
|
||||
space: true,
|
||||
depth: 0,
|
||||
};
|
||||
let spaceItems: HierarchyItemSpace[] = [];
|
||||
const spaceItems: HierarchyItemSpace[] = [];
|
||||
|
||||
const findAndCollectHierarchySpaces = (
|
||||
spaceItem: HierarchyItemSpace,
|
||||
parentSpaceId: string,
|
||||
visited: Set<string> = new Set()
|
||||
) => {
|
||||
const spaceItemId = makeLobbyCategoryId(parentSpaceId, spaceItem.roomId);
|
||||
|
||||
// Prevent infinite recursion
|
||||
if (visited.has(spaceItemId)) return;
|
||||
visited.add(spaceItemId);
|
||||
|
||||
const findAndCollectHierarchySpaces = (spaceItem: HierarchyItemSpace) => {
|
||||
if (spaceItems.find((item) => item.roomId === spaceItem.roomId)) return;
|
||||
const space = getRoom(spaceItem.roomId);
|
||||
spaceItems.push(spaceItem);
|
||||
|
||||
if (!space) return;
|
||||
const childEvents = getStateEvents(space, StateEvent.SpaceChild);
|
||||
const childEvents = getStateEvents(space, StateEvent.SpaceChild)
|
||||
.filter((childEvent) => {
|
||||
if (!isValidChild(childEvent)) return false;
|
||||
const childId = childEvent.getStateKey();
|
||||
if (!childId || !isRoomId(childId)) return false;
|
||||
if (excludeRoom(spaceItem.roomId, childId, spaceItem.depth)) return false;
|
||||
|
||||
// because we can not find if a childId is space without joining
|
||||
// or requesting room summary, we will look it into spaceRooms local
|
||||
// cache which we maintain as we load summary in UI.
|
||||
return getRoom(childId)?.isSpaceRoom() || spaceRooms.has(childId);
|
||||
})
|
||||
.sort(childEventTs)
|
||||
.sort(childEventByOrder);
|
||||
|
||||
childEvents.forEach((childEvent) => {
|
||||
if (!isValidChild(childEvent)) return;
|
||||
const childId = childEvent.getStateKey();
|
||||
if (!childId || !isRoomId(childId)) return;
|
||||
|
||||
// because we can not find if a childId is space without joining
|
||||
// or requesting room summary, we will look it into spaceRooms local
|
||||
// cache which we maintain as we load summary in UI.
|
||||
if (getRoom(childId)?.isSpaceRoom() || spaceRooms.has(childId)) {
|
||||
const childItem: HierarchyItemSpace = {
|
||||
roomId: childId,
|
||||
content: childEvent.getContent<MSpaceChildContent>(),
|
||||
ts: childEvent.getTs(),
|
||||
space: true,
|
||||
parentId: spaceItem.roomId,
|
||||
};
|
||||
findAndCollectHierarchySpaces(childItem);
|
||||
}
|
||||
const childItem: HierarchyItemSpace = {
|
||||
roomId: childId,
|
||||
content: childEvent.getContent<MSpaceChildContent>(),
|
||||
ts: childEvent.getTs(),
|
||||
space: true,
|
||||
parentId: spaceItem.roomId,
|
||||
depth: spaceItem.depth + 1,
|
||||
};
|
||||
findAndCollectHierarchySpaces(childItem, spaceItem.roomId, visited);
|
||||
});
|
||||
};
|
||||
findAndCollectHierarchySpaces(rootSpaceItem);
|
||||
|
||||
spaceItems = [
|
||||
rootSpaceItem,
|
||||
...spaceItems
|
||||
.filter((item) => item.roomId !== rootSpaceId)
|
||||
.sort(hierarchyItemTs)
|
||||
.sort(hierarchyItemByOrder),
|
||||
];
|
||||
findAndCollectHierarchySpaces(rootSpaceItem, rootSpaceId);
|
||||
|
||||
return spaceItems;
|
||||
};
|
||||
@@ -96,9 +114,15 @@ const getSpaceHierarchy = (
|
||||
rootSpaceId: string,
|
||||
spaceRooms: Set<string>,
|
||||
getRoom: (roomId: string) => Room | undefined,
|
||||
excludeRoom: (parentId: string, roomId: string, depth: number) => boolean,
|
||||
closedCategory: (spaceId: string) => boolean
|
||||
): SpaceHierarchy[] => {
|
||||
const spaceItems: HierarchyItemSpace[] = getHierarchySpaces(rootSpaceId, getRoom, spaceRooms);
|
||||
const spaceItems: HierarchyItemSpace[] = getHierarchySpaces(
|
||||
rootSpaceId,
|
||||
getRoom,
|
||||
excludeRoom,
|
||||
spaceRooms
|
||||
);
|
||||
|
||||
const hierarchy: SpaceHierarchy[] = spaceItems.map((spaceItem) => {
|
||||
const space = getRoom(spaceItem.roomId);
|
||||
@@ -120,6 +144,7 @@ const getSpaceHierarchy = (
|
||||
content: childEvent.getContent<MSpaceChildContent>(),
|
||||
ts: childEvent.getTs(),
|
||||
parentId: spaceItem.roomId,
|
||||
depth: spaceItem.depth,
|
||||
};
|
||||
childItems.push(childItem);
|
||||
});
|
||||
@@ -137,19 +162,20 @@ export const useSpaceHierarchy = (
|
||||
spaceId: string,
|
||||
spaceRooms: Set<string>,
|
||||
getRoom: (roomId: string) => Room | undefined,
|
||||
excludeRoom: (parentId: string, roomId: string, depth: number) => boolean,
|
||||
closedCategory: (spaceId: string) => boolean
|
||||
): SpaceHierarchy[] => {
|
||||
const mx = useMatrixClient();
|
||||
const roomToParents = useAtomValue(roomToParentsAtom);
|
||||
|
||||
const [hierarchyAtom] = useState(() =>
|
||||
atom(getSpaceHierarchy(spaceId, spaceRooms, getRoom, closedCategory))
|
||||
atom(getSpaceHierarchy(spaceId, spaceRooms, getRoom, excludeRoom, closedCategory))
|
||||
);
|
||||
const [hierarchy, setHierarchy] = useAtom(hierarchyAtom);
|
||||
|
||||
useEffect(() => {
|
||||
setHierarchy(getSpaceHierarchy(spaceId, spaceRooms, getRoom, closedCategory));
|
||||
}, [mx, spaceId, spaceRooms, setHierarchy, getRoom, closedCategory]);
|
||||
setHierarchy(getSpaceHierarchy(spaceId, spaceRooms, getRoom, excludeRoom, closedCategory));
|
||||
}, [mx, spaceId, spaceRooms, setHierarchy, getRoom, closedCategory, excludeRoom]);
|
||||
|
||||
useStateEventCallback(
|
||||
mx,
|
||||
@@ -160,10 +186,12 @@ export const useSpaceHierarchy = (
|
||||
if (!eventRoomId) return;
|
||||
|
||||
if (spaceId === eventRoomId || getAllParents(roomToParents, eventRoomId).has(spaceId)) {
|
||||
setHierarchy(getSpaceHierarchy(spaceId, spaceRooms, getRoom, closedCategory));
|
||||
setHierarchy(
|
||||
getSpaceHierarchy(spaceId, spaceRooms, getRoom, excludeRoom, closedCategory)
|
||||
);
|
||||
}
|
||||
},
|
||||
[spaceId, roomToParents, setHierarchy, spaceRooms, getRoom, closedCategory]
|
||||
[spaceId, roomToParents, setHierarchy, spaceRooms, getRoom, closedCategory, excludeRoom]
|
||||
)
|
||||
);
|
||||
|
||||
@@ -173,10 +201,44 @@ export const useSpaceHierarchy = (
|
||||
const getSpaceJoinedHierarchy = (
|
||||
rootSpaceId: string,
|
||||
getRoom: GetRoomCallback,
|
||||
excludeRoom: (parentId: string, roomId: string) => boolean,
|
||||
excludeRoom: (parentId: string, roomId: string, depth: number) => boolean,
|
||||
sortRoomItems: (parentId: string, items: HierarchyItem[]) => HierarchyItem[]
|
||||
): HierarchyItem[] => {
|
||||
const spaceItems: HierarchyItemSpace[] = getHierarchySpaces(rootSpaceId, getRoom, new Set());
|
||||
const spaceItems: HierarchyItemSpace[] = getHierarchySpaces(
|
||||
rootSpaceId,
|
||||
getRoom,
|
||||
excludeRoom,
|
||||
new Set()
|
||||
);
|
||||
|
||||
/**
|
||||
* Recursively checks if the given space or any of its descendants contain non-space rooms.
|
||||
*
|
||||
* @param spaceId - The space ID to check.
|
||||
* @param visited - Set used to prevent recursion errors.
|
||||
* @returns True if the space or any descendant contains non-space rooms.
|
||||
*/
|
||||
const getContainsRoom = (spaceId: string, visited: Set<string> = new Set()) => {
|
||||
// Prevent infinite recursion
|
||||
if (visited.has(spaceId)) return false;
|
||||
visited.add(spaceId);
|
||||
|
||||
const space = getRoom(spaceId);
|
||||
if (!space) return false;
|
||||
|
||||
const childEvents = getStateEvents(space, StateEvent.SpaceChild);
|
||||
|
||||
return childEvents.some((childEvent): boolean => {
|
||||
if (!isValidChild(childEvent)) return false;
|
||||
const childId = childEvent.getStateKey();
|
||||
if (!childId || !isRoomId(childId)) return false;
|
||||
const room = getRoom(childId);
|
||||
if (!room) return false;
|
||||
|
||||
if (!room.isSpaceRoom()) return true;
|
||||
return getContainsRoom(childId, visited);
|
||||
});
|
||||
};
|
||||
|
||||
const hierarchy: HierarchyItem[] = spaceItems.flatMap((spaceItem) => {
|
||||
const space = getRoom(spaceItem.roomId);
|
||||
@@ -193,20 +255,21 @@ const getSpaceJoinedHierarchy = (
|
||||
return true;
|
||||
});
|
||||
|
||||
if (joinedRoomEvents.length === 0) return [];
|
||||
if (!getContainsRoom(spaceItem.roomId)) return [];
|
||||
|
||||
const childItems: HierarchyItemRoom[] = [];
|
||||
joinedRoomEvents.forEach((childEvent) => {
|
||||
const childId = childEvent.getStateKey();
|
||||
if (!childId) return;
|
||||
|
||||
if (excludeRoom(space.roomId, childId)) return;
|
||||
if (excludeRoom(space.roomId, childId, spaceItem.depth)) return;
|
||||
|
||||
const childItem: HierarchyItemRoom = {
|
||||
roomId: childId,
|
||||
content: childEvent.getContent<MSpaceChildContent>(),
|
||||
ts: childEvent.getTs(),
|
||||
parentId: spaceItem.roomId,
|
||||
depth: spaceItem.depth,
|
||||
};
|
||||
childItems.push(childItem);
|
||||
});
|
||||
@@ -219,7 +282,7 @@ const getSpaceJoinedHierarchy = (
|
||||
export const useSpaceJoinedHierarchy = (
|
||||
spaceId: string,
|
||||
getRoom: GetRoomCallback,
|
||||
excludeRoom: (parentId: string, roomId: string) => boolean,
|
||||
excludeRoom: (parentId: string, roomId: string, depth: number) => boolean,
|
||||
sortByActivity: (spaceId: string) => boolean
|
||||
): HierarchyItem[] => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
import { MouseEventHandler, forwardRef, useCallback, useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
MouseEventHandler,
|
||||
ReactElement,
|
||||
forwardRef,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import {
|
||||
Avatar,
|
||||
@@ -18,7 +27,7 @@ import {
|
||||
config,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import { useVirtualizer } from '@tanstack/react-virtual';
|
||||
import { useVirtualizer, VirtualItem } from '@tanstack/react-virtual';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { JoinRule, Room, RoomJoinRulesEventContent } from '$types/matrix-sdk';
|
||||
@@ -31,18 +40,21 @@ import { useSelectedRoom } from '$hooks/router/useSelectedRoom';
|
||||
import { useSpaceLobbySelected, useSpaceSearchSelected } from '$hooks/router/useSelectedSpace';
|
||||
import { useSpace } from '$hooks/useSpace';
|
||||
import { VirtualTile } from '$components/virtualizer';
|
||||
import { spaceRoomsAtom } from '$state/spaceRooms';
|
||||
import { RoomNavCategoryButton, RoomNavItem } from '$features/room-nav';
|
||||
import { makeNavCategoryId } from '$state/closedNavCategories';
|
||||
import { SpaceNavItem } from '$features/space-nav';
|
||||
import { makeNavCategoryId, getNavCategoryIdParts } from '$state/closedNavCategories';
|
||||
import { roomToUnreadAtom } from '$state/room/roomToUnread';
|
||||
import { useCategoryHandler } from '$hooks/useCategoryHandler';
|
||||
import { useNavToActivePathMapper } from '$hooks/useNavToActivePathMapper';
|
||||
import { useRoomName } from '$hooks/useRoomMeta';
|
||||
import { useSpaceJoinedHierarchy } from '$hooks/useSpaceHierarchy';
|
||||
import { HierarchyItem, useSpaceJoinedHierarchy } from '$hooks/useSpaceHierarchy';
|
||||
import { allRoomsAtom } from '$state/room-list/roomList';
|
||||
import { PageNav, PageNavContent, PageNavHeader } from '$components/page';
|
||||
import { usePowerLevels } from '$hooks/usePowerLevels';
|
||||
import { useRecursiveChildScopeFactory, useSpaceChildren } from '$state/hooks/roomList';
|
||||
import { roomToParentsAtom } from '$state/room/roomToParents';
|
||||
import { roomToChildrenAtom } from '$state/room/roomToChildren';
|
||||
import { markAsRead } from '$utils/notifications';
|
||||
import { useRoomsUnread } from '$state/hooks/unread';
|
||||
import { UseStateProvider } from '$components/UseStateProvider';
|
||||
@@ -375,7 +387,10 @@ export function Space() {
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
const mDirects = useAtomValue(mDirectAtom);
|
||||
const roomToUnread = useAtomValue(roomToUnreadAtom);
|
||||
const roomToParents = useAtomValue(roomToParentsAtom);
|
||||
const roomToChildren = useAtomValue(roomToChildrenAtom);
|
||||
const allRooms = useAtomValue(allRoomsAtom);
|
||||
const [spaceRooms] = useAtom(spaceRoomsAtom);
|
||||
const allJoinedRooms = useMemo(() => new Set(allRooms), [allRooms]);
|
||||
const notificationPreferences = useRoomsNotificationPreferencesContext();
|
||||
|
||||
@@ -397,25 +412,261 @@ export function Space() {
|
||||
[mx, allJoinedRooms]
|
||||
);
|
||||
|
||||
const closedCategoriesCache = useRef(new Map());
|
||||
const ancestorsCollapsedCache = useRef(new Map());
|
||||
useEffect(() => {
|
||||
closedCategoriesCache.current.clear();
|
||||
ancestorsCollapsedCache.current.clear();
|
||||
}, [closedCategories, roomToParents, getRoom]);
|
||||
|
||||
/**
|
||||
* Recursively checks if a given parentId (or all its ancestors) is in a closed category.
|
||||
*
|
||||
* @param spaceId - The root space ID.
|
||||
* @param parentId - The parent space ID to start the check from.
|
||||
* @param previousId - The last ID checked, only used to ignore root collapse state.
|
||||
* @param visited - Set used to prevent recursion errors.
|
||||
* @returns True if parentId or all ancestors is in a closed category.
|
||||
*/
|
||||
const getInClosedCategories = useCallback(
|
||||
(
|
||||
spaceId: string,
|
||||
parentId: string,
|
||||
previousId?: string,
|
||||
visited: Set<string> = new Set()
|
||||
): boolean => {
|
||||
// Ignore root space being collapsed if in a subspace,
|
||||
// this is due to many spaces dumping all rooms in the top-level space.
|
||||
if (parentId === spaceId && previousId) {
|
||||
if (spaceRooms.has(previousId) || getRoom(previousId)?.isSpaceRoom()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const categoryId = makeNavCategoryId(spaceId, parentId);
|
||||
|
||||
// Prevent infinite recursion
|
||||
if (visited.has(categoryId)) return false;
|
||||
visited.add(categoryId);
|
||||
|
||||
if (closedCategoriesCache.current.has(categoryId)) {
|
||||
return closedCategoriesCache.current.get(categoryId);
|
||||
}
|
||||
|
||||
if (closedCategories.has(categoryId)) {
|
||||
closedCategoriesCache.current.set(categoryId, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
const parentParentIds = roomToParents.get(parentId);
|
||||
if (!parentParentIds || parentParentIds.size === 0) {
|
||||
closedCategoriesCache.current.set(categoryId, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// As a subspace can be in multiple spaces,
|
||||
// only return true if all parent spaces are closed.
|
||||
const allClosed = !Array.from(parentParentIds).some(
|
||||
(id) => !getInClosedCategories(spaceId, id, parentId, visited)
|
||||
);
|
||||
visited.delete(categoryId);
|
||||
closedCategoriesCache.current.set(categoryId, allClosed);
|
||||
return allClosed;
|
||||
},
|
||||
[closedCategories, getRoom, roomToParents, spaceRooms]
|
||||
);
|
||||
|
||||
/**
|
||||
* Recursively checks if the given room or any of its descendants should be visible.
|
||||
*
|
||||
* @param roomId - The room ID to check.
|
||||
* @param visited - Set used to prevent recursion errors.
|
||||
* @returns True if the room or any descendant should be visible.
|
||||
*/
|
||||
const getContainsShowRoom = useCallback(
|
||||
(roomId: string, visited: Set<string> = new Set()): boolean => {
|
||||
if (roomToUnread.has(roomId) || roomId === selectedRoomId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prevent infinite recursion
|
||||
if (visited.has(roomId)) return false;
|
||||
visited.add(roomId);
|
||||
|
||||
const childIds = roomToChildren.get(roomId);
|
||||
if (!childIds || childIds.size === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Array.from(childIds).some((id) => getContainsShowRoom(id, visited));
|
||||
},
|
||||
[roomToUnread, selectedRoomId, roomToChildren]
|
||||
);
|
||||
|
||||
/**
|
||||
* Determines whether all parent categories are collapsed.
|
||||
*
|
||||
* @param spaceId - The root space ID.
|
||||
* @param roomId - The room ID to start the check from.
|
||||
* @returns True if every parent category is collapsed; false otherwise.
|
||||
*/
|
||||
const getAllAncestorsCollapsed = (spaceId: string, roomId: string): boolean => {
|
||||
const categoryId = makeNavCategoryId(spaceId, roomId);
|
||||
if (ancestorsCollapsedCache.current.has(categoryId)) {
|
||||
return ancestorsCollapsedCache.current.get(categoryId);
|
||||
}
|
||||
|
||||
const parentIds = roomToParents.get(roomId);
|
||||
if (!parentIds || parentIds.size === 0) {
|
||||
ancestorsCollapsedCache.current.set(categoryId, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
const allCollapsed = !Array.from(parentIds).some(
|
||||
(id) => !getInClosedCategories(spaceId, id, roomId)
|
||||
);
|
||||
ancestorsCollapsedCache.current.set(categoryId, allCollapsed);
|
||||
return allCollapsed;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines the depth limit for the joined space hierarchy and the SpaceNavItems to start appearing
|
||||
*/
|
||||
const [subspaceHierarchyLimit] = useSetting(settingsAtom, 'subspaceHierarchyLimit');
|
||||
/**
|
||||
* Creates an SVG used for connecting spaces to their subrooms.
|
||||
* @param virtualizedItems - The virtualized item list that will be used to render elements in the nav
|
||||
* @returns React SVG Element that can be overlayed on top of the nav category for rooms.
|
||||
*/
|
||||
const getConnectorSVG = (
|
||||
hierarchy: HierarchyItem[],
|
||||
virtualizedItems: VirtualItem[]
|
||||
): ReactElement => {
|
||||
const DEPTH_START = 2;
|
||||
const PADDING_LEFT_DEPTH_OFFSET = 15.75;
|
||||
const PADDING_LEFT_DEPTH_OFFSET_START = -15.75;
|
||||
const RADIUS = 5;
|
||||
|
||||
let connectorStack: { aX: number; aY: number }[] = [];
|
||||
// Holder for the paths
|
||||
const pathHolder: ReactElement[] = [];
|
||||
virtualizedItems.forEach((vItem) => {
|
||||
const { roomId, depth } = hierarchy[vItem.index] ?? {};
|
||||
const room = getRoom(roomId);
|
||||
// We will render spaces at a level above their normal depth, since we want their children to be "under" them
|
||||
const renderDepth = room?.isSpaceRoom() ? depth : depth + 1;
|
||||
// for the root items, we are not doing anything with it.
|
||||
if (renderDepth < DEPTH_START) {
|
||||
return;
|
||||
}
|
||||
// for nearly root level text/call rooms, we will not be drawing any arcs.
|
||||
if (renderDepth === DEPTH_START - 1 && !room?.isSpaceRoom() && connectorStack.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// for the sub-root items, we will not draw any arcs from root to it.
|
||||
// however, we should capture the aX and aY to draw starter arcs for next depths.
|
||||
if (renderDepth === DEPTH_START) {
|
||||
connectorStack = [
|
||||
{
|
||||
aX: PADDING_LEFT_DEPTH_OFFSET * DEPTH_START + PADDING_LEFT_DEPTH_OFFSET_START,
|
||||
aY: vItem.end,
|
||||
},
|
||||
];
|
||||
return;
|
||||
}
|
||||
// adjust the stack to be at the correct depth, which is the "parent" of the current item.
|
||||
while (connectorStack.length + DEPTH_START > renderDepth && connectorStack.length !== 0) {
|
||||
connectorStack.pop();
|
||||
}
|
||||
|
||||
// Fixes crash in case the top level virtual item is unrendered.
|
||||
if (connectorStack.length === 0) {
|
||||
connectorStack = [{ aX: Math.round(renderDepth * PADDING_LEFT_DEPTH_OFFSET), aY: 0 }];
|
||||
}
|
||||
|
||||
const lastConnector = connectorStack[connectorStack.length - 1];
|
||||
|
||||
// aX: numeric x where the vertical connector starts
|
||||
// aY: end of parent (already numeric)
|
||||
const { aX, aY } = lastConnector;
|
||||
|
||||
// bX: point where the vertical connector ends
|
||||
const bX = Math.round(
|
||||
(renderDepth - 0.5) * PADDING_LEFT_DEPTH_OFFSET + PADDING_LEFT_DEPTH_OFFSET_START
|
||||
);
|
||||
// bY: center of current item
|
||||
const bY = vItem.end - vItem.size / 2;
|
||||
|
||||
const pathString =
|
||||
`M ${aX} ${aY} ` +
|
||||
`L ${aX} ${bY - RADIUS} ` +
|
||||
`A ${RADIUS} ${RADIUS} 0 0 0 ${aX + RADIUS} ${bY} ` +
|
||||
`L ${bX} ${bY}`;
|
||||
|
||||
pathHolder.push(
|
||||
<path
|
||||
d={pathString}
|
||||
fill="none"
|
||||
stroke={color.Surface.ContainerLine}
|
||||
strokeWidth="2"
|
||||
display="block"
|
||||
/>
|
||||
);
|
||||
|
||||
// add this item to the connector stack, in case the next item's depth is higher.
|
||||
connectorStack.push({
|
||||
aX: Math.round(renderDepth * PADDING_LEFT_DEPTH_OFFSET) + PADDING_LEFT_DEPTH_OFFSET_START,
|
||||
aY: vItem.end,
|
||||
});
|
||||
});
|
||||
return (
|
||||
<svg
|
||||
style={{
|
||||
position: 'absolute',
|
||||
inset: 0,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
>
|
||||
{pathHolder}
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
|
||||
const hierarchy = useSpaceJoinedHierarchy(
|
||||
space.roomId,
|
||||
getRoom,
|
||||
useCallback(
|
||||
(parentId, roomId) => {
|
||||
if (!closedCategories.has(makeNavCategoryId(space.roomId, parentId))) {
|
||||
(parentId, roomId, depth) => {
|
||||
if (depth >= subspaceHierarchyLimit) {
|
||||
// we will exclude items above this depth
|
||||
return true;
|
||||
}
|
||||
if (!getInClosedCategories(space.roomId, parentId, roomId)) {
|
||||
return false;
|
||||
}
|
||||
const unread = roomToUnread.get(roomId);
|
||||
const containsShowRoom = getContainsShowRoom(roomId);
|
||||
const hasUnread = !!unread && (unread.total > 0 || unread.highlight > 0);
|
||||
const showRoomAnyway =
|
||||
hasUnread || roomId === selectedRoomId || callEmbed?.roomId === roomId;
|
||||
return !showRoomAnyway;
|
||||
return containsShowRoom || !showRoomAnyway;
|
||||
},
|
||||
[space.roomId, closedCategories, roomToUnread, selectedRoomId, callEmbed]
|
||||
[
|
||||
getContainsShowRoom,
|
||||
getInClosedCategories,
|
||||
space.roomId,
|
||||
callEmbed,
|
||||
subspaceHierarchyLimit,
|
||||
roomToUnread,
|
||||
selectedRoomId,
|
||||
]
|
||||
),
|
||||
useCallback(
|
||||
(sId) => closedCategories.has(makeNavCategoryId(space.roomId, sId)),
|
||||
[closedCategories, space.roomId]
|
||||
(sId) => getInClosedCategories(space.roomId, sId),
|
||||
[getInClosedCategories, space.roomId]
|
||||
)
|
||||
);
|
||||
|
||||
@@ -426,13 +677,30 @@ export function Space() {
|
||||
overscan: 10,
|
||||
});
|
||||
|
||||
const handleCategoryClick = useCategoryHandler(setClosedCategories, (categoryId) =>
|
||||
closedCategories.has(categoryId)
|
||||
);
|
||||
const virtualizedItems = virtualizer.getVirtualItems();
|
||||
|
||||
const handleCategoryClick = useCategoryHandler(setClosedCategories, (categoryId) => {
|
||||
const collapsed = closedCategories.has(categoryId);
|
||||
const [spaceId, roomId] = getNavCategoryIdParts(categoryId);
|
||||
|
||||
// Only prevent collapsing if all parents are collapsed
|
||||
const toggleable = !getAllAncestorsCollapsed(spaceId, roomId);
|
||||
|
||||
if (toggleable) {
|
||||
return collapsed;
|
||||
}
|
||||
return !collapsed;
|
||||
});
|
||||
|
||||
const getToLink = (roomId: string) =>
|
||||
getSpaceRoomPath(spaceIdOrAlias, getCanonicalAliasOrRoomId(mx, roomId));
|
||||
|
||||
const getCategoryPadding = (depth: number): string | undefined => {
|
||||
if (depth === 0) return undefined;
|
||||
if (depth === 1) return config.space.S400;
|
||||
return config.space.S0;
|
||||
};
|
||||
|
||||
const navigate = useNavigate();
|
||||
const lastRoomId = useAtomValue(lastVisitedRoomIdAtom);
|
||||
|
||||
@@ -495,13 +763,35 @@ export function Space() {
|
||||
position: 'relative',
|
||||
}}
|
||||
>
|
||||
{virtualizer.getVirtualItems().map((vItem) => {
|
||||
const { roomId } = hierarchy[vItem.index] ?? {};
|
||||
{virtualizedItems.map((vItem) => {
|
||||
const { roomId, depth } = hierarchy[vItem.index] ?? {};
|
||||
const room = mx.getRoom(roomId);
|
||||
const renderDepth = room?.isSpaceRoom() ? depth - 2 : depth - 1;
|
||||
if (!room) return null;
|
||||
if (depth === subspaceHierarchyLimit && room.isSpaceRoom()) {
|
||||
return (
|
||||
<VirtualTile
|
||||
virtualItem={vItem}
|
||||
key={vItem.index}
|
||||
ref={virtualizer.measureElement}
|
||||
>
|
||||
<div style={{ paddingLeft: `calc(${renderDepth} * ${config.space.S400})` }}>
|
||||
<SpaceNavItem
|
||||
room={room}
|
||||
selected={selectedRoomId === roomId}
|
||||
linkPath={getSpaceLobbyPath(getCanonicalAliasOrRoomId(mx, roomId))}
|
||||
/>
|
||||
</div>
|
||||
</VirtualTile>
|
||||
);
|
||||
}
|
||||
|
||||
const paddingTop = getCategoryPadding(depth);
|
||||
const paddingLeft = `calc(${renderDepth} * ${config.space.S400})`;
|
||||
|
||||
if (room.isSpaceRoom()) {
|
||||
const categoryId = makeNavCategoryId(space.roomId, roomId);
|
||||
const closedViaCategory = getInClosedCategories(space.roomId, roomId);
|
||||
|
||||
return (
|
||||
<VirtualTile
|
||||
@@ -509,14 +799,12 @@ export function Space() {
|
||||
key={vItem.index}
|
||||
ref={virtualizer.measureElement}
|
||||
>
|
||||
<div
|
||||
style={{ paddingTop: vItem.index === 0 ? undefined : config.space.S400 }}
|
||||
>
|
||||
<div style={{ paddingTop, paddingLeft }}>
|
||||
<NavCategoryHeader>
|
||||
<RoomNavCategoryButton
|
||||
data-category-id={categoryId}
|
||||
onClick={handleCategoryClick}
|
||||
closed={closedCategories.has(categoryId)}
|
||||
closed={closedCategories.has(categoryId) || closedViaCategory}
|
||||
>
|
||||
{roomId === space.roomId ? 'Rooms' : room?.name}
|
||||
</RoomNavCategoryButton>
|
||||
@@ -532,20 +820,23 @@ export function Space() {
|
||||
key={vItem.index}
|
||||
ref={virtualizer.measureElement}
|
||||
>
|
||||
<RoomNavItem
|
||||
room={room}
|
||||
selected={selectedRoomId === roomId}
|
||||
showAvatar={mDirects.has(roomId)}
|
||||
direct={mDirects.has(roomId)}
|
||||
linkPath={getToLink(roomId)}
|
||||
notificationMode={getRoomNotificationMode(
|
||||
notificationPreferences,
|
||||
room.roomId
|
||||
)}
|
||||
/>
|
||||
<div style={{ paddingLeft }}>
|
||||
<RoomNavItem
|
||||
room={room}
|
||||
selected={selectedRoomId === roomId}
|
||||
showAvatar={mDirects.has(roomId)}
|
||||
direct={mDirects.has(roomId)}
|
||||
linkPath={getToLink(roomId)}
|
||||
notificationMode={getRoomNotificationMode(
|
||||
notificationPreferences,
|
||||
room.roomId
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</VirtualTile>
|
||||
);
|
||||
})}
|
||||
{getConnectorSVG(hierarchy, virtualizedItems)}
|
||||
</NavCategory>
|
||||
</Box>
|
||||
</PageNavContent>
|
||||
|
||||
@@ -66,3 +66,5 @@ export const makeClosedLobbyCategoriesAtom = (userId: string): ClosedLobbyCatego
|
||||
};
|
||||
|
||||
export const makeLobbyCategoryId = (...args: string[]): string => args.join('|');
|
||||
|
||||
export const getLobbyCategoryIdParts = (categoryId: string): string[] => categoryId.split('|');
|
||||
@@ -66,3 +66,5 @@ export const makeClosedNavCategoriesAtom = (userId: string): ClosedNavCategories
|
||||
};
|
||||
|
||||
export const makeNavCategoryId = (...args: string[]): string => args.join('|');
|
||||
|
||||
export const getNavCategoryIdParts = (categoryId: string): string[] => categoryId.split('|');
|
||||
@@ -0,0 +1,16 @@
|
||||
import { atom } from 'jotai';
|
||||
import { roomToParentsAtom } from './roomToParents';
|
||||
|
||||
export const roomToChildrenAtom = atom((get) => {
|
||||
const roomToParents = get(roomToParentsAtom);
|
||||
const map = new Map<string, Set<string>>();
|
||||
|
||||
roomToParents.forEach((parentSet, childId) => {
|
||||
parentSet.forEach((parentId) => {
|
||||
if (!map.has(parentId)) map.set(parentId, new Set());
|
||||
map.get(parentId)?.add(childId);
|
||||
});
|
||||
});
|
||||
|
||||
return map;
|
||||
});
|
||||
@@ -96,6 +96,7 @@ export interface Settings {
|
||||
autoplayStickers: boolean;
|
||||
autoplayEmojis: boolean;
|
||||
saveStickerEmojiBandwidth: boolean;
|
||||
subspaceHierarchyLimit: number;
|
||||
alwaysShowCallButton: boolean;
|
||||
faviconForMentionsOnly: boolean;
|
||||
highlightMentions: boolean;
|
||||
@@ -181,6 +182,7 @@ const defaultSettings: Settings = {
|
||||
autoplayStickers: true,
|
||||
autoplayEmojis: true,
|
||||
saveStickerEmojiBandwidth: false,
|
||||
subspaceHierarchyLimit: 3,
|
||||
alwaysShowCallButton: false,
|
||||
faviconForMentionsOnly: false,
|
||||
highlightMentions: true,
|
||||
|
||||
@@ -18,8 +18,7 @@ globalStyle(
|
||||
button:active,
|
||||
[role="button"]:active,
|
||||
[class*="Button"]:active,
|
||||
[class*="Chip"]:active,
|
||||
[class*="MenuItem"]:active
|
||||
[class*="Chip"]:active
|
||||
`,
|
||||
{
|
||||
transform: 'scale(0.96) !important',
|
||||
|
||||
@@ -9,7 +9,7 @@ function hashCode(str?: string): number {
|
||||
const chr = str.codePointAt(i) ?? 0;
|
||||
// eslint-disable-next-line no-bitwise
|
||||
hash = (hash << 5) - hash + chr;
|
||||
// eslint-disable-next-line no-bitwise
|
||||
|
||||
hash = Math.trunc(hash);
|
||||
}
|
||||
return Math.abs(hash);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
.dark-theme,
|
||||
.black-theme,
|
||||
.cinny-dark-theme,
|
||||
.butter-theme {
|
||||
--tc-link: hsl(213deg 100% 80%);
|
||||
|
||||
|
||||
Reference in new issue
Block a user