From d7ed9ffb43d8fafa4f45b4f029d9da6919dbd8c0 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 17 Nov 2026 15:59:41 +0100 Subject: [PATCH] Add the Commons entry row: found by alias or carried id, opens the album view Commons is found by file_zones.commons in the stewardships state, else the alias #commons:, through lookupZoneRoom (shared with the Media row). Gated on fileZoneShare.enabled; shown above the tiers; nothing when absent. isFileZone accepts the Commons alias on the home server. Co-Authored-By: Claude Sonnet 5.5 --- docs/commons-files-desk.md | 2 +- src/app/features/albums/isFileZone.test.ts | 6 ++ src/app/features/albums/isFileZone.ts | 9 ++- src/app/features/albums/useAlbums.ts | 2 + src/app/features/estate/EstateNavigator.tsx | 12 +++- src/app/features/estate/MediaRow.test.tsx | 10 ++++ src/app/features/estate/MediaRow.tsx | 34 ++++++++++- src/app/features/estate/mediaRoom.test.ts | 65 +++++++++++++++++++++ src/app/features/estate/mediaRoom.ts | 36 ++++++++++-- 9 files changed, 164 insertions(+), 12 deletions(-) diff --git a/docs/commons-files-desk.md b/docs/commons-files-desk.md index fa7242d2..20ad243e 100644 --- a/docs/commons-files-desk.md +++ b/docs/commons-files-desk.md @@ -118,7 +118,7 @@ Under A the paused service is not built, and most of its list disappears: ## Cuts under A -Status 2026-11-14 (dev da822e9e plus the size-refusal cut): built: folders by album title path with navigation and breadcrumb (#147), pagination (#148), version folding (#149), add-to-album with named refusals (#150), Stop for a send in flight, replaces loops shown, freshest last event on add (#151), and the pre-send size refusal: a file larger than the server's `m.upload.size` is named and left unsent before any upload or album root, and a server stating no cap refuses nothing. **Not built: the Commons entry row** (item 1 below, found by `#commons:gamecult.org` or the carried `media.commons` id through `lookupMediaRoom`, behind a dark `filesDesk.enabled` flag; neither the row nor the flag exists in the code). It waits on Eureka's Commons room. +Status 2026-11-14 (dev da822e9e plus the size-refusal cut): built: folders by album title path with navigation and breadcrumb (#147), pagination (#148), version folding (#149), add-to-album with named refusals (#150), Stop for a send in flight, replaces loops shown, freshest last event on add (#151), and the pre-send size refusal: a file larger than the server's `m.upload.size` is named and left unsent before any upload or album root, and a server stating no cap refuses nothing. The Commons entry row is built (item 1): `useCommons` in `MediaRow.tsx` finds the room by the carried id `@rooms.file_zones.commons` in the root Space's stewardships, else by the alias `#commons:`, through `lookupZoneRoom` (the one lookup `lookupMediaRoom` also uses); `EstateNavigator` shows it above the tiers as a Commons link when joined, a join row when invited or not joined, and nothing when the room is absent, the lookup failed or is out. It is gated on the existing `fileZoneShare.enabled`, not a new `filesDesk.enabled` flag. `isFileZone` also accepts the room holding `#commons:` as its alias, so the album view and ShareSet work there without a `fileZoneRooms` entry or the create type. 1. **Commons entry**: a Commons row in the navigator (like `MediaRow`, found by alias or carried id), opening the room's album view. Flagged, no new data layer. 2. **Pagination** of albums and files in `useAlbums` (done, PR #148). diff --git a/src/app/features/albums/isFileZone.test.ts b/src/app/features/albums/isFileZone.test.ts index 0e55269f..23cdef21 100644 --- a/src/app/features/albums/isFileZone.test.ts +++ b/src/app/features/albums/isFileZone.test.ts @@ -21,4 +21,10 @@ describe('isFileZone', () => { it('is false when only another room is configured', () => { expect(isFileZone(room, { fileZoneRooms: ['!g:x', '#g:x'] })).toBe(false); }); + it('is true for the Commons alias on the home server, and only there', () => { + const c = { roomId: '!c:x', aliases: ['#commons:x'] }; + expect(isFileZone({ ...c, server: 'x' }, {})).toBe(true); + expect(isFileZone({ ...c, server: 'y' }, {})).toBe(false); + expect(isFileZone(c, {})).toBe(false); + }); }); diff --git a/src/app/features/albums/isFileZone.ts b/src/app/features/albums/isFileZone.ts index 071ef17b..fec253ab 100644 --- a/src/app/features/albums/isFileZone.ts +++ b/src/app/features/albums/isFileZone.ts @@ -1,14 +1,21 @@ export const FILE_ZONE_TYPE = 'org.gamecult.file_zone'; +/** The shared Commons room's key in the carried `file_zones` map, and its alias on the home server. */ +export const COMMONS_KEY = 'commons'; +export const commonsAlias = (server: string): string => `#${COMMONS_KEY}:${server}`; + export type FileZoneRoom = { roomId: string; /** Canonical and alternative aliases. */ aliases?: string[]; /** The `type` of the room's m.room.create content. */ createType?: string; + /** The home server name; the Commons alias on it makes the room a file zone. */ + server?: string; }; -/** A room is the file zone when its create type says so or the client config lists it. */ +/** A room is the file zone when its create type says so, it holds the Commons alias on the home server, or the client config lists it. */ export const isFileZone = (room: FileZoneRoom, config: { fileZoneRooms?: string[] }): boolean => room.createType === FILE_ZONE_TYPE || + (!!room.server && !!room.aliases?.includes(commonsAlias(room.server))) || !!config.fileZoneRooms?.some((r) => r === room.roomId || room.aliases?.includes(r)); diff --git a/src/app/features/albums/useAlbums.ts b/src/app/features/albums/useAlbums.ts index 13c199ec..514b6c19 100644 --- a/src/app/features/albums/useAlbums.ts +++ b/src/app/features/albums/useAlbums.ts @@ -15,6 +15,7 @@ const REFRESH_MS = 30_000; /** True when the room is the file zone: by its create type, or listed in the client config. */ export const useIsFileZone = (room: Room): boolean => { const config = useClientConfig(); + const server = useMatrixClient().getDomain() ?? undefined; // Subscribes to alias changes (alt aliases live in the same event). useStateEvent(room, StateEvent.RoomCanonicalAlias); const createType = room.currentState.getStateEvents('m.room.create', '')?.getContent().type; @@ -23,6 +24,7 @@ export const useIsFileZone = (room: Room): boolean => { roomId: room.roomId, aliases: [room.getCanonicalAlias(), ...room.getAltAliases()].filter((a): a is string => !!a), createType, + server, }, config ); diff --git a/src/app/features/estate/EstateNavigator.tsx b/src/app/features/estate/EstateNavigator.tsx index b560e08c..746b45b9 100644 --- a/src/app/features/estate/EstateNavigator.tsx +++ b/src/app/features/estate/EstateNavigator.tsx @@ -37,7 +37,7 @@ import { searchModalAtom } from '../../state/searchModal'; import { getCanonicalAliasOrRoomId } from '../../utils/matrix'; import { useMatrixClient } from '../../hooks/useMatrixClient'; import { MINDS } from '../../components/message/pose/poses'; -import { MediaLink, MediaNote, useMindMedia } from './MediaRow'; +import { MediaLink, MediaNote, useCommons, useMindMedia } from './MediaRow'; import { MediaRow as MediaRowState } from './mediaRoom'; import { useSelectedRoom } from '../../hooks/router/useSelectedRoom'; import { useCallEmbed } from '../../hooks/useCallEmbed'; @@ -194,6 +194,15 @@ function MindMedia({ media }: { media: MediaRowState }) { return ; } +/** The shared Commons room above the tiers: a link when joined, a join row otherwise, nothing when there is none. */ +function CommonsEntry() { + const mx = useMatrixClient(); + const room = useCommons(); + if (!room) return null; + if (room.state === 'joined') return ; + return ; +} + function GroupSection({ tierId, group }: { tierId: string; group: EstateGroup }) { const media = useMindMedia(group.mind, group.rooms); const hasMedia = MINDS.includes(group.mind); @@ -345,6 +354,7 @@ function EstateTiers({ rootId }: { rootId: string }) { return ( <> + {tiers.map((tier) => ( ))} diff --git a/src/app/features/estate/MediaRow.test.tsx b/src/app/features/estate/MediaRow.test.tsx index 6b590158..88f7e89e 100644 --- a/src/app/features/estate/MediaRow.test.tsx +++ b/src/app/features/estate/MediaRow.test.tsx @@ -26,4 +26,14 @@ describe('Media row', () => { expect(text(html)).toBe('Media'); expect(html).toContain('href="/home/%23void-files%3Agamecult.org/"'); }); + + it('the Commons link reads "Commons" and opens the room', () => { + const html = renderToStaticMarkup( + + + + ); + expect(text(html)).toBe('Commons'); + expect(html).toContain('href="/home/%23commons%3Agamecult.org/"'); + }); }); diff --git a/src/app/features/estate/MediaRow.tsx b/src/app/features/estate/MediaRow.tsx index 6277f09c..2672fc16 100644 --- a/src/app/features/estate/MediaRow.tsx +++ b/src/app/features/estate/MediaRow.tsx @@ -5,7 +5,7 @@ import { Avatar, Box, Icon, Icons, Text } from 'folds'; import { NavGutter, NavItem, NavItemContent, NavLink } from '../../components/nav'; import { NAV_ROOM_ICON_REST_OPACITY, NavLabel } from '../../components/nav/styles.css'; import { EstateRoom } from './buildEstate'; -import { isFileZone } from '../albums/isFileZone'; +import { COMMONS_KEY, commonsAlias, isFileZone } from '../albums/isFileZone'; import { useClientConfig } from '../../hooks/useClientConfig'; import { MINDS } from '../../components/message/pose/poses'; import { useMatrixClient } from '../../hooks/useMatrixClient'; @@ -15,7 +15,9 @@ import { useEstateRootId } from './useEstate'; import { STEWARDSHIPS_KEY, MediaRow as MediaRowState, + commonsRow, lookupMediaRoom, + lookupZoneRoom, mediaRoomIdFromStewardships, mediaRow, typedMediaRoom, @@ -44,7 +46,7 @@ export function MediaNote({ note, title }: { note: string; title?: string }) { } /** The joined Media row: opens the room, which shows its album view. */ -export function MediaLink({ to }: { to: string }) { +export function MediaLink({ to, label = 'Media' }: { to: string; label?: string }) { return ( @@ -52,7 +54,7 @@ export function MediaLink({ to }: { to: string }) { {mediaIcon} - Media + {label} @@ -105,3 +107,29 @@ export const useMindMedia = (mind: string, rooms: readonly EstateRoom[]): MediaR if (typed) return { kind: 'room', room: { ...typed, name: 'Media' } }; return mediaRow(lookup.data, membership); }; + +/** The shared Commons room as the navigator sees it right now: undefined means no row. Dark unless fileZoneShare.enabled. */ +export const useCommons = (): EstateRoom | undefined => { + const mx = useMatrixClient(); + const { rootId } = useEstateRootId(); + const joined = useAtomValue(allRoomsAtom); + const invited = useAtomValue(allInvitesAtom); + const enabled = !!useClientConfig().fileZoneShare?.enabled; + const server = mx.getDomain() ?? ''; + const carried = mediaRoomIdFromStewardships( + rootId + ? mx.getRoom(rootId)?.currentState.getStateEvents(STEWARDSHIPS_KEY, '')?.getContent() + : undefined, + COMMONS_KEY + ); + const lookup = useQuery({ + queryKey: ['commons-room', server, carried], + queryFn: () => lookupZoneRoom(mx, commonsAlias(server), server, carried), + staleTime: 60_000, + enabled, + }); + const membership = new Map(); + invited.forEach((id) => membership.set(id, 'invite')); + joined.forEach((id) => membership.set(id, 'join')); + return commonsRow(enabled, lookup.data, membership); +}; diff --git a/src/app/features/estate/mediaRoom.test.ts b/src/app/features/estate/mediaRoom.test.ts index 934caaae..6f259e38 100644 --- a/src/app/features/estate/mediaRoom.test.ts +++ b/src/app/features/estate/mediaRoom.test.ts @@ -1,9 +1,13 @@ import { describe, expect, it } from 'vitest'; +import { commonsAlias, COMMONS_KEY } from '../albums/isFileZone'; import { + commonsRow, lookupMediaRoom, + lookupZoneRoom, mediaAlias, mediaRoomIdFromStewardships, mediaRow, + MediaLookup, typedMediaRoom, } from './mediaRoom'; @@ -132,3 +136,64 @@ describe('the Media row of a Mind', () => { expect(typedMediaRoom(rooms, () => false)).toBeUndefined(); }); }); + +describe('the Commons row', () => { + const none = new Map(); + + it('is found by the alias #commons:', async () => { + const { mx, asked } = clientFor(async () => ({ room_id: '!c:gamecult.org' })); + const lookup = await lookupZoneRoom(mx, commonsAlias('gamecult.org'), 'gamecult.org'); + expect(asked).toEqual(['#commons:gamecult.org']); + expect(commonsRow(true, lookup, new Map([['!c:gamecult.org', 'join']]))).toMatchObject({ + roomId: '!c:gamecult.org', + name: 'Commons', + state: 'joined', + }); + }); + + it('is found by a carried id under file_zones.commons, asking nobody', async () => { + const { mx, asked } = clientFor(async () => { + throw new Error('must not be asked'); + }); + const carried = mediaRoomIdFromStewardships( + { '@rooms': { file_zones: { [COMMONS_KEY]: '!c:gamecult.org' } } }, + COMMONS_KEY + ); + const lookup = await lookupZoneRoom(mx, commonsAlias('gamecult.org'), 'gamecult.org', carried); + expect(asked).toEqual([]); + expect(commonsRow(true, lookup, none)).toMatchObject({ roomId: '!c:gamecult.org' }); + }); + + it('shows no row when the room is absent, the lookup failed or is still out', async () => { + const missing = await lookupZoneRoom( + clientFor(async () => { + throw notFound; + }).mx, + commonsAlias('gamecult.org'), + 'gamecult.org' + ); + const failed = await lookupZoneRoom( + clientFor(async () => { + throw new Error('down'); + }).mx, + commonsAlias('gamecult.org'), + 'gamecult.org' + ); + expect(commonsRow(true, missing, none)).toBeUndefined(); + expect(commonsRow(true, failed, none)).toBeUndefined(); + expect(commonsRow(true, undefined, none)).toBeUndefined(); + }); + + it('shows no row with the flag off, even for a found room', () => { + const found: MediaLookup = { found: true, roomId: '!c:gamecult.org', via: ['gamecult.org'] }; + expect(commonsRow(false, found, new Map([['!c:gamecult.org', 'join']]))).toBeUndefined(); + }); + + it('offers a join to a viewer who has not joined, and an accept to an invited one', () => { + const found: MediaLookup = { found: true, roomId: '!c:gamecult.org', via: ['gamecult.org'] }; + expect(commonsRow(true, found, none)?.state).toBe('joinable'); + expect(commonsRow(true, found, new Map([['!c:gamecult.org', 'invite']]))?.state).toBe( + 'invited' + ); + }); +}); diff --git a/src/app/features/estate/mediaRoom.ts b/src/app/features/estate/mediaRoom.ts index 5d1503b6..69acd560 100644 --- a/src/app/features/estate/mediaRoom.ts +++ b/src/app/features/estate/mediaRoom.ts @@ -46,16 +46,16 @@ export type MediaLookup = | { found: true; roomId: string; via: string[] } | { found: false; reason: 'unset' | 'error'; message?: string }; -/** Resolve a Mind's media room: a carried id if there is one, else the alias. A 404 means it is not set up. */ -export const lookupMediaRoom = async ( +/** Resolve a file-zone room (a Mind's media room, or Commons): a carried id if there is one, else the alias. A 404 means it is not set up. */ +export const lookupZoneRoom = async ( mx: MediaClient, - mind: string, + alias: string, server: string, carriedId?: string ): Promise => { if (carriedId) return { found: true, roomId: carriedId, via: [server] }; try { - const r = await mx.getRoomIdForAlias(mediaAlias(mind, server)); + const r = await mx.getRoomIdForAlias(alias); return { found: true, roomId: r.room_id, via: r.servers?.length ? r.servers : [server] }; } catch (e) { const err = e as { @@ -75,6 +75,14 @@ export const lookupMediaRoom = async ( } }; +/** Resolve a Mind's media room. */ +export const lookupMediaRoom = ( + mx: MediaClient, + mind: string, + server: string, + carriedId?: string +): Promise => lookupZoneRoom(mx, mediaAlias(mind, server), server, carriedId); + export type MediaRow = | { kind: 'checking' } | { kind: 'unset' } @@ -86,7 +94,8 @@ const MEMBERSHIP_STATE = { join: 'joined', invite: 'invited', none: 'joinable' } /** What the Media row shows: the lookup result joined to the user's own membership. */ export const mediaRow = ( lookup: MediaLookup | undefined, - membership: ReadonlyMap + membership: ReadonlyMap, + name = 'Media' ): MediaRow => { if (!lookup) return { kind: 'checking' }; if (!lookup.found) { @@ -99,7 +108,7 @@ export const mediaRow = ( kind: 'room', room: { roomId: lookup.roomId, - name: 'Media', + name, state: MEMBERSHIP_STATE[m ?? 'none'], via: lookup.via, parentId: null, @@ -107,3 +116,18 @@ export const mediaRow = ( }, }; }; + +/** + * The Commons row: the shared room, or nothing. Off with the share flag; not set up, still looking and a failed lookup + * show no row (the room is shared furniture, not a per-Mind promise like Media). A found room is joined, invited or + * joinable, as for Media. + */ +export const commonsRow = ( + enabled: boolean, + lookup: MediaLookup | undefined, + membership: ReadonlyMap +): EstateRoom | undefined => { + if (!enabled) return undefined; + const row = mediaRow(lookup, membership, 'Commons'); + return row.kind === 'room' ? row.room : undefined; +};